2
* gtracestat.c: list the statistics information for a dumped xentrace file.
3
* Copyright (c) 2009, Intel Corporation.
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
* You should have received a copy of the GNU General Public License along with
15
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16
* Place - Suite 330, Boston, MA 02111-1307 USA.
27
#include <sys/types.h>
31
#include <xen/trace.h>
33
#define CHECK_DUP_CX 0
35
/********** MACROS **********/
38
#define MAX_MODE_NR 16
41
/* simplified xentrace record */
46
unsigned char irqs[4];
47
unsigned int predicted;
48
unsigned int expected;
52
/********** FORWARD DECLARATION **********/
54
void show_version(void);
55
int load_file(char *fname);
56
void do_digest(uint64_t start, uint64_t end, uint64_t scale);
57
void do_breakevents(void);
59
void do_px_count(void);
61
void do_average(void);
62
void do_cstate(uint64_t start, uint64_t end);
63
void do_exp_ratio(void);
64
void do_exp_pred(void);
66
/********** GLOBAL VARIABLES **********/
67
/* store simplified xentrace data */
69
int64_t data_nr, data_cur;
70
/* store max cx state number and cpu number */
71
int max_cx_num = -1, max_cpu_num = -1;
72
int px_freq_table[MAX_PX_NR];
75
int is_menu_gov_enabled = 0;
77
/* user specified translation unit */
78
uint64_t tsc2ms = 2793000UL;
79
uint64_t tsc2us = 2793UL;
80
uint64_t tsc2phase = 55800000UL;
82
/* each cpu column width */
85
/* digest mode variables */
86
struct rec *evt[MAX_CPU_NR];
87
int evt_len[MAX_CPU_NR];
89
/* hand-crafted min() */
90
static inline uint64_t min(uint64_t a, uint64_t b)
94
static inline uint64_t max(uint64_t a, uint64_t b)
101
int main(int argc, char *argv[])
104
/* operation flags */
105
int is_breakevents = 0;
110
int is_exp_ratio = 0;
112
uint64_t start_time = 0;
113
uint64_t time_scale = 0;
114
uint64_t end_time = 0;
116
struct option long_options [] = {
117
/* short options are listed correspondingly */
118
{ "version", 0, NULL, 'v' },
119
{ "help", 0, NULL, 'h' },
120
/* list Cx entires one by one */
121
{ "digest", 0, NULL, 'd' },
122
/* ignored when digest is disabled */
123
{ "start", 1, NULL, 's' },
124
{ "end", 1, NULL, 'e' },
125
{ "scale", 1, NULL, 'l' },
126
/* give summary about breakevents info */
127
{ "breakevents", 0, NULL, 'b' },
128
{ "count", 0, NULL, 'c' },
129
{ "average", 0, NULL, 'a' },
130
/* list max/min residency for each Cx */
131
{ "maxmin", 0, NULL, 'm' },
132
{ "tsc2us", 1, NULL, 'u' },
133
{ "px", 0, NULL, 'p' },
134
{ "tsc2phase", 1, NULL, 'n' },
135
{ "exp-ratio", 0, NULL, 'z' },
136
{ "exp-pred", 0, NULL, 'x' },
137
{ NULL, 0, NULL, 0 },
142
ch = getopt_long(argc, argv, "vhds:e:l:bcmaupnzx",
143
long_options, &opt_idx);
163
tsc2phase = atoll(optarg);
165
tsc2phase = 55800000UL;
170
start_time = atoll(optarg);
173
end_time = atoll(optarg);
176
time_scale = atoll(optarg);
191
tsc2us = atoll(optarg);
192
tsc2ms = tsc2us * 1000UL;
201
if (argc - optind > 1) {
202
printf("Multiple file specified?\n");
206
fname = argv[optind];
208
if (load_file(fname))
213
/* if people not specify the time related number,
214
* use the default one from the record.
217
start_time = data[0].tsc;
219
end_time = data[data_cur-1].tsc;
221
time_scale = 10UL * tsc2ms; /* default: 10 ms */
222
do_digest(start_time, end_time, time_scale);
228
if (is_count && !is_px)
230
if (is_count && is_px)
248
/* used for qsort() */
249
/* sort by cpu first, then by tsc */
250
static int data_cmp(const void *_a, const void *_b)
252
struct rec *a = (struct rec *)_a;
253
struct rec *b = (struct rec *)_b;
254
if (a->cpu == b->cpu)
255
return a->tsc > b->tsc ? 1 : -1;
256
return a->cpu > b->cpu ? 1 : -1;
259
/* load file and make them a list of records
260
* update these following variables:
261
* data, data_cur, data_nr
262
* max_cpu_num, max_cx_num
265
int load_file(char *fname)
267
/* file descriptor for raw xentrace file */
269
/* current cpu during xentrace data parse */
273
fd = open(fname, O_RDONLY);
275
fprintf(stderr, "file %s cannot open\n", fname);
279
/* the initial number is 1024,
280
* and when it overflows, this number doubles.
284
data = malloc(sizeof(struct rec) * data_nr);
286
fprintf(stderr, "not enough memory\n");
295
ret = read(fd, &rec, sizeof(uint32_t));
298
if (ret != sizeof(uint32_t)) {
299
fprintf(stderr, "reading header error\n");
304
if (rec.cycles_included)
305
size += sizeof(uint64_t);
306
size += sizeof(uint32_t) * rec.extra_u32;
308
ret = read(fd, (char *)&rec + sizeof(uint32_t), size);
312
fprintf(stderr, "reading data error\n");
316
if (rec.event == 0x1f003) {
317
/* cpu change event */
319
if (rec.extra_u32 > 0)
320
cur_cpu = rec.u.nocycles.extra_u32[0];
322
} else if (!rec.cycles_included ||
323
(rec.event != TRC_PM_IDLE_ENTRY &&
324
rec.event != TRC_PM_IDLE_EXIT &&
325
rec.event != TRC_PM_FREQ_CHANGE)) {
326
/* we care about only idle events now */
331
if (data_cur == data_nr) {
334
fprintf(stderr, "too many entries\n");
338
data = realloc(data, sizeof(struct rec) * data_nr);
340
fprintf(stderr, "not enough memory\n");
345
data[data_cur].tsc = rec.u.cycles.cycles_hi;
346
data[data_cur].tsc <<= 32;
347
data[data_cur].tsc |= rec.u.cycles.cycles_lo;
348
data[data_cur].cpu = cur_cpu;
350
if (rec.event != TRC_PM_FREQ_CHANGE)
353
if (rec.u.cycles.extra_u32[0] ==
354
rec.u.cycles.extra_u32[1])
356
data[data_cur].px = rec.u.cycles.extra_u32[1];
357
for (i = 0; i < max_px_num; i++)
358
if (px_freq_table[i] == data[data_cur].px)
361
px_freq_table[max_px_num++] = data[data_cur].px;
363
if (rec.event == TRC_PM_IDLE_ENTRY) {
364
data[data_cur].cx = rec.u.cycles.extra_u32[0];
365
if (rec.extra_u32 >= 4) {
366
data[data_cur].expected = rec.u.cycles.extra_u32[2];
367
data[data_cur].predicted = rec.u.cycles.extra_u32[3];
368
is_menu_gov_enabled = 1;
370
is_menu_gov_enabled = 0;
371
} else if (rec.event == TRC_PM_IDLE_EXIT) {
372
/* IDLE_EXIT default to C0 */
373
data[data_cur].cx = 0;
374
/* store the reasons why it exits */
375
data[data_cur].irqs[0] = rec.u.cycles.extra_u32[2];
376
data[data_cur].irqs[1] = rec.u.cycles.extra_u32[3];
377
data[data_cur].irqs[2] = rec.u.cycles.extra_u32[4];
378
data[data_cur].irqs[3] = rec.u.cycles.extra_u32[5];
381
/* update max info */
382
if (data[data_cur].cx > max_cx_num)
383
max_cx_num = data[data_cur].cx;
386
if (data[data_cur].cpu > max_cpu_num)
387
max_cpu_num = data[data_cur].cpu;
393
/* sort data array according to TSC time line */
394
qsort(data, data_cur, sizeof(struct rec), data_cmp);
399
for (i = 0; i < max_cpu_num; i++) {
403
for (i = data_cur-1; i >= 0; i--) {
404
evt[data[i].cpu] = data+i;
405
evt_len[data[i].cpu]++;
410
printf("Checking %s...\n", fname);
411
for (xx = 0; xx < max_cpu_num; xx++) {
412
// printf("............ CPU %d .............\n", xx);
413
for (yy = 0; yy+1 < evt_len[xx]; yy++)
414
if ( evt[xx][yy].cx > 0 && evt[xx][yy+1].cx > 0) {
415
printf("same witht next one %"PRIu64" %d %d\n",
416
evt[xx][yy].tsc, evt[xx][yy].cpu, evt[xx][yy].cx);
424
for (x = 0; x < max_cpu_num; x++) {
425
printf("CPU%d**************************************\n", x);
426
for (y = 0; y+1 < evt_len[x]; y++) {
427
printf("[%dHz]: phase: %d\n",
429
(int)((evt[x][y+1].tsc - evt[x][y].tsc)/tsc2phase));
436
void show_version(void)
438
printf("gtracestat - (C) 2009 Intel Corporation\n");
444
printf("tracestat <trace.data> [-vhdselbcmau]\n");
445
printf(" trace.data raw data got by 'xentrace -e 0x80f000 trace.dat'\n");
446
printf(" -v / --version show version message\n");
447
printf(" -h / --help show this message\n");
448
printf(" -d / --digest digest mode, more variables to specify.\n");
449
printf(" -s / --start <start_time> specify start time (only in digest mode)\n");
450
printf(" -e / --end <end_time> specify end time (only in digest mode)\n");
451
printf(" -l / --scale <scale> specify time scale (only in digest mode)\n");
452
printf(" -b / --breakevents give breakevents summary info\n");
453
printf(" -c / --count give count summary info\n");
454
printf(" -a / --average give total/average residency info\n");
455
printf(" -m / --maxmin show man/min residency summary info\n");
456
printf(" -u / --tsc2us specify how many tsc is a us unit\n");
457
printf(" -p / --px operate on Px entries\n");
458
printf(" -n / --tsc2phase specify how many tsc is a phase unit (only in px)\n");
459
printf(" -z / --exp-ratio show the ratio of early break events\n");
460
printf(" -x / --exp-pred show the ratio of expected / predicted in Cx entry\n");
463
static inline int len_of_number(uint64_t n)
473
/* determine the cx at time t
474
* take advantage of evt and evt_len.
476
int determine_cx(int c, uint64_t t)
481
while (i < evt_len[c] && evt[c][i].tsc <= t)
483
/* if there are any events happening,
484
* it must be in a Cx state now.
487
return evt[c][i-1].cx;
488
/* look forward to see whether it will enter
489
* a Cx state, if so, it must be in C0 state.
490
* we can't determine a Cx state from exit event.
492
if (i < evt_len[c] && evt[c][i].cx > 0)
500
* cx_i - number of cx index
501
* cx_r - residency of each cx entry
503
int process(int c, uint64_t t, uint64_t s, int *cx_i, uint64_t *cx_r)
509
cx = determine_cx(c, t);
511
while (i < evt_len[c] && evt[c][i].tsc < t)
514
if (cx >= 0 && i < evt_len[c]) {
516
cx_r[n] = evt[c][i].tsc - t;
520
while (i < evt_len[c] && evt[c][i].tsc < t+s) {
521
/* we are now at [t, t+s) */
523
len = min((i+1 < evt_len[c] ? evt[c][i+1].tsc : t+s), t+s)
536
void nr_putchar(int nr, int ch)
539
for (i = 0; i < nr; i++)
543
#define MAX_INTERVAL_ENTRY 1000
544
/* process period [start_time, start_time + time_scale) */
545
void single_digest(uint64_t start_time, uint64_t time_scale)
548
int cx_i[MAX_CPU_NR][MAX_INTERVAL_ENTRY];
549
uint64_t cx_r[MAX_CPU_NR][MAX_INTERVAL_ENTRY];
550
int cx_n[MAX_CPU_NR];
553
memset(cx_i, 0, sizeof(int) * MAX_CPU_NR * MAX_INTERVAL_ENTRY);
554
memset(cx_r, 0, sizeof(uint64_t) * MAX_CPU_NR * MAX_INTERVAL_ENTRY);
555
memset(cx_n, 0, sizeof(int) * MAX_CPU_NR);
558
for (cpu = 0; cpu < max_cpu_num; cpu++) {
559
cx_n[cpu] = process(cpu, start_time, time_scale, cx_i[cpu], cx_r[cpu]);
560
if (cx_n[cpu] > max_n)
564
/* means how many lines will be consumed */
565
while (--max_n >= 0) {
566
for (cpu = 0; cpu < max_cpu_num; cpu++) {
569
/* find the available cx index */
570
for (i = 0; i < MAX_INTERVAL_ENTRY && cx_i[cpu][i] == -1; i++)
572
if (i < MAX_INTERVAL_ENTRY) {
575
len= printf("C%d,%"PRIu64".%d", cx_i[cpu][i],
577
(unsigned int)(cx_r[cpu][i]/(tsc2ms/10))%10);
578
nr_putchar(width-len, ' ');
582
nr_putchar(width, ' ');
586
nr_putchar(width, ' ');
592
void do_digest(uint64_t start, uint64_t end, uint64_t scale)
596
uint64_t delta_ms = scale / tsc2ms;
598
for (i = 0; i < max_cpu_num; i++) {
600
len = printf("CPU%d", i);
601
nr_putchar(width-len, ' ');
604
while (start < end) {
605
/* print --- xxx ms --- line */
606
int off = (max_cpu_num * width - len_of_number(ms) - 2)/2;
607
nr_putchar(off, '-');
608
off += printf("%"PRIu64"ms", ms);
609
off += printf(" (%"PRIu64")", start);
610
nr_putchar(max_cpu_num * width-off, '-');
612
/* print each digest entries */
613
single_digest(start, scale);
628
void cond_rec_init(struct cond_rec *r, uint64_t min, uint64_t max)
635
void cond_rec_inc(uint64_t cur, struct cond_rec *r)
637
if (r->min <= cur && cur < r->max) {
643
/* c - current cpu to scan
644
* cx - cx state to track
645
* a - conditonal array
646
* n - how many entries there are
648
void do_count_per_cpu(int c, int cx, struct cond_rec *a, int n)
651
/* find Cx entry first */
653
while (i < evt_len[c] && evt[c][i].cx == 0)
655
/* check evt[c][i] and evt[c][i+1] */
656
while (i + 1 < evt_len[c]) {
657
if (evt[c][i].cx == cx) {
658
uint64_t len = evt[c][i+1].tsc - evt[c][i].tsc;
660
/* check for each condition */
661
for (j = 0; j < n; j++)
662
cond_rec_inc(len, a+j);
668
struct cond_rec *make_cond_rec(uint64_t *a, int n)
671
struct cond_rec *t = malloc(sizeof(struct cond_rec) * (n+1));
674
for (i = 0; i < n; i++) {
681
t[n].max = (uint64_t) -1;
688
uint64_t max_res[MAX_CPU_NR][MAX_CX_NR];
689
uint64_t min_res[MAX_CPU_NR][MAX_CX_NR];
690
uint64_t max_tm[MAX_CPU_NR][MAX_CX_NR];
691
uint64_t min_tm[MAX_CPU_NR][MAX_CX_NR];
693
void do_maxmin_per_cpu(int c)
696
/* find Cx entry first */
698
while (i < evt_len[c] && evt[c][i].cx == 0)
700
/* check evt[c][i] and evt[c][i+1] */
701
while (i + 1 < evt_len[c]) {
702
int cx = evt[c][i].cx;
703
uint64_t len = evt[c][i+1].tsc - evt[c][i].tsc;
704
if (len > max_res[c][cx]) {
705
max_res[c][cx] = len;
706
max_tm[c][cx] = evt[c][i].tsc;
708
if (len < min_res[c][cx]) {
709
min_res[c][cx] = len;
710
min_tm[c][cx] = evt[c][i].tsc;
720
for (i = 0; i < max_cpu_num; i++)
721
for (j = 0; j < max_cx_num; j++) {
723
min_res[i][j] = (uint64_t) -1;
726
for (i = 0; i < max_cpu_num; i++)
727
do_maxmin_per_cpu(i);
729
for (i = 0; i < max_cpu_num; i++) {
730
printf("********* CPU%d *********\n", i);
731
for (j = 0; j < max_cx_num; j++)
732
if (max_res[i][j] == 0)
733
printf(" not found ");
735
printf("%7"PRIu64"us (%15"PRIu64") ", max_res[i][j]/tsc2us, max_tm[i][j]);
737
for (j = 0; j < max_cx_num; j++)
738
if (max_res[i][j] == 0)
739
printf(" not found ");
741
printf("%7"PRIu64"us (%15"PRIu64") ", min_res[i][j]/tsc2us, min_tm[i][j]);
748
uint64_t scale[100] = { 50000UL, 100000UL, 200000UL, 400000UL, 800000UL, 1000000UL };
754
printf("Please input the period: (Ctrl+D to quit)\n");
755
printf("The default is 50us, 100us, 200us, 400us, 800us, 1000us.\n(unit is us, you DO NOT need to add us and specify ZERO us and please be in INCREASING order.)\n");
756
while (scanf("%d", &a[len]) == 1)
759
for (i = 0; i < len; i++)
760
scale[i] = a[i] * tsc2us;
763
for (i = 0; i < max_cpu_num; i++) {
764
struct cond_rec *r[MAX_CX_NR];
765
uint64_t sum[MAX_CX_NR];
768
printf("********** CPU%d *********\n", i);
769
for (j = 0; j < max_cx_num; j++) {
770
r[j] = make_cond_rec(scale, scale_len);
773
do_count_per_cpu(i, j, r[j], scale_len+1);
777
for (k = 0; k < scale_len+1; k++)
778
sum[j] += r[j][k].cnt;
783
for (j = 0; j < max_cx_num; j++)
786
for (k = 0; k < scale_len+1; k++) {
788
printf("%5"PRIu64" us -> MAX us:", r[0][k].min/tsc2us);
790
printf("%5"PRIu64" us -> %5"PRIu64" us:",
791
r[0][k].min/tsc2us, r[0][k].max/tsc2us);
792
for (j = 0; j < max_cx_num; j++)
793
printf(" %10"PRIu64" (%5.2f%%)",
794
r[j][k].cnt, 100.0 * (double) r[j][k].cnt / (double)sum[j]);
797
for (j = 0; j < max_cx_num; j++)
802
static void do_px_count_per_cpu(int c, int px, struct cond_rec *cond, int n)
808
while (i+1 < evt_len[c]) {
809
if (evt[c][i].px == px) {
810
len = evt[c][i+1].tsc - evt[c][i].tsc;
811
/* check each condition */
812
for (j = 0; j < n; j++)
813
cond_rec_inc(len, cond+j);
819
void do_px_count(void)
825
printf("Please input phases series: (Ctrl+D to quit)\n");
826
printf("The default is 1, 2, 4, 8, 16, 32.\n");
827
printf("Please be in increasing order.\n");
828
scale[0] = tsc2phase;
829
scale[1] = 2 * tsc2phase;
830
scale[2] = 4 * tsc2phase;
831
scale[3] = 8 * tsc2phase;
832
scale[4] = 16 * tsc2phase;
833
scale[5] = 32 * tsc2phase;
835
while (scanf("%d", &a[n]) == 1)
838
for (i = 0; i < n; i++)
839
scale[i] = a[i] * tsc2phase;
842
for (c = 0; c < max_cpu_num; c++) {
843
struct cond_rec *p[MAX_PX_NR];
846
printf("***** CPU%d *****\n", c);
847
for (i = 0; i < max_px_num; i++) {
848
p[i] = make_cond_rec(scale, n);
851
do_px_count_per_cpu(c, px_freq_table[i], p[i], n+1);
855
for (j = 0; j < max_px_num; j++)
856
printf("P%d\t", px_freq_table[j]);
858
for (k = 0; k < n+1; k++) {
860
printf("%5"PRIu64" -> MAX : ", p[0][k].min/tsc2phase);
862
printf("%5"PRIu64" -> %5"PRIu64": ",
863
p[0][k].min/tsc2phase, p[0][k].max/tsc2phase);
864
for (j = 0; j < max_px_num; j++) {
865
printf("%"PRIu64"\t", p[j][k].cnt);
871
for (j = 0; j < max_px_num; j++) {
873
for (k = 0; k < n+1; k++) {
874
sum += (int)p[j][k].cnt;
879
printf("\nAverage: ");
880
for (j = 0; j < max_px_num; j++) {
883
for (k = 0; k < n+1; k++) {
884
sum += (int)p[j][k].cnt;
885
s_res += (int)(p[j][k].res/tsc2phase);
890
printf("%.1f\t", (double)s_res/(double)sum);
893
for (j = 0; j < max_px_num; j++) {
895
for (k = 0; k < n+1; k++) {
896
s_res += (int)(p[j][k].res/tsc2phase);
899
printf("%d\t", s_res);
905
void do_breakevents(void)
907
int br[MAX_CPU_NR][257];
908
float pc[MAX_CPU_NR][257];
911
memset(br, 0, sizeof(int) * MAX_CPU_NR * 257);
912
memset(pc, 0, sizeof(int) * MAX_CPU_NR * 257);
914
for (i = 0; i < max_cpu_num; i++) {
916
for (j = 0; j < evt_len[i]; j++) {
917
if (evt[i][j].cx == 0) {
919
/* collect breakevents information */
921
for (k = 0; k < 4; k++) {
922
int irq = evt[i][j].irqs[k];
935
for (j = 0; j < 257; j++)
936
pc[i][j] = 100.0 * br[i][j]/sum;
938
/* print the results */
941
for (i = 0; i < max_cpu_num; i++) {
943
l += printf("CPU%d", i);
944
nr_putchar(width-l, ' ');
948
for (j = 0; j < 257; j++) {
950
for (i = 0; i < max_cpu_num; i++)
957
printf("[%03x] ", j);
958
for (i = 0; i < max_cpu_num; i++) {
961
l += printf("%.1f%%,%d ", pc[i][j], br[i][j]);
962
nr_putchar(width-l, ' ');
964
nr_putchar(width, ' ');
972
void single_cstate(int c, uint64_t t, uint64_t e,
977
void do_cstate(uint64_t start, uint64_t end)
979
uint64_t cxtime[MAX_CX_NR];
980
uint64_t max_res[MAX_CX_NR];
981
uint64_t min_res[MAX_CX_NR];
982
uint64_t num[MAX_CX_NR];
987
for (i = 0; i < max_cx_num; i++) {
988
int l = printf("C%d", i);
989
nr_putchar(width-l, ' ');
993
for (i = 0; i < max_cpu_num; i++) {
995
single_cstate(i, start, end, cxtime, max_res, min_res, num);
996
printf("CPU%2d ", i);
997
for (j = 0; j < max_cx_num; j++)
999
for (j = 0; j < max_cx_num; j++) {
1000
int l = printf("%.1f%%, %"PRIu64".%d, %"PRIu64".%d, %"PRIu64,
1001
100.0 * cxtime[j]/sum,
1003
(unsigned int)(max_res[j]/(tsc2ms/10))%10,
1005
(unsigned int)(min_res[j]/(tsc2ms/10))%10,
1006
cxtime[j]/num[j]/tsc2ms);
1007
nr_putchar(width - l, ' ');
1012
void single_cstate(int c, uint64_t t, uint64_t e,
1022
for (i = 0; i < max_cx_num; i++) {
1025
min_res[i] = (uint64_t) -1;
1029
cx = determine_cx(c, t);
1031
while (i < evt_len[c] && evt[c][i].tsc <= t)
1033
for (; i+1 < evt_len[c] && evt[c][i].tsc <= e; i++) {
1034
int cxidx = evt[c][i].cx;
1037
if (first && cx >= 0) {
1038
/* Partial Cx, only once */
1042
delta = evt[c][i].tsc - max(evt[c][i-1].tsc, t);
1046
/* update min and max residency */
1047
if (delta > max_res[cxidx])
1048
max_res[cxidx] = delta;
1049
if (delta < min_res[cxidx])
1050
min_res[cxidx] = delta;
1052
delta = evt[c][i+1].tsc - evt[c][i].tsc;
1056
/* update min and max residency */
1057
if (delta > max_res[cxidx])
1058
max_res[cxidx] = delta;
1059
if (delta < min_res[cxidx])
1060
min_res[cxidx] = delta;
1064
void do_average_per_cpu(int c)
1067
uint64_t tot[MAX_CX_NR] = { 0 };
1068
uint64_t cnt[MAX_CX_NR] = { 0 };
1071
/* find Cx entry first */
1073
while (i < evt_len[c] && evt[c][i].cx == 0)
1075
/* check evt[c][i] and evt[c][i+1] */
1076
while (i + 1 < evt_len[c]) {
1077
uint64_t len = evt[c][i+1].tsc - evt[c][i].tsc;
1078
int cx = evt[c][i].cx;
1084
/* prevent divide zero error */
1088
printf("CPU%d:\tResidency(ms)\t\tAvg Res(ms)\n", c);
1089
for (i = 0; i < max_cx_num; i++) {
1090
/* prevent divide zero error */
1093
printf(" C%d\t%"PRIu64"\t(%6.2f%%)\t%.2f\n", i,
1094
tot[i]/tsc2ms, 100.0 * tot[i] / (double)sum,
1095
(double)tot[i]/cnt[i]/tsc2ms );
1100
void do_average(void)
1104
for (i = 0; i < max_cpu_num; i++)
1105
do_average_per_cpu(i);
1108
static void do_exp_ratio_per_cpu(int c)
1111
uint64_t expected[MAX_CX_NR] = { 0 }, sum[MAX_CX_NR] = { 0 };
1114
while (i < evt_len[c] && evt[c][i].cx == 0)
1116
/* check evt[c][i] and evt[c][i+1] */
1117
while (i + 1 < evt_len[c]) {
1121
if ((evt[c][i].cx == 0 && evt[c][i+1].cx == 0) ||
1122
(evt[c][i].cx > 0 && evt[c][i+1].cx > 0)) {
1126
len = evt[c][i+1].tsc - evt[c][i].tsc;
1129
if ((len/tsc2us) <= evt[c][i].expected)
1136
printf("********** CPU%d **********\n", c);
1137
for (i = 1; i < max_cx_num; i++) {
1139
printf("C%d\t0\t0\t00.00%%\n", i);
1141
printf("C%d\t%"PRIu64"\t%"PRIu64"\t%4.2f%%\n",
1142
i, expected[i], sum[i], 100.0 * (double)expected[i]/(double)sum[i]);
1146
void do_exp_ratio(void)
1150
if (!is_menu_gov_enabled) {
1151
printf("The file seems doesn't consists the expected/predicted information.\n");
1155
printf("Cx\tearly\ttot\tratio(%%)\n");
1156
for (i = 0; i < max_cpu_num; i++)
1157
do_exp_ratio_per_cpu(i);
1160
static void do_exp_pred_per_cpu(int c)
1163
uint64_t expected[MAX_CX_NR] = { 0 }, sum[MAX_CX_NR] = { 0 };
1166
while (i < evt_len[c] && evt[c][i].cx == 0)
1168
/* check evt[c][i] and evt[c][i+1] */
1169
while (i + 1 < evt_len[c]) {
1172
if ((evt[c][i].cx == 0 && evt[c][i+1].cx == 0) ||
1173
(evt[c][i].cx > 0 && evt[c][i+1].cx > 0)) {
1179
if (evt[c][i].expected <= evt[c][i].predicted)
1186
printf("********** CPU%d **********\n", c);
1187
for (i = 1; i < max_cx_num; i++) {
1189
printf("C%d\t0\t0\t00.00%%\n", i);
1191
printf("C%d\t%"PRIu64"\t%"PRIu64"\t%4.2f%%\n",
1192
i, expected[i], sum[i], 100.0 * (double)expected[i]/(double)sum[i]);
1196
void do_exp_pred(void)
1200
if (!is_menu_gov_enabled) {
1201
printf("The file seems doesn't consists the expected/predicted information.\n");
1205
printf("Cx\texp\ttot\tratio(%%)\n");
1206
for (i = 0; i < max_cpu_num; i++)
1207
do_exp_pred_per_cpu(i);