diff options
author | Glenn Kasten <gkasten@google.com> | 2011-07-15 16:27:13 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-15 16:27:13 -0700 |
commit | 0bd30801c9e0abf6a8a29aab4686de7bce5a5a84 (patch) | |
tree | bc335e3e0228207ff4c854ed51252afdd5ed9ae0 /services/audioflinger | |
parent | 7e7de71f6eef5652ee1260e40215804a2ce543c3 (diff) | |
parent | da494f962592960f2eb5111ad3f7abe1ff8732d5 (diff) | |
download | frameworks_base-0bd30801c9e0abf6a8a29aab4686de7bce5a5a84.zip frameworks_base-0bd30801c9e0abf6a8a29aab4686de7bce5a5a84.tar.gz frameworks_base-0bd30801c9e0abf6a8a29aab4686de7bce5a5a84.tar.bz2 |
Merge "Log CPU usage"
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/Android.mk | 1 | ||||
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/services/audioflinger/Android.mk b/services/audioflinger/Android.mk index 6bb1f56..a0407b9 100644 --- a/services/audioflinger/Android.mk +++ b/services/audioflinger/Android.mk @@ -24,6 +24,7 @@ LOCAL_SHARED_LIBRARIES := \ libdl LOCAL_STATIC_LIBRARIES := \ + libcpustats \ libmedia_helper LOCAL_MODULE:= libaudioflinger diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index daf94f2..86d4cc3 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -52,6 +52,9 @@ #include <media/EffectsFactoryApi.h> #include <audio_effects/effect_visualizer.h> +#include <cpustats/ThreadCpuUsage.h> +// #define DEBUG_CPU_USAGE 10 // log statistics every n wall clock seconds + // ---------------------------------------------------------------------------- @@ -1529,9 +1532,40 @@ bool AudioFlinger::MixerThread::threadLoop() uint32_t idleSleepTime = idleSleepTimeUs(); uint32_t sleepTime = idleSleepTime; Vector< sp<EffectChain> > effectChains; +#ifdef DEBUG_CPU_USAGE + ThreadCpuUsage cpu; + const CentralTendencyStatistics& stats = cpu.statistics(); +#endif while (!exitPending()) { +#ifdef DEBUG_CPU_USAGE + cpu.sampleAndEnable(); + unsigned n = stats.n(); + // cpu.elapsed() is expensive, so don't call it every loop + if ((n & 127) == 1) { + long long elapsed = cpu.elapsed(); + if (elapsed >= DEBUG_CPU_USAGE * 1000000000LL) { + double perLoop = elapsed / (double) n; + double perLoop100 = perLoop * 0.01; + double mean = stats.mean(); + double stddev = stats.stddev(); + double minimum = stats.minimum(); + double maximum = stats.maximum(); + cpu.resetStatistics(); + LOGI("CPU usage over past %.1f secs (%u mixer loops at %.1f mean ms per loop):\n us per mix loop: mean=%.0f stddev=%.0f min=%.0f max=%.0f\n %% of wall: mean=%.1f stddev=%.1f min=%.1f max=%.1f", + elapsed * .000000001, n, perLoop * .000001, + mean * .001, + stddev * .001, + minimum * .001, + maximum * .001, + mean / perLoop100, + stddev / perLoop100, + minimum / perLoop100, + maximum / perLoop100); + } + } +#endif processConfigEvents(); mixerStatus = MIXER_IDLE; |