/***************************************************************************** * * perf_extract.c 2014.05.24 Smythies * program to parse times out of a "perf script" report, and calculate * delta t since the last time. * There seems to be large gaps in runnings of the intel_pstate driver * Smythies *****************************************************************************/ #include #include #include #define MAX_LENGTH 2000 /* maximum line length */ #define MAX_SAMPLES 1000000 /* maximum number of samples */ void main(int argc, char **argv){ double dt[MAX_SAMPLES]; /* array of delta time numbers */ char in_buffer[MAX_LENGTH]; char *infile, *outfile; char *index; FILE *inf, *out; double new_time, old_time, max_time, min_time; int sample, i; switch(argc){ case 3: infile = argv[1]; outfile = argv[2]; break; default: printf("perf_extract infile outfile\n"); printf(" parse times out of a perf script report, and calculate delta t since the last time from infile to an MATK plottable outfile\n"); exit(-1); } /* endcase */ printf("perf_extract: Begin...\n"); if((inf = fopen(infile, "rt")) == NULL){ printf("Unable to open input file '%s'\n", infile); exit(-1); } /* endif */ if((out = fopen(outfile, "wt")) == NULL){ printf("Error opening output file '%s'\n", outfile); exit(-1); } /* endif */ sample = 0; max_time = 0.0; min_time = 5000000.0; while((fgets(in_buffer, MAX_LENGTH, inf)) != NULL){ /* do infile line at a time */ if((index = strstr(in_buffer, "[007] ")) != NULL){ /* find search string if it is there */ sscanf(index, "[007] %lf", &new_time); if( sample != 0){ dt[sample -1] = new_time - old_time; if(dt[sample-1] > max_time) max_time = dt[sample-1]; if(dt[sample-1] < min_time) min_time = dt[sample-1]; } /* endif */ sample++; old_time = new_time; if(sample == MAX_SAMPLES){ printf("perf_extract: Hit maximum number of samples, the rest ignored\n"); break; } /* endif */ } else { printf("perf_extract: Got an odd line. This should not occur, but continuing anyhow.\n"); } /* endif */ } /* endwhile */ printf("perf_extract: Number of samples: %d Delta time: Min: %lf Max: %lf\n", sample, min_time, max_time); printf("perf_extract: dumping to output file '%s'\n", outfile); for(i = 0; i < sample-1; i++){ fprintf(out, "%d %5.3lf\n", i, dt[i]); } /* endfor */ fclose(inf); fclose(out); printf("perf_extract: Done. Exiting...\n"); } /* endprogram */