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

Add trace marking

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