Skip to content

Commit 5c56be9

Browse files
Dirk Brandewielenb
authored andcommitted
turbostat: Add option to report joules consumed per sample
Add "-J" option to report energy consumed in joules per sample. This option also adds the sample time to the reported values. Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent e6f9bb3 commit 5c56be9

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ char *proc_stat = "/proc/stat";
4343
unsigned int interval_sec = 5; /* set with -i interval_sec */
4444
unsigned int verbose; /* set with -v */
4545
unsigned int rapl_verbose; /* set with -R */
46+
unsigned int rapl_joules; /* set with -J */
4647
unsigned int thermal_verbose; /* set with -T */
4748
unsigned int summary_only; /* set with -s */
4849
unsigned int skip_c0;
@@ -317,19 +318,35 @@ void print_header(void)
317318
outp += sprintf(outp, " %%pc10");
318319
}
319320

320-
if (do_rapl & RAPL_PKG)
321-
outp += sprintf(outp, " Pkg_W");
322-
if (do_rapl & RAPL_CORES)
323-
outp += sprintf(outp, " Cor_W");
324-
if (do_rapl & RAPL_GFX)
325-
outp += sprintf(outp, " GFX_W");
326-
if (do_rapl & RAPL_DRAM)
327-
outp += sprintf(outp, " RAM_W");
328-
if (do_rapl & RAPL_PKG_PERF_STATUS)
329-
outp += sprintf(outp, " PKG_%%");
330-
if (do_rapl & RAPL_DRAM_PERF_STATUS)
331-
outp += sprintf(outp, " RAM_%%");
321+
if (do_rapl && !rapl_joules) {
322+
if (do_rapl & RAPL_PKG)
323+
outp += sprintf(outp, " Pkg_W");
324+
if (do_rapl & RAPL_CORES)
325+
outp += sprintf(outp, " Cor_W");
326+
if (do_rapl & RAPL_GFX)
327+
outp += sprintf(outp, " GFX_W");
328+
if (do_rapl & RAPL_DRAM)
329+
outp += sprintf(outp, " RAM_W");
330+
if (do_rapl & RAPL_PKG_PERF_STATUS)
331+
outp += sprintf(outp, " PKG_%%");
332+
if (do_rapl & RAPL_DRAM_PERF_STATUS)
333+
outp += sprintf(outp, " RAM_%%");
334+
} else {
335+
if (do_rapl & RAPL_PKG)
336+
outp += sprintf(outp, " Pkg_J");
337+
if (do_rapl & RAPL_CORES)
338+
outp += sprintf(outp, " Cor_J");
339+
if (do_rapl & RAPL_GFX)
340+
outp += sprintf(outp, " GFX_J");
341+
if (do_rapl & RAPL_DRAM)
342+
outp += sprintf(outp, " RAM_W");
343+
if (do_rapl & RAPL_PKG_PERF_STATUS)
344+
outp += sprintf(outp, " PKG_%%");
345+
if (do_rapl & RAPL_DRAM_PERF_STATUS)
346+
outp += sprintf(outp, " RAM_%%");
347+
outp += sprintf(outp, " time");
332348

349+
}
333350
outp += sprintf(outp, "\n");
334351
}
335352

@@ -548,19 +565,39 @@ int format_counters(struct thread_data *t, struct core_data *c,
548565
fmt6 = " %4.0f**";
549566
}
550567

551-
if (do_rapl & RAPL_PKG)
552-
outp += sprintf(outp, fmt6, p->energy_pkg * rapl_energy_units / interval_float);
553-
if (do_rapl & RAPL_CORES)
554-
outp += sprintf(outp, fmt6, p->energy_cores * rapl_energy_units / interval_float);
555-
if (do_rapl & RAPL_GFX)
556-
outp += sprintf(outp, fmt5, p->energy_gfx * rapl_energy_units / interval_float);
557-
if (do_rapl & RAPL_DRAM)
558-
outp += sprintf(outp, fmt5, p->energy_dram * rapl_energy_units / interval_float);
559-
if (do_rapl & RAPL_PKG_PERF_STATUS )
560-
outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float);
561-
if (do_rapl & RAPL_DRAM_PERF_STATUS )
562-
outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float);
568+
if (do_rapl && !rapl_joules) {
569+
if (do_rapl & RAPL_PKG)
570+
outp += sprintf(outp, fmt6, p->energy_pkg * rapl_energy_units / interval_float);
571+
if (do_rapl & RAPL_CORES)
572+
outp += sprintf(outp, fmt6, p->energy_cores * rapl_energy_units / interval_float);
573+
if (do_rapl & RAPL_GFX)
574+
outp += sprintf(outp, fmt5, p->energy_gfx * rapl_energy_units / interval_float);
575+
if (do_rapl & RAPL_DRAM)
576+
outp += sprintf(outp, fmt5, p->energy_dram * rapl_energy_units / interval_float);
577+
if (do_rapl & RAPL_PKG_PERF_STATUS)
578+
outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float);
579+
if (do_rapl & RAPL_DRAM_PERF_STATUS)
580+
outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float);
581+
} else {
582+
if (do_rapl & RAPL_PKG)
583+
outp += sprintf(outp, fmt6,
584+
p->energy_pkg * rapl_energy_units);
585+
if (do_rapl & RAPL_CORES)
586+
outp += sprintf(outp, fmt6,
587+
p->energy_cores * rapl_energy_units);
588+
if (do_rapl & RAPL_GFX)
589+
outp += sprintf(outp, fmt5,
590+
p->energy_gfx * rapl_energy_units);
591+
if (do_rapl & RAPL_DRAM)
592+
outp += sprintf(outp, fmt5,
593+
p->energy_dram * rapl_energy_units);
594+
if (do_rapl & RAPL_PKG_PERF_STATUS)
595+
outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float);
596+
if (do_rapl & RAPL_DRAM_PERF_STATUS)
597+
outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float);
598+
outp += sprintf(outp, fmt5, interval_float);
563599

600+
}
564601
done:
565602
outp += sprintf(outp, "\n");
566603

@@ -2340,7 +2377,7 @@ void cmdline(int argc, char **argv)
23402377

23412378
progname = argv[0];
23422379

2343-
while ((opt = getopt(argc, argv, "+pPSvi:sc:sC:m:M:RT:")) != -1) {
2380+
while ((opt = getopt(argc, argv, "+pPSvi:sc:sC:m:M:RJT:")) != -1) {
23442381
switch (opt) {
23452382
case 'p':
23462383
show_core_only++;
@@ -2375,6 +2412,10 @@ void cmdline(int argc, char **argv)
23752412
case 'T':
23762413
tcc_activation_temp_override = atoi(optarg);
23772414
break;
2415+
case 'J':
2416+
rapl_joules++;
2417+
break;
2418+
23782419
default:
23792420
usage();
23802421
}

0 commit comments

Comments
 (0)