File: default_report.c

package info (click to toggle)
idlestat 0.8-4
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 452 kB
  • sloc: ansic: 6,237; makefile: 57
file content (358 lines) | stat: -rw-r--r-- 9,822 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
 *  default_report.c
 *
 *  Copyright (C) 2014, Linaro Limited.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * Contributors:
 *     Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
 *
 */
#include <float.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "report_ops.h"
#include "idlestat.h"
#include "utils.h"
#include "compiler.h"


static void charrep(char c, int count)
{
	int i;
	for (i = 0; i < count; i++)
		printf("%c", c);
}

static int default_check_output(struct program_options *options,
				UNUSED void *report_data)
{
	if (check_window_size() && !options->outfilename) {
		fprintf(stderr, "The terminal must be at least "
			"80 columns wide\n");
		return 1;
	}
	return 0;
}

static int default_open_report_file(char *path, UNUSED void *report_data)
{
	return redirect_stdout_to_file(path);
}

static int default_close_report_file(UNUSED void *report_data)
{
	return (fclose(stdout) == EOF) ? -1 : 0;
}


/* Topology headers for all tables (C-state/P-state/Wakeups) */

static void boxless_cpu_header(const char *cpu, UNUSED void *report_data)
{
	/* No pipe characters and less aggressive indentions */
        if (strstr(cpu, "cluster"))
                printf("  %s\n", cpu);
        else if (strstr(cpu, "core"))
                printf("    %s\n", cpu);
        else printf("       %s\n", cpu);
}

static void default_cpu_header(const char *cpu, int len)
{
        charrep('-', len);
        printf("\n");

        if (strstr(cpu, "cluster"))
                printf("| %-*s |\n", len - 4, cpu);
        else if (strstr(cpu, "core"))
                printf("|      %-*s |\n", len - 9, cpu);
        else printf("|             %-*s |\n", len - 16, cpu);

	charrep('-', len);
	printf("\n");
}

static void default_end_cpu(UNUSED void *report_data)
{
}

static void boxless_end_cpu(UNUSED void *report_data)
{
	printf("\n");
}


/* C-states */

static void boxless_cstate_table_header(UNUSED void *report_data)
{
	/* Note: Data is right-aligned, so boxless headers are too */
	printf("   C-state        min        max        avg      total    hits    over   under\n");
}

static void default_cstate_table_header(UNUSED void *report_data)
{
	/* Note: Boxed header columns appear centered */
	charrep('-', 80);
	printf("\n| C-state  |   min    |   max    |   avg    |   total  | hits  |  over | under |\n");
}

static void default_cstate_cpu_header(const char *cpu,
				      UNUSED void *report_data)
{
	default_cpu_header(cpu, 80);
}

static void boxless_cstate_single_state(struct cpuidle_cstate *c,
					UNUSED void *report_data)
{
	printf("  %8s   ", c->name);
	display_factored_time(c->min_time == DBL_MAX ? 0. :
				      c->min_time, 8);
	printf("   ");
	display_factored_time(c->max_time, 8);
	printf("   ");
	display_factored_time(c->avg_time, 8);
	printf("   ");
	display_factored_time(c->duration, 8);
	printf("   ");
	printf("%5d   %5d   %5d\n", c->nrdata, c->early_wakings,
	       c->late_wakings);
}

static void default_cstate_single_state(struct cpuidle_cstate *c,
					UNUSED void *report_data)
{
	printf("| %8s | ", c->name);
	display_factored_time(c->min_time == DBL_MAX ? 0. :
				      c->min_time, 8);
	printf(" | ");
	display_factored_time(c->max_time, 8);
	printf(" | ");
	display_factored_time(c->avg_time, 8);
	printf(" | ");
	display_factored_time(c->duration, 8);
	printf(" | ");
	printf("%5d | %5d | %5d |\n", c->nrdata, c->early_wakings,
	       c->late_wakings);
}

static void boxless_cstate_table_footer(UNUSED void *report_data)
{
	printf("\n");
}

static void default_cstate_table_footer(UNUSED void *report_data)
{
	charrep('-', 80);
	printf("\n\n");
}


/* P-states */

static void boxless_pstate_table_header(UNUSED void *report_data)
{
	/* Note: Data is right-aligned, so boxless headers are too */
	printf("   P-state        min        max        avg      total    hits\n");
}

static void default_pstate_table_header(UNUSED void *report_data)
{
	charrep('-', 64);
	printf("\n");

	/* Note: Boxed header columns appear centered */
	printf("| P-state  |   min    |   max    |   avg    |   total  | hits  |\n");
}

static void default_pstate_cpu_header(const char *cpu,
				      UNUSED void *report_data)
{
	default_cpu_header(cpu, 64);
}

static void boxless_pstate_single_freq(struct cpufreq_pstate *p,
				       UNUSED void *report_data)
{
	printf("  ");
	display_factored_freq(p->freq, 8);
	printf("   ");
	display_factored_time(p->min_time == DBL_MAX ? 0. : p->min_time, 8);
	printf("   ");
	display_factored_time(p->max_time, 8);
	printf("   ");
	display_factored_time(p->avg_time, 8);
	printf("   ");
	display_factored_time(p->duration, 8);
	printf("   %5d\n", p->count);
}

