]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/timing/timing.c
timing: clock_gettime() version working
[eurobot/public.git] / src / timing / timing.c
index fb5d6741666624925f9e1c14b92fd6c4149b2ae2..c45c0bbbfc64689fdd8f011a1683b2ec16a9c9fe 100644 (file)
@@ -42,6 +42,7 @@ struct timespec meas_start_ts;
 void timing_statistics_asm(void);
 void timing_output_trace_screen(void);
 void timing_output_trace_file(void);
+void timing_statistics_clock_gettime(void);
 
 timestamp_t * timestamp_handle_overflow(void)
 {
@@ -102,7 +103,7 @@ void timing_ipoint_asm(unsigned char id)
 #endif
 
 #ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
-void timing_ipoint_clock_gettime(unsigned short id)
+void timing_ipoint_clock_gettime(unsigned char id)
 {
        timestamp_t *p, *pinc;
        
@@ -116,8 +117,10 @@ void timing_ipoint_clock_gettime(unsigned short id)
                if (!p) 
                        return;
        }
-       else
+       else {
+               p->id = id;
                timestamp_ptr++;
+       }
 }
 #endif
 
@@ -133,6 +136,7 @@ void timing_init(int init_freq)
 #endif
 #ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
        timing_ipoint = timing_ipoint_clock_gettime;
+       timing_statistics = timing_statistics_clock_gettime;
 #endif
        system("mount -t debugfs trace /debug");
        system("echo sched_switch > /debug/tracing/current_tracer");
@@ -165,6 +169,7 @@ void timing_init(int init_freq)
        timing_output_trace = timing_output_trace_file;
 #endif
        printf("Timing library initialized!\n");
+       system("dmesg | grep tb_orig_stamp | sed 's#.*tb_orig_stamp\\=\\([0-9]*\\).*#\\1#' | tee tb_orig_stamp");
        system("echo 1 > /debug/tracing/tracing_enabled");
        clock_gettime(clk_id, &meas_start_ts);
 }
@@ -178,10 +183,12 @@ void timing_finish()
        system("echo nop > /debug/tracing/current_tracer");
 }
 
+#ifdef CONFIG_TIMING_IPOINT_ASM
 void print_ts_asm(timestamp_t *ts)
 {
        printf("%d %llu\n", ts->id, (uint64_t)((uint64_t)ts->tbu << 32 | ts->tbl));
 }
+#endif
 
 void timing_output_trace_screen(void)
 {
@@ -192,7 +199,9 @@ void timing_output_trace_screen(void)
        if(timestamp_enabled)
        while(ts_iter != (timestamp_ptr+1))
        {
+#ifdef CONFIG_TIMING_IPOINT_ASM
                print_ts_asm(ts_iter);
+#endif
                ts_iter++;
                i++;
        }
@@ -200,6 +209,15 @@ void timing_output_trace_screen(void)
        printf("got %d timestamps over limit\n",cnt);
 }
 
+double timespec2sec(struct timespec *tspec)
+{
+       double result;
+
+       result = tspec->tv_sec + (tspec->tv_nsec*0.000000001);
+
+       return result;
+}
+
 void timing_output_trace_file(void)
 {
        FILE *file;
@@ -221,6 +239,7 @@ void timing_output_trace_file(void)
                                (uint64_t)((uint64_t)ts_iter->tbu << 32 | ts_iter->tbl));
 #endif
 #ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
+               fprintf(file, "%d %.6f\n", ts_iter->id, timespec2sec(&ts_iter->ts));
 #endif
                ts_iter++;
                i++;
@@ -231,6 +250,7 @@ void timing_output_trace_file(void)
        fclose(file);
 }
 
+#ifdef CONFIG_TIMING_IPOINT_ASM
 double sub_timestamps_us(timestamp_t *t1, timestamp_t *t2)
 {
        double result;
@@ -270,4 +290,46 @@ void timing_statistics_asm(void)
        else
        printf("got %d timestamps over limit\n",cnt);
 }
+#endif
+
+double sub_ts_us(struct timespec start, struct timespec end)
+{
+       struct timespec temp;
+       double ret;
+       
+       if ((end.tv_nsec-start.tv_nsec)<0) {
+               temp.tv_sec = end.tv_sec-start.tv_sec-1;
+               temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
+       } else {
+               temp.tv_sec = end.tv_sec-start.tv_sec;
+               temp.tv_nsec = end.tv_nsec-start.tv_nsec;
+       }
+
+       ret = (temp.tv_sec * 1000000.0) + (temp.tv_nsec/1000.0);
+       
+       return ret;
+}
+
+#ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
+void timing_statistics_clock_gettime(void)
+{
+       timestamp_t *ts_iter;
+       int i=1;
+
+       printf("Highrest_Statistics\n");
+       ts_iter = ts;
+
+       if(timestamp_enabled)
+               while(ts_iter != (timestamp_ptr+1))
+               {
+                       if(i%2 == 0) {
+                               printf("%3.2f\n", sub_ts_us((ts_iter-1)->ts,(ts_iter)->ts));
+                       }
+                       ts_iter++;
+                       i++;
+               }
+       else
+               printf("got %d timestamps over limit\n",cnt);
+}
+#endif