atrace: add clock rate and bus utilization

Change-Id: I4e1764b51225436fc2b3d61454ee822f511a1a7d
This commit is contained in:
Erik Gilling 2012-09-20 17:55:10 -07:00
parent 4b23eefd72
commit 99be77cf00

View File

@ -30,7 +30,8 @@
/* Command line options */ /* Command line options */
static int g_traceDurationSeconds = 5; static int g_traceDurationSeconds = 5;
static bool g_traceSchedSwitch = false; static bool g_traceSchedSwitch = false;
static bool g_traceCpuFrequency = false; static bool g_traceFrequency = false;
static bool g_traceBusUtilization = false;
static bool g_traceCpuIdle = false; static bool g_traceCpuIdle = false;
static bool g_traceDisk = false; static bool g_traceDisk = false;
static bool g_traceGovernorLoad = false; static bool g_traceGovernorLoad = false;
@ -58,9 +59,15 @@ static const char* k_schedSwitchEnablePath =
static const char* k_schedWakeupEnablePath = static const char* k_schedWakeupEnablePath =
"/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable"; "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable";
static const char* k_memoryBusEnablePath =
"/sys/kernel/debug/tracing/events/memory_bus/enable";
static const char* k_cpuFreqEnablePath = static const char* k_cpuFreqEnablePath =
"/sys/kernel/debug/tracing/events/power/cpu_frequency/enable"; "/sys/kernel/debug/tracing/events/power/cpu_frequency/enable";
static const char *k_clockSetRateEnablePath =
"/sys/kernel/debug/tracing/events/power/clock_set_rate/enable";
static const char* k_cpuIdleEnablePath = static const char* k_cpuIdleEnablePath =
"/sys/kernel/debug/tracing/events/power/cpu_idle/enable"; "/sys/kernel/debug/tracing/events/power/cpu_idle/enable";
@ -141,10 +148,23 @@ static bool setSchedSwitchTracingEnable(bool enable)
return ok; return ok;
} }
// Enable or disable tracing of the CPU clock frequency. // Enable or disable tracing of the Bus utilization.
static bool setCpuFrequencyTracingEnable(bool enable) static bool setBusUtilizationTracingEnable(bool enable)
{ {
return setKernelOptionEnable(k_cpuFreqEnablePath, enable); bool ok = false;
// these can be platform specific so make sure that at least
// one succeeds.
ok |= setKernelOptionEnable(k_memoryBusEnablePath, enable);
return ok;
}
// Enable or disable tracing of the CPU clock frequency.
static bool setFrequencyTracingEnable(bool enable)
{
bool ok = true;
ok &= setKernelOptionEnable(k_cpuFreqEnablePath, enable);
ok &= setKernelOptionEnable(k_clockSetRateEnablePath, enable);
return ok;
} }
// Enable or disable tracing of CPU idle events. // Enable or disable tracing of CPU idle events.
@ -225,7 +245,8 @@ static bool startTrace(bool isRoot)
// Set up the tracing options that don't require root. // Set up the tracing options that don't require root.
ok &= setTraceOverwriteEnable(g_traceOverwrite); ok &= setTraceOverwriteEnable(g_traceOverwrite);
ok &= setSchedSwitchTracingEnable(g_traceSchedSwitch); ok &= setSchedSwitchTracingEnable(g_traceSchedSwitch);
ok &= setCpuFrequencyTracingEnable(g_traceCpuFrequency); ok &= setBusUtilizationTracingEnable(g_traceBusUtilization);
ok &= setFrequencyTracingEnable(g_traceFrequency);
ok &= setCpuIdleTracingEnable(g_traceCpuIdle); ok &= setCpuIdleTracingEnable(g_traceCpuIdle);
if (fileExists(k_governorLoadEnablePath) || g_traceGovernorLoad) { if (fileExists(k_governorLoadEnablePath) || g_traceGovernorLoad) {
ok &= setGovernorLoadTracingEnable(g_traceGovernorLoad); ok &= setGovernorLoadTracingEnable(g_traceGovernorLoad);
@ -260,7 +281,8 @@ static void stopTrace(bool isRoot)
// Set the options back to their defaults. // Set the options back to their defaults.
setTraceOverwriteEnable(true); setTraceOverwriteEnable(true);
setSchedSwitchTracingEnable(false); setSchedSwitchTracingEnable(false);
setCpuFrequencyTracingEnable(false); setBusUtilizationTracingEnable(false);
setFrequencyTracingEnable(false);
if (fileExists(k_governorLoadEnablePath)) { if (fileExists(k_governorLoadEnablePath)) {
setGovernorLoadTracingEnable(false); setGovernorLoadTracingEnable(false);
} }
@ -380,10 +402,11 @@ static void showHelp(const char *cmd)
" -b N use a trace buffer size of N KB\n" " -b N use a trace buffer size of N KB\n"
" -c trace into a circular buffer\n" " -c trace into a circular buffer\n"
" -d trace disk I/O\n" " -d trace disk I/O\n"
" -f trace CPU frequency changes\n" " -f trace clock frequency changes\n"
" -l trace CPU frequency governor load\n" " -l trace CPU frequency governor load\n"
" -s trace the kernel scheduler switches\n" " -s trace the kernel scheduler switches\n"
" -t N trace for N seconds [defualt 5]\n" " -t N trace for N seconds [defualt 5]\n"
" -u trace bus utilization\n"
" -w trace the kernel workqueue\n" " -w trace the kernel workqueue\n"
" -z compress the trace dump\n"); " -z compress the trace dump\n");
} }
@ -415,7 +438,7 @@ int main(int argc, char **argv)
for (;;) { for (;;) {
int ret; int ret;
ret = getopt(argc, argv, "b:cidflst:wz"); ret = getopt(argc, argv, "b:cidflst:uwz");
if (ret < 0) { if (ret < 0) {
break; break;
@ -447,7 +470,7 @@ int main(int argc, char **argv)
break; break;
case 'f': case 'f':
g_traceCpuFrequency = true; g_traceFrequency = true;
break; break;
case 's': case 's':
@ -458,6 +481,14 @@ int main(int argc, char **argv)
g_traceDurationSeconds = atoi(optarg); g_traceDurationSeconds = atoi(optarg);
break; break;
case 'u':
if (!isRoot) {
fprintf(stderr, "error: tracing bus utilization requires root privileges\n");
exit(1);
}
g_traceBusUtilization = true;
break;
case 'w': case 'w':
if (!isRoot) { if (!isRoot) {
fprintf(stderr, "error: tracing kernel work queues requires root privileges\n"); fprintf(stderr, "error: tracing kernel work queues requires root privileges\n");