Commit 99e580f0 authored by Joanne Hugé's avatar Joanne Hugé

Add trace marking

parent 02829888
......@@ -59,17 +59,20 @@ static void *timerthread(void *p) {
stat->max_res = 0;
stat->min_res = UINT64_MAX;
if(param->enable_tracing)
tracing(1);
for (stat->nb_cycles = 0;; stat->nb_cycles++) {
if (param->max_cycles && (stat->nb_cycles >= param->max_cycles)) break;
if(param->enable_tracing)
tracing(1);
tracemark("Time measure start\n");
clock_gettime(CLOCK_ID, &previous);
clock_gettime(CLOCK_ID, &current);
if(param->enable_tracing)
tracing(0);
tracemark("Time measure end\n");
diff = calcdiff_ns(current, previous);
......@@ -81,6 +84,10 @@ static void *timerthread(void *p) {
usleep(param->interval);
}
if(param->enable_tracing)
tracing(0);
return NULL;
}
......@@ -123,6 +130,8 @@ int main(int argc, char *argv[]) {
if (main_param.enable_tracing && (param.stat.max_res >= param.latency_threshold)) break;
}
// Just in case main exists before the thread
if(main_param.enable_tracing)
tracing(0);
exit(EXIT_SUCCESS);
......
......@@ -39,7 +39,9 @@
static char *fileprefix;
static char *procfileprefix = "/proc/sys/kernel/";
static char *debugfileprefix = "/sys/kernel/debug/tracing/";
static int trace_fd = -1;
static int tracemark_fd = -1;
static int kernvar(int mode, const char *name, char *value,
size_t sizeofvalue) {
......@@ -74,6 +76,9 @@ static void setkernvar(const char *name, char *value) {
void setup_tracer(void) {
char trace_path[MAX_PATH];
char tracemark_path[MAX_PATH];
fileprefix = procfileprefix;
setkernvar("ftrace_enabled", "1");
......@@ -82,14 +87,17 @@ void setup_tracer(void) {
setkernvar("current_tracer", "nop");
setkernvar("current_tracer", "function");
/* open the tracing on file descriptor */
if (trace_fd == -1) {
char path[MAX_PATH];
strcpy(path, fileprefix);
strcat(path, "tracing_on");
if ((trace_fd = open(path, O_WRONLY)) == -1)
printf("unable to open %s for tracing", path);
}
// Open tracing_on file
strcpy(trace_path, fileprefix);
strcat(trace_path, "tracing_on");
if ((trace_fd = open(trace_path, O_WRONLY)) == -1)
printf("unable to open %s for tracing", trace_path);
// Open trace mark file
strcpy(tracemark_path, fileprefix);
strcat(tracemark_path, "trace_marker");
if ((tracemark_fd = open(tracemark_path, O_WRONLY)) == -1)
printf("unable to open %s for tracing", tracemark_path);
tracing(0);
}
......@@ -100,3 +108,7 @@ void tracing(int on) {
else
write(trace_fd, "0", 1);
}
void tracemark(char * s) {
write(tracemark_fd, s, strlen(s));
}
......@@ -3,5 +3,6 @@
void setup_tracer(void);
void tracing(int on);
void tracemark(char * s);
#endif
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