Commit c763242a authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf time-utils: Factor out set_percent_time()

Factor out set_percent_time() so it can be reused.
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190604130017.31207-14-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f79a7689
...@@ -135,12 +135,27 @@ static int parse_percent(double *pcnt, char *str) ...@@ -135,12 +135,27 @@ static int parse_percent(double *pcnt, char *str)
return 0; return 0;
} }
static int set_percent_time(struct perf_time_interval *ptime, double start_pcnt,
double end_pcnt, u64 start, u64 end)
{
u64 total = end - start;
if (start_pcnt < 0.0 || start_pcnt > 1.0 ||
end_pcnt < 0.0 || end_pcnt > 1.0) {
return -1;
}
ptime->start = start + round(start_pcnt * total);
ptime->end = start + round(end_pcnt * total);
return 0;
}
static int percent_slash_split(char *str, struct perf_time_interval *ptime, static int percent_slash_split(char *str, struct perf_time_interval *ptime,
u64 start, u64 end) u64 start, u64 end)
{ {
char *p, *end_str; char *p, *end_str;
double pcnt, start_pcnt, end_pcnt; double pcnt, start_pcnt, end_pcnt;
u64 total = end - start;
int i; int i;
/* /*
...@@ -168,15 +183,7 @@ static int percent_slash_split(char *str, struct perf_time_interval *ptime, ...@@ -168,15 +183,7 @@ static int percent_slash_split(char *str, struct perf_time_interval *ptime,
start_pcnt = pcnt * (i - 1); start_pcnt = pcnt * (i - 1);
end_pcnt = pcnt * i; end_pcnt = pcnt * i;
if (start_pcnt < 0.0 || start_pcnt > 1.0 || return set_percent_time(ptime, start_pcnt, end_pcnt, start, end);
end_pcnt < 0.0 || end_pcnt > 1.0) {
return -1;
}
ptime->start = start + round(start_pcnt * total);
ptime->end = start + round(end_pcnt * total);
return 0;
} }
static int percent_dash_split(char *str, struct perf_time_interval *ptime, static int percent_dash_split(char *str, struct perf_time_interval *ptime,
...@@ -184,7 +191,6 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime, ...@@ -184,7 +191,6 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime,
{ {
char *start_str = NULL, *end_str; char *start_str = NULL, *end_str;
double start_pcnt, end_pcnt; double start_pcnt, end_pcnt;
u64 total = end - start;
int ret; int ret;
/* /*
...@@ -203,16 +209,7 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime, ...@@ -203,16 +209,7 @@ static int percent_dash_split(char *str, struct perf_time_interval *ptime,
free(start_str); free(start_str);
if (start_pcnt < 0.0 || start_pcnt > 1.0 || return set_percent_time(ptime, start_pcnt, end_pcnt, start, end);
end_pcnt < 0.0 || end_pcnt > 1.0 ||
start_pcnt > end_pcnt) {
return -1;
}
ptime->start = start + round(start_pcnt * total);
ptime->end = start + round(end_pcnt * total);
return 0;
} }
typedef int (*time_pecent_split)(char *, struct perf_time_interval *, typedef int (*time_pecent_split)(char *, struct perf_time_interval *,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment