diff options
author | Glenn Kasten <gkasten@google.com> | 2012-02-24 07:21:32 -0800 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2012-02-24 13:56:12 -0800 |
commit | 6ec27552a0011906345f803a41fa4e9e11d3988a (patch) | |
tree | 35921ff40976cbe9779e1ebed29df56b3adbb75e /services/audioflinger | |
parent | be3835c64dc782c1c40ebf75badd1db47aff7b1a (diff) | |
download | frameworks_base-6ec27552a0011906345f803a41fa4e9e11d3988a.zip frameworks_base-6ec27552a0011906345f803a41fa4e9e11d3988a.tar.gz frameworks_base-6ec27552a0011906345f803a41fa4e9e11d3988a.tar.bz2 |
Pull CPU statistics code out of threadLoop()
This is to prepare for the threadLoop() merge
Change-Id: I118c7d5c6b011b5d5b95ec7d63fb03feb166a9cf
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 6256951..74eba2f 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1932,6 +1932,46 @@ AudioFlinger::MixerThread::~MixerThread() delete mAudioMixer; } +class CpuStats { +public: + void sample(); +#ifdef DEBUG_CPU_USAGE +private: + ThreadCpuUsage mCpu; +#endif +}; + +void CpuStats::sample() { +#ifdef DEBUG_CPU_USAGE + const CentralTendencyStatistics& stats = mCpu.statistics(); + mCpu.sampleAndEnable(); + unsigned n = stats.n(); + // mCpu.elapsed() is expensive, so don't call it every loop + if ((n & 127) == 1) { + long long elapsed = mCpu.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(); + mCpu.resetStatistics(); + ALOGI("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 +}; + bool AudioFlinger::MixerThread::threadLoop() { Vector< sp<Track> > tracksToRemove; @@ -1950,42 +1990,13 @@ bool AudioFlinger::MixerThread::threadLoop() uint32_t sleepTime = idleSleepTime; uint32_t sleepTimeShift = 0; Vector< sp<EffectChain> > effectChains; -#ifdef DEBUG_CPU_USAGE - ThreadCpuUsage cpu; - const CentralTendencyStatistics& stats = cpu.statistics(); -#endif + CpuStats cpuStats; acquireWakeLock(); 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(); - ALOGI("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 + cpuStats.sample(); processConfigEvents(); mixerStatus = MIXER_IDLE; |