17 #include <sys/types.h>
26 #define DEF(x) & x ## _monitor ,
28 #include "idle_monitors.def"
33 static unsigned int avail_monitors;
40 static char *show_monitors_param;
44 static char range_abbr[
RANGE_MAX] = {
'T',
'C',
'P',
'M', };
46 static void print_wrong_arg_exit(
void)
48 printf(
_(
"invalid or unknown argument\n"));
68 for (x = 0; x <
n; x++)
78 for (; len <
n; len++)
87 int state, need_len, pr_mon_len;
90 int percent_width = 4;
95 for (mon = 0; mon < avail_monitors; mon++) {
109 if (topology_depth > 2)
111 if (topology_depth > 1)
113 if (topology_depth > 0)
116 for (mon = 0; mon < avail_monitors; mon++) {
121 for (state = 0; state < monitors[mon]->
hw_states_num; state++) {
140 unsigned long long result;
147 if (topology_depth > 2)
148 printf(
"%4d|", cpu_top.core_info[cpu].pkg);
149 if (topology_depth > 1)
150 printf(
"%4d|", cpu_top.core_info[cpu].core);
151 if (topology_depth > 0)
152 printf(
"%4d|", cpu_top.core_info[cpu].cpu);
154 for (mon = 0; mon < avail_monitors; mon++) {
158 for (state = 0; state < monitors[mon]->
hw_states_num; state++) {
166 cpu_top.core_info[cpu].cpu);
169 else if (percent >= 100.0)
175 cpu_top.core_info[cpu].cpu);
181 printf(
_(
"Monitor %s, Counter %s has no count "
182 "function. Implementation error\n"),
194 if (!cpu_top.core_info[cpu].is_online) {
211 static void parse_monitor_param(
char *
param)
220 token = strtok(tmp,
",");
224 printf(
_(
"%s: max monitor name length"
229 for (num = 0; num < avail_monitors; num++) {
231 dprint(
"Found requested monitor: %s\n", token);
232 tmp_mons[hits] = monitors[num];
238 printf(
_(
"No matching monitor found in %s, "
239 "try -l option\n"), param);
243 memcpy(monitors, tmp_mons,
245 avail_monitors = hits;
254 for (mon = 0; mon < avail_monitors; mon++) {
255 printf(
_(
"Monitor \"%s\" (%d states) - Might overflow after %u "
260 for (state = 0; state < monitors[mon]->
hw_states_num; state++) {
276 unsigned long long timediff;
283 for (num = 0; num < avail_monitors; num++)
284 monitors[num]->
start();
288 execvp(argv[0], argv);
291 if (child_pid == -1) {
298 if (waitpid(child_pid, &status, 0) == -1) {
304 for (num = 0; num < avail_monitors; num++)
305 monitors[num]->
stop();
308 if (WIFEXITED(status))
309 printf(
_(
"%s took %.5f seconds and exited with status %d\n"),
310 argv[0], timediff / (1000.0 * 1000),
311 WEXITSTATUS(status));
319 for (num = 0; num < avail_monitors; num++) {
320 dprint(
"HW C-state residency monitor: %s - States: %d\n",
321 monitors[num]->
name, monitors[num]->hw_states_num);
322 monitors[num]->
start();
325 for (num = 0; num < avail_monitors; num++)
326 monitors[num]->
stop();
336 while ((opt = getopt(argc, argv,
"+li:m:")) != -1) {
340 print_wrong_arg_exit();
346 print_wrong_arg_exit();
351 print_wrong_arg_exit();
353 show_monitors_param = optarg;
356 print_wrong_arg_exit();
372 printf(
_(
"Cannot read number of available processors\n"));
382 for (num = 0; all_monitors[num]; num++) {
383 dprint(
"Try to register: %s\n", all_monitors[num]->
name);
387 fprintf(stderr,
_(
"Available monitor %s needs "
388 "root access\n"), test_mon->
name);
391 monitors[avail_monitors] = test_mon;
392 dprint(
"%s registered\n", all_monitors[num]->
name);
397 if (avail_monitors == 0) {
398 printf(
_(
"No HW Cstate monitors found\n"));
408 parse_monitor_param(show_monitors_param);
410 dprint(
"Packages: %d - Cores: %d - CPUs: %d\n",
423 if (cpu_top.pkgs > 1)
429 if (cpu_top.pkgs > 1)
435 for (num = 0; num < avail_monitors; num++)