static void default_pstate_single_freq(struct cpufreq_pstate *p,
				       UNUSED void *report_data)
{
	printf("| ");
	display_factored_freq(p->freq, 8);
	printf(" | ");
	display_factored_time(p->min_time == DBL_MAX ? 0. : p->min_time, 8);
	printf(" | ");
	display_factored_time(p->max_time, 8);
	printf(" | ");
	display_factored_time(p->avg_time, 8);
	printf(" | ");
	display_factored_time(p->duration, 8);
	printf(" | %5d |\n", p->count);
}

static void boxless_pstate_table_footer(UNUSED void *report_data)
{
	printf("\n");
}

static void default_pstate_table_footer(UNUSED void *report_data)
{
	charrep('-', 64);
	printf("\n\n");
}


/* Wakeups */

static void boxless_wakeup_table_header(UNUSED void *report_data)
{
	/*
	 * Note: Columns 1 and 2 are left-aligned, others are right-aligned.
	 * Boxless headers follow the data convention
	 */
	printf("  IRQ   Name                Count     early      late\n");
}

static void default_wakeup_table_header(UNUSED void *report_data)
{
	charrep('-', 55);
	printf("\n");

	/* Note: Boxed header columns appear centered */
	printf("| IRQ |       Name      |  Count  |  early  |  late   |\n");
}

static void default_wakeup_cpu_header(const char *cpu,
				      UNUSED void *report_data)
{
	default_cpu_header(cpu, 55);
}

static void boxless_wakeup_single_irq(struct wakeup_irq *irqinfo,
				      UNUSED void *report_data)
{
	if (irqinfo->id != -1) {
		printf("  %-3d   %-15.15s   %7d   %7d   %7d\n",
		       irqinfo->id, irqinfo->name, irqinfo->count,
		       irqinfo->early_triggers, irqinfo->late_triggers);
	} else {
		printf("  IPI   %-15.15s   %7d   %7d   %7d\n",
		       irqinfo->name, irqinfo->count,
		       irqinfo->early_triggers, irqinfo->late_triggers);
	}
}

static void default_wakeup_single_irq(struct wakeup_irq *irqinfo,
				      UNUSED void *report_data)
{
	if (irqinfo->id != -1) {
		printf("| %-3d | %-15.15s | %7d | %7d | %7d |\n",
		       irqinfo->id, irqinfo->name, irqinfo->count,
		       irqinfo->early_triggers, irqinfo->late_triggers);
	} else {
		printf("| IPI | %-15.15s | %7d | %7d | %7d |\n",
		       irqinfo->name, irqinfo->count,
		       irqinfo->early_triggers, irqinfo->late_triggers);
	}
}

static void boxless_wakeup_table_footer(UNUSED void *report_data)
{
	printf("\n");
}

static void default_wakeup_table_footer(UNUSED void *report_data)
{
	charrep('-', 55);
	printf("\n\n");
}


static struct report_ops default_report_ops = {
	.name = "default",
	.check_output = default_check_output, /* Shared */

	.open_report_file = default_open_report_file, /* Shared */
	.close_report_file = default_close_report_file, /* Shared */

	.cstate_table_header = default_cstate_table_header,
	.cstate_table_footer = default_cstate_table_footer,
	.cstate_cpu_header = default_cstate_cpu_header,
	.cstate_single_state = default_cstate_single_state,
	.cstate_end_cpu = default_end_cpu,

	.pstate_table_header = default_pstate_table_header,
	.pstate_table_footer = default_pstate_table_footer,
	.pstate_cpu_header = default_pstate_cpu_header,
	.pstate_single_freq = default_pstate_single_freq,
	.pstate_end_cpu = default_end_cpu,

	.wakeup_table_header = default_wakeup_table_header,
	.wakeup_table_footer = default_wakeup_table_footer,
	.wakeup_cpu_header = default_wakeup_cpu_header,
	.wakeup_single_irq = default_wakeup_single_irq,
	.wakeup_end_cpu = default_end_cpu,
};

EXPORT_REPORT_OPS(default);

static struct report_ops boxless_report_ops = {
	.name = "boxless",
	.check_output = default_check_output,

	.open_report_file = default_open_report_file,
	.close_report_file = default_close_report_file,

	.cstate_table_header = boxless_cstate_table_header,
	.cstate_table_footer = boxless_cstate_table_footer,
	.cstate_cpu_header = boxless_cpu_header,
	.cstate_single_state = boxless_cstate_single_state,
	.cstate_end_cpu = boxless_end_cpu,

	.pstate_table_header = boxless_pstate_table_header,
	.pstate_table_footer = boxless_pstate_table_footer,
	.pstate_cpu_header = boxless_cpu_header,
	.pstate_single_freq = boxless_pstate_single_freq,
	.pstate_end_cpu = boxless_end_cpu,

	.wakeup_table_header = boxless_wakeup_table_header,
	.wakeup_table_footer = boxless_wakeup_table_footer,
	.wakeup_cpu_header = boxless_cpu_header,
	.wakeup_single_irq = boxless_wakeup_single_irq,
	.wakeup_end_cpu = boxless_end_cpu,
};

EXPORT_REPORT_OPS(boxless);