time_meas.c 2.85 KB
Newer Older
1 2
#include <stdio.h>
#include "time_meas.h"
knopp's avatar
 
knopp committed
3 4
#include <math.h>
#include <unistd.h>
5

6
// global var for openair performance profiler
7
int opp_enabled = 0;
8

9

10 11 12 13
double get_cpu_freq_GHz(void) {

  time_stats_t ts = {0};
  reset_meas(&ts);
14 15
  ts.trials++;
  ts.in = rdtsc_oai();
16
  sleep(1);
17
  ts.diff = (rdtsc_oai()-ts.in);
18
  cpu_freq_GHz = (double)ts.diff/1000000000;
19
  printf("CPU Freq is %f \n", cpu_freq_GHz);
20 21 22
  return cpu_freq_GHz; 
}

23
void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name){
24 25 26 27 28 29 30 31 32 33 34

  if (opp_enabled) {

    //static double cpu_freq_GHz = 3.2;

    //if (cpu_freq_GHz == 0.0)
      //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow

    if (ts->trials>0) {

      //fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->diff_now/(cpu_freq_GHz*1000000.0)),subframe,ts->diff_now);
Cedric Roux's avatar
fix  
Cedric Roux committed
35
      fprintf(file_name,"%15.3f ms, diff_now %15.3f \n",(ts->diff_now/(cpu_freq_GHz*1000000.0)),(double)ts->diff_now);
36 37 38 39 40
      
    }
  }
}

41 42
void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time)
{
43 44

  if (opp_enabled) {
45

46 47
    static int first_time = 0;
    static double cpu_freq_GHz = 0.0;
48

49 50
    if (cpu_freq_GHz == 0.0)
      cpu_freq_GHz = get_cpu_freq_GHz();
51

52
    if (first_time == 0) {
53 54
      first_time=1;

55
      if ((total_exec_time == NULL) || (sf_exec_time== NULL))
56
        fprintf(stderr, "%25s  %25s  %25s  %25s %25s %6f\n","Name","Total","Per Trials",   "Num Trials","CPU_F_GHz", cpu_freq_GHz);
57
      else
58
        fprintf(stderr, "%25s  %25s  %25s  %20s %15s %6f\n","Name","Total","Average/Frame","Trials",    "CPU_F_GHz", cpu_freq_GHz);
59
    }
60

61 62
    if (ts->trials>0) {
      //printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

      if ((total_exec_time == NULL) || (sf_exec_time== NULL)) {
        fprintf(stderr, "%25s:  %15.3f ms ;  %15.3f us; %15d;\n",
                name,
                (ts->diff/cpu_freq_GHz/1000000.0),
                (ts->diff/ts->trials/cpu_freq_GHz/1000.0),
                ts->trials);
      } else {
        fprintf(stderr, "%25s:  %15.3f ms (%5.2f%%); %15.3f us (%5.2f%%); %15d;\n",
                name,
                (ts->diff/cpu_freq_GHz/1000000.0),
                ((ts->diff/cpu_freq_GHz/1000000.0)/(total_exec_time->diff/cpu_freq_GHz/1000000.0))*100,  // percentage
                (ts->diff/ts->trials/cpu_freq_GHz/1000.0),
                ((ts->diff/ts->trials/cpu_freq_GHz/1000.0)/(sf_exec_time->diff/sf_exec_time->trials/cpu_freq_GHz/1000.0))*100,  // percentage
                ts->trials);
78
      }
79 80
    }
  }
81

82
}
83

84 85
double get_time_meas_us(time_stats_t *ts)
{
86

87
  static double cpu_freq_GHz = 0.0;
88

89 90
  if (cpu_freq_GHz == 0.0)
    cpu_freq_GHz = get_cpu_freq_GHz();
91 92

  if (ts->trials>0)
93
    return  (ts->diff/ts->trials/cpu_freq_GHz/1000.0);
94

95
  return 0;
96
}