/***************************************************************************** * * joules_extract.c 2014.07.15 Smythies * To extract package Joules from turbostat output. * Crude, but I do not care. * *****************************************************************************/ #include #include #include #define MAX_LENGTH 2000 /* maximum line length */ void main(int argc, char **argv){ char in_buffer[MAX_LENGTH]; char *infile, *outfile; char *index; FILE *inf, *out; double busy, c1, c3, c6, c7, pc2, pc3, pc6, pc7, joules, c_joules, g_joules, p_time; long ave_mhz, bzy_mhz, tsc_mhz, smi, coretmp, pkgtmp; switch(argc){ case 3: infile = argv[1]; outfile = argv[2]; break; default: printf("joules_extract infile outfile\n"); printf(" parse the package Joules out of turbostat -S -J output. Assumed to be output from some script. From infile to list in outfile\n"); exit(-1); } /* endcase */ printf("joules_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 */ while((fgets(in_buffer, MAX_LENGTH, inf)) != NULL){ /* do infile line at a time */ if((index = strstr(in_buffer, "Avg_MHz")) != NULL){ /* synchronize to the turbostat output, ignoring anything in between */ if((fgets(in_buffer, MAX_LENGTH, inf)) == NULL){ /* if the next line is EOF then something is wrong */ printf("joules_extract: unexpected EOF. Something is wrong...\n"); } /* endif */ sscanf(in_buffer, "%ld %lf %ld %ld %ld %lf %lf %lf %lf %ld %ld %lf %lf %lf %lf %lf %lf %lf %lf", &ave_mhz, &busy, &bzy_mhz, &tsc_mhz, &smi, &c1, &c3, &c6, &c7, &coretmp, &pkgtmp, &pc2, &pc3, &pc6, &pc7, &joules, &c_joules, &g_joules, &p_time); fprintf(out, "%lf\n", joules); } /* endif */ } /* endwhile */ fclose(inf); fclose(out); printf("joules_extract: Done. Exiting...\n"); } /* endprogram */