Loading services/audioflinger/Configuration.h +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ //#define AUDIO_WATCHDOG // uncomment to display CPU load adjusted for CPU frequency #define CPU_FREQUENCY_STATISTICS //define CPU_FREQUENCY_STATISTICS // uncomment to enable fast threads to take performance samples for later statistical analysis #define FAST_THREAD_STATISTICS Loading services/audioflinger/FastMixer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ #include <utils/Trace.h> #include <system/audio.h> #ifdef FAST_THREAD_STATISTICS #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #ifdef CPU_FREQUENCY_STATISTICS #include <cpustats/ThreadCpuUsage.h> #endif Loading services/audioflinger/FastMixerDumpState.cpp +20 −20 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ #include "Configuration.h" #ifdef FAST_THREAD_STATISTICS #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #ifdef CPU_FREQUENCY_STATISTICS #include <cpustats/ThreadCpuUsage.h> #endif Loading Loading @@ -92,9 +92,9 @@ void FastMixerDumpState::dump(int fd) const } // statistics for monotonic (wall clock) time, thread raw CPU load in time, CPU clock frequency, // and adjusted CPU load in MHz normalized for CPU clock frequency CentralTendencyStatistics wall, loadNs; Statistics<double> wall, loadNs; #ifdef CPU_FREQUENCY_STATISTICS CentralTendencyStatistics kHz, loadMHz; Statistics<double> kHz, loadMHz; uint32_t previousCpukHz = 0; #endif // Assuming a normal distribution for cycle times, three standard deviations on either side of Loading @@ -109,18 +109,18 @@ void FastMixerDumpState::dump(int fd) const if (tail != NULL) { tail[j] = wallNs; } wall.sample(wallNs); wall.add(wallNs); uint32_t sampleLoadNs = mLoadNs[i]; loadNs.sample(sampleLoadNs); loadNs.add(sampleLoadNs); #ifdef CPU_FREQUENCY_STATISTICS uint32_t sampleCpukHz = mCpukHz[i]; // skip bad kHz samples if ((sampleCpukHz & ~0xF) != 0) { kHz.sample(sampleCpukHz >> 4); kHz.add(sampleCpukHz >> 4); if (sampleCpukHz == previousCpukHz) { double megacycles = (double) sampleLoadNs * (double) (sampleCpukHz >> 4) * 1e-12; double adjMHz = megacycles / mixPeriodSec; // _not_ wallNs * 1e9 loadMHz.sample(adjMHz); loadMHz.add(adjMHz); } } previousCpukHz = sampleCpukHz; Loading @@ -128,42 +128,42 @@ void FastMixerDumpState::dump(int fd) const } if (n) { dprintf(fd, " Simple moving statistics over last %.1f seconds:\n", wall.n() * mixPeriodSec); wall.getN() * mixPeriodSec); dprintf(fd, " wall clock time in ms per mix cycle:\n" " mean=%.2f min=%.2f max=%.2f stddev=%.2f\n", wall.mean()*1e-6, wall.minimum()*1e-6, wall.maximum()*1e-6, wall.stddev()*1e-6); wall.getMean()*1e-6, wall.getMin()*1e-6, wall.getMax()*1e-6, wall.getStdDev()*1e-6); dprintf(fd, " raw CPU load in us per mix cycle:\n" " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n", loadNs.mean()*1e-3, loadNs.minimum()*1e-3, loadNs.maximum()*1e-3, loadNs.stddev()*1e-3); loadNs.getMean()*1e-3, loadNs.getMin()*1e-3, loadNs.getMax()*1e-3, loadNs.getStdDev()*1e-3); } else { dprintf(fd, " No FastMixer statistics available currently\n"); } #ifdef CPU_FREQUENCY_STATISTICS dprintf(fd, " CPU clock frequency in MHz:\n" " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n", kHz.mean()*1e-3, kHz.minimum()*1e-3, kHz.maximum()*1e-3, kHz.stddev()*1e-3); kHz.getMean()*1e-3, kHz.getMin()*1e-3, kHz.getMax()*1e-3, kHz.getStdDev()*1e-3); dprintf(fd, " adjusted CPU load in MHz (i.e. normalized for CPU clock frequency):\n" " mean=%.1f min=%.1f max=%.1f stddev=%.1f\n", loadMHz.mean(), loadMHz.minimum(), loadMHz.maximum(), loadMHz.stddev()); loadMHz.getMean(), loadMHz.getMin(), loadMHz.getMax(), loadMHz.getStdDev()); #endif if (tail != NULL) { qsort(tail, n, sizeof(uint32_t), compare_uint32_t); // assume same number of tail samples on each side, left and right uint32_t count = n / kTailDenominator; CentralTendencyStatistics left, right; Statistics<double> left, right; for (uint32_t i = 0; i < count; ++i) { left.sample(tail[i]); right.sample(tail[n - (i + 1)]); left.add(tail[i]); right.add(tail[n - (i + 1)]); } dprintf(fd, " Distribution of mix cycle times in ms for the tails " "(> ~3 stddev outliers):\n" " left tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n" " right tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n", left.mean()*1e-6, left.minimum()*1e-6, left.maximum()*1e-6, left.stddev()*1e-6, right.mean()*1e-6, right.minimum()*1e-6, right.maximum()*1e-6, right.stddev()*1e-6); left.getMean()*1e-6, left.getMin()*1e-6, left.getMax()*1e-6, left.getStdDev()*1e-6, right.getMean()*1e-6, right.getMin()*1e-6, right.getMax()*1e-6, right.getStdDev()*1e-6); delete[] tail; } #endif Loading services/audioflinger/Threads.cpp +19 −19 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ #endif #ifdef DEBUG_CPU_USAGE #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #include <cpustats/ThreadCpuUsage.h> #endif Loading Loading @@ -335,9 +335,9 @@ public: #ifdef DEBUG_CPU_USAGE private: ThreadCpuUsage mCpuUsage; // instantaneous thread CPU usage in wall clock ns CentralTendencyStatistics mWcStats; // statistics on thread CPU usage in wall clock ns Statistics<double> mWcStats; // statistics on thread CPU usage in wall clock ns CentralTendencyStatistics mHzStats; // statistics on thread CPU usage in cycles Statistics<double> mHzStats; // statistics on thread CPU usage in cycles int mCpuNum; // thread's current CPU number int mCpukHz; // frequency of thread's current CPU in kHz Loading @@ -363,7 +363,7 @@ void CpuStats::sample(const String8 &title // record sample for wall clock statistics if (valid) { mWcStats.sample(wcNs); mWcStats.add(wcNs); } // get the current CPU number Loading @@ -382,26 +382,26 @@ void CpuStats::sample(const String8 &title // if no change in CPU number or frequency, then record sample for cycle statistics if (valid && mCpukHz > 0) { double cycles = wcNs * cpukHz * 0.000001; mHzStats.sample(cycles); const double cycles = wcNs * cpukHz * 0.000001; mHzStats.add(cycles); } unsigned n = mWcStats.n(); const unsigned n = mWcStats.getN(); // mCpuUsage.elapsed() is expensive, so don't call it every loop if ((n & 127) == 1) { long long elapsed = mCpuUsage.elapsed(); const long long elapsed = mCpuUsage.elapsed(); if (elapsed >= DEBUG_CPU_USAGE * 1000000000LL) { double perLoop = elapsed / (double) n; double perLoop100 = perLoop * 0.01; double perLoop1k = perLoop * 0.001; double mean = mWcStats.mean(); double stddev = mWcStats.stddev(); double minimum = mWcStats.minimum(); double maximum = mWcStats.maximum(); double meanCycles = mHzStats.mean(); double stddevCycles = mHzStats.stddev(); double minCycles = mHzStats.minimum(); double maxCycles = mHzStats.maximum(); const double perLoop = elapsed / (double) n; const double perLoop100 = perLoop * 0.01; const double perLoop1k = perLoop * 0.001; const double mean = mWcStats.getMean(); const double stddev = mWcStats.getStdDev(); const double minimum = mWcStats.getMin(); const double maximum = mWcStats.getMax(); const double meanCycles = mHzStats.getMean(); const double stddevCycles = mHzStats.getStdDev(); const double minCycles = mHzStats.getMin(); const double maxCycles = mHzStats.getMax(); mCpuUsage.resetElapsed(); mWcStats.reset(); mHzStats.reset(); Loading Loading
services/audioflinger/Configuration.h +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ //#define AUDIO_WATCHDOG // uncomment to display CPU load adjusted for CPU frequency #define CPU_FREQUENCY_STATISTICS //define CPU_FREQUENCY_STATISTICS // uncomment to enable fast threads to take performance samples for later statistical analysis #define FAST_THREAD_STATISTICS Loading
services/audioflinger/FastMixer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ #include <utils/Trace.h> #include <system/audio.h> #ifdef FAST_THREAD_STATISTICS #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #ifdef CPU_FREQUENCY_STATISTICS #include <cpustats/ThreadCpuUsage.h> #endif Loading
services/audioflinger/FastMixerDumpState.cpp +20 −20 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ #include "Configuration.h" #ifdef FAST_THREAD_STATISTICS #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #ifdef CPU_FREQUENCY_STATISTICS #include <cpustats/ThreadCpuUsage.h> #endif Loading Loading @@ -92,9 +92,9 @@ void FastMixerDumpState::dump(int fd) const } // statistics for monotonic (wall clock) time, thread raw CPU load in time, CPU clock frequency, // and adjusted CPU load in MHz normalized for CPU clock frequency CentralTendencyStatistics wall, loadNs; Statistics<double> wall, loadNs; #ifdef CPU_FREQUENCY_STATISTICS CentralTendencyStatistics kHz, loadMHz; Statistics<double> kHz, loadMHz; uint32_t previousCpukHz = 0; #endif // Assuming a normal distribution for cycle times, three standard deviations on either side of Loading @@ -109,18 +109,18 @@ void FastMixerDumpState::dump(int fd) const if (tail != NULL) { tail[j] = wallNs; } wall.sample(wallNs); wall.add(wallNs); uint32_t sampleLoadNs = mLoadNs[i]; loadNs.sample(sampleLoadNs); loadNs.add(sampleLoadNs); #ifdef CPU_FREQUENCY_STATISTICS uint32_t sampleCpukHz = mCpukHz[i]; // skip bad kHz samples if ((sampleCpukHz & ~0xF) != 0) { kHz.sample(sampleCpukHz >> 4); kHz.add(sampleCpukHz >> 4); if (sampleCpukHz == previousCpukHz) { double megacycles = (double) sampleLoadNs * (double) (sampleCpukHz >> 4) * 1e-12; double adjMHz = megacycles / mixPeriodSec; // _not_ wallNs * 1e9 loadMHz.sample(adjMHz); loadMHz.add(adjMHz); } } previousCpukHz = sampleCpukHz; Loading @@ -128,42 +128,42 @@ void FastMixerDumpState::dump(int fd) const } if (n) { dprintf(fd, " Simple moving statistics over last %.1f seconds:\n", wall.n() * mixPeriodSec); wall.getN() * mixPeriodSec); dprintf(fd, " wall clock time in ms per mix cycle:\n" " mean=%.2f min=%.2f max=%.2f stddev=%.2f\n", wall.mean()*1e-6, wall.minimum()*1e-6, wall.maximum()*1e-6, wall.stddev()*1e-6); wall.getMean()*1e-6, wall.getMin()*1e-6, wall.getMax()*1e-6, wall.getStdDev()*1e-6); dprintf(fd, " raw CPU load in us per mix cycle:\n" " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n", loadNs.mean()*1e-3, loadNs.minimum()*1e-3, loadNs.maximum()*1e-3, loadNs.stddev()*1e-3); loadNs.getMean()*1e-3, loadNs.getMin()*1e-3, loadNs.getMax()*1e-3, loadNs.getStdDev()*1e-3); } else { dprintf(fd, " No FastMixer statistics available currently\n"); } #ifdef CPU_FREQUENCY_STATISTICS dprintf(fd, " CPU clock frequency in MHz:\n" " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n", kHz.mean()*1e-3, kHz.minimum()*1e-3, kHz.maximum()*1e-3, kHz.stddev()*1e-3); kHz.getMean()*1e-3, kHz.getMin()*1e-3, kHz.getMax()*1e-3, kHz.getStdDev()*1e-3); dprintf(fd, " adjusted CPU load in MHz (i.e. normalized for CPU clock frequency):\n" " mean=%.1f min=%.1f max=%.1f stddev=%.1f\n", loadMHz.mean(), loadMHz.minimum(), loadMHz.maximum(), loadMHz.stddev()); loadMHz.getMean(), loadMHz.getMin(), loadMHz.getMax(), loadMHz.getStdDev()); #endif if (tail != NULL) { qsort(tail, n, sizeof(uint32_t), compare_uint32_t); // assume same number of tail samples on each side, left and right uint32_t count = n / kTailDenominator; CentralTendencyStatistics left, right; Statistics<double> left, right; for (uint32_t i = 0; i < count; ++i) { left.sample(tail[i]); right.sample(tail[n - (i + 1)]); left.add(tail[i]); right.add(tail[n - (i + 1)]); } dprintf(fd, " Distribution of mix cycle times in ms for the tails " "(> ~3 stddev outliers):\n" " left tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n" " right tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n", left.mean()*1e-6, left.minimum()*1e-6, left.maximum()*1e-6, left.stddev()*1e-6, right.mean()*1e-6, right.minimum()*1e-6, right.maximum()*1e-6, right.stddev()*1e-6); left.getMean()*1e-6, left.getMin()*1e-6, left.getMax()*1e-6, left.getStdDev()*1e-6, right.getMean()*1e-6, right.getMin()*1e-6, right.getMax()*1e-6, right.getStdDev()*1e-6); delete[] tail; } #endif Loading
services/audioflinger/Threads.cpp +19 −19 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ #endif #ifdef DEBUG_CPU_USAGE #include <cpustats/CentralTendencyStatistics.h> #include <audio_utils/Statistics.h> #include <cpustats/ThreadCpuUsage.h> #endif Loading Loading @@ -335,9 +335,9 @@ public: #ifdef DEBUG_CPU_USAGE private: ThreadCpuUsage mCpuUsage; // instantaneous thread CPU usage in wall clock ns CentralTendencyStatistics mWcStats; // statistics on thread CPU usage in wall clock ns Statistics<double> mWcStats; // statistics on thread CPU usage in wall clock ns CentralTendencyStatistics mHzStats; // statistics on thread CPU usage in cycles Statistics<double> mHzStats; // statistics on thread CPU usage in cycles int mCpuNum; // thread's current CPU number int mCpukHz; // frequency of thread's current CPU in kHz Loading @@ -363,7 +363,7 @@ void CpuStats::sample(const String8 &title // record sample for wall clock statistics if (valid) { mWcStats.sample(wcNs); mWcStats.add(wcNs); } // get the current CPU number Loading @@ -382,26 +382,26 @@ void CpuStats::sample(const String8 &title // if no change in CPU number or frequency, then record sample for cycle statistics if (valid && mCpukHz > 0) { double cycles = wcNs * cpukHz * 0.000001; mHzStats.sample(cycles); const double cycles = wcNs * cpukHz * 0.000001; mHzStats.add(cycles); } unsigned n = mWcStats.n(); const unsigned n = mWcStats.getN(); // mCpuUsage.elapsed() is expensive, so don't call it every loop if ((n & 127) == 1) { long long elapsed = mCpuUsage.elapsed(); const long long elapsed = mCpuUsage.elapsed(); if (elapsed >= DEBUG_CPU_USAGE * 1000000000LL) { double perLoop = elapsed / (double) n; double perLoop100 = perLoop * 0.01; double perLoop1k = perLoop * 0.001; double mean = mWcStats.mean(); double stddev = mWcStats.stddev(); double minimum = mWcStats.minimum(); double maximum = mWcStats.maximum(); double meanCycles = mHzStats.mean(); double stddevCycles = mHzStats.stddev(); double minCycles = mHzStats.minimum(); double maxCycles = mHzStats.maximum(); const double perLoop = elapsed / (double) n; const double perLoop100 = perLoop * 0.01; const double perLoop1k = perLoop * 0.001; const double mean = mWcStats.getMean(); const double stddev = mWcStats.getStdDev(); const double minimum = mWcStats.getMin(); const double maximum = mWcStats.getMax(); const double meanCycles = mHzStats.getMean(); const double stddevCycles = mHzStats.getStdDev(); const double minCycles = mHzStats.getMin(); const double maxCycles = mHzStats.getMax(); mCpuUsage.resetElapsed(); mWcStats.reset(); mHzStats.reset(); Loading