- /* Display C-states */
- show_cstates(cstate_lines);
-
- /* Do timer_stats info */
- buf[0] = '\0';
- totalticks = 0;
-
- fp = NULL;
- if (!G.cant_enable_timer_stats)
- fp = fopen_for_read("/proc/timer_stats");
- if (fp) {
-// Examlpe file contents:
-// Timer Stats Version: v0.2
-// Sample period: 1.329 s
-// 76, 0 swapper hrtimer_start_range_ns (tick_sched_timer)
-// 88, 0 swapper hrtimer_start_range_ns (tick_sched_timer)
-// 24, 3787 firefox hrtimer_start_range_ns (hrtimer_wakeup)
-// 46D, 1136 kondemand/1 do_dbs_timer (delayed_work_timer_fn)
-// ...
-// 1, 1656 Xorg hrtimer_start_range_ns (hrtimer_wakeup)
-// 1, 2159 udisks-daemon hrtimer_start_range_ns (hrtimer_wakeup)
-// 331 total events, 249.059 events/sec
- while (fgets(buf, sizeof(buf), fp)) {
- const char *count, *process, *func;
- char *p;
- char line[512];
- int cnt = 0;
-// TODO: optimize
- if (strstr(buf, "total events"))
- break;
- count = skip_whitespace(buf);
- p = strchr(count, ',');
- if (!p)
- continue;
- *p++ = '\0';
- p = skip_whitespace(p); /* points to pid */
-
-/* Find char ' ', then eat remaining spaces */
-#define ADVANCE(p) do { \
- (p) = strchr((p), ' '); \
- if (!(p)) \
- continue; \
- *(p) = '\0'; \
- (p)++; \
- (p) = skip_whitespace(p); \
-} while (0)
- /* Get process name */
- ADVANCE(p);
- process = p;
-
- /* Get function */
- ADVANCE(p);
- func = p;
-
- if (strcmp(process, "swapper") == 0
- && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0
- ) {
- process = "[kernel scheduler]";
- func = "Load balancing tick";
- }
-
- if (strcmp(process, "insmod") == 0)
- process = "[kernel module]";
- if (strcmp(process, "modprobe") == 0)
- process = "[kernel module]";
- if (strcmp(process, "swapper") == 0)
- process = "[kernel core]";
-
- if (strncmp(func, "tick_nohz_", 10) == 0)
- continue;
- if (strncmp(func, "tick_setup_sched_timer", 20) == 0)
- continue;
- if (strcmp(process, "powertop") == 0)
- continue;
-
- strchrnul(p, '\n')[0] = '\0';
-
- cnt = bb_strtoull(count, &p, 10);
- while (*p != '\0') {
- if (*p++ == 'D')
- goto skip;
- }
-
- if (strchr(process, '['))
- sprintf(line, "%s %s", process, func);
- else
- sprintf(line, "%s", process);
- save_line(line, cnt);
- skip: ;
- }
- fclose(fp);
- }