projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Unify the time handling
[fio.git]
/
parse.c
diff --git
a/parse.c
b/parse.c
index c8bae0335a4e90365022e946d24136b1a1cc501b..079f19e3d32754f53ebfb3d9ca0ff5a8c707fc15 100644
(file)
--- a/
parse.c
+++ b/
parse.c
@@
-122,11
+122,12
@@
static void show_option_help(struct fio_option *o, int is_err)
show_option_values(o);
}
show_option_values(o);
}
-static unsigned long long get_mult_time(const char *str, int len)
+static unsigned long long get_mult_time(const char *str, int len,
+ int is_seconds)
{
const char *p = str;
char *c;
{
const char *p = str;
char *c;
- unsigned long long mult = 1
000
;
+ unsigned long long mult = 1;
/*
* Go forward until we hit a non-digit, or +/- sign
/*
* Go forward until we hit a non-digit, or +/- sign
@@
-137,23
+138,29
@@
static unsigned long long get_mult_time(const char *str, int len)
p++;
}
p++;
}
- if (!isalpha((int) *p))
- return 1000;
+ if (!isalpha((int) *p)) {
+ if (is_seconds)
+ return 1000000UL;
+ else
+ return 1;
+ }
c = strdup(p);
for (int i = 0; i < strlen(c); i++)
c[i] = tolower(c[i]);
c = strdup(p);
for (int i = 0; i < strlen(c); i++)
c[i] = tolower(c[i]);
- if (!strncmp("
ms", c, 2
))
+ if (!strncmp("
us", c, 2) || !strncmp("usec", c, 4
))
mult = 1;
mult = 1;
- else if (!str
cmp("s", c
))
+ else if (!str
ncmp("ms", c, 2) || !strncmp("msec", c, 4
))
mult = 1000;
mult = 1000;
+ else if (!strcmp("s", c))
+ mult = 1000000;
else if (!strcmp("m", c))
else if (!strcmp("m", c))
- mult = 60 * 1000;
+ mult = 60 * 1000
000UL
;
else if (!strcmp("h", c))
else if (!strcmp("h", c))
- mult = 60 * 60 * 1000;
+ mult = 60 * 60 * 1000
000UL
;
else if (!strcmp("d", c))
else if (!strcmp("d", c))
- mult = 24 * 60 * 60 * 1000;
+ mult = 24 * 60 * 60 * 1000
000UL
;
free(c);
return mult;
free(c);
return mult;
@@
-268,7
+275,8
@@
int str_to_float(const char *str, double *val)
/*
* convert string into decimal value, noting any size suffix
*/
/*
* convert string into decimal value, noting any size suffix
*/
-int str_to_decimal(const char *str, long long *val, int kilo, void *data)
+int str_to_decimal(const char *str, long long *val, int kilo, void *data,
+ int is_seconds)
{
int len, base;
{
int len, base;
@@
-295,19
+303,19
@@
int str_to_decimal(const char *str, long long *val, int kilo, void *data)
else
*val *= mult;
} else
else
*val *= mult;
} else
- *val *= get_mult_time(str, len);
+ *val *= get_mult_time(str, len
, is_seconds
);
return 0;
}
int check_str_bytes(const char *p, long long *val, void *data)
{
return 0;
}
int check_str_bytes(const char *p, long long *val, void *data)
{
- return str_to_decimal(p, val, 1, data);
+ return str_to_decimal(p, val, 1, data
, 0
);
}
}
-int check_str_time(const char *p, long long *val)
+int check_str_time(const char *p, long long *val
, int is_seconds
)
{
{
- return str_to_decimal(p, val, 0, NULL);
+ return str_to_decimal(p, val, 0, NULL
, is_seconds
);
}
void strip_blank_front(char **p)
}
void strip_blank_front(char **p)
@@
-349,7
+357,7
@@
static int check_range_bytes(const char *str, long *val, void *data)
{
long long __val;
{
long long __val;
- if (!str_to_decimal(str, &__val, 1, data)) {
+ if (!str_to_decimal(str, &__val, 1, data
, 0
)) {
*val = __val;
return 0;
}
*val = __val;
return 0;
}
@@
-459,7
+467,7
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
*p = '\0';
if (is_time)
*p = '\0';
if (is_time)
- ret = check_str_time(tmp, &ull);
+ ret = check_str_time(tmp, &ull
, o->is_seconds
);
else
ret = check_str_bytes(tmp, &ull, data);
else
ret = check_str_bytes(tmp, &ull, data);