Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ce96d97 authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Pull CPU statistics code out of threadLoop()"

parents 7fb5e883 83efdd0f
Loading
Loading
Loading
Loading
+42 −31
Original line number Diff line number Diff line
@@ -1933,39 +1933,23 @@ AudioFlinger::MixerThread::~MixerThread()
    delete mAudioMixer;
}

bool AudioFlinger::MixerThread::threadLoop()
{
    Vector< sp<Track> > tracksToRemove;
    mixer_state mixerStatus = MIXER_IDLE;
    nsecs_t standbyTime = systemTime();
    size_t mixBufferSize = mFrameCount * mFrameSize;
    // FIXME: Relaxed timing because of a certain device that can't meet latency
    // Should be reduced to 2x after the vendor fixes the driver issue
    // increase threshold again due to low power audio mode. The way this warning threshold is
    // calculated and its usefulness should be reconsidered anyway.
    nsecs_t maxPeriod = seconds(mFrameCount) / mSampleRate * 15;
    nsecs_t lastWarning = 0;
    bool longStandbyExit = false;
    uint32_t activeSleepTime = activeSleepTimeUs();
    uint32_t idleSleepTime = idleSleepTimeUs();
    uint32_t sleepTime = idleSleepTime;
    uint32_t sleepTimeShift = 0;
    Vector< sp<EffectChain> > effectChains;
class CpuStats {
public:
    void sample();
#ifdef DEBUG_CPU_USAGE
    ThreadCpuUsage cpu;
    const CentralTendencyStatistics& stats = cpu.statistics();
private:
    ThreadCpuUsage mCpu;
#endif
};

    acquireWakeLock();

    while (!exitPending())
    {
void CpuStats::sample() {
#ifdef DEBUG_CPU_USAGE
        cpu.sampleAndEnable();
    const CentralTendencyStatistics& stats = mCpu.statistics();
    mCpu.sampleAndEnable();
    unsigned n = stats.n();
        // cpu.elapsed() is expensive, so don't call it every loop
    // mCpu.elapsed() is expensive, so don't call it every loop
    if ((n & 127) == 1) {
            long long elapsed = cpu.elapsed();
        long long elapsed = mCpu.elapsed();
        if (elapsed >= DEBUG_CPU_USAGE * 1000000000LL) {
            double perLoop = elapsed / (double) n;
            double perLoop100 = perLoop * 0.01;
@@ -1973,7 +1957,7 @@ bool AudioFlinger::MixerThread::threadLoop()
            double stddev = stats.stddev();
            double minimum = stats.minimum();
            double maximum = stats.maximum();
                cpu.resetStatistics();
            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,
@@ -1987,6 +1971,33 @@ bool AudioFlinger::MixerThread::threadLoop()
        }
    }
#endif
};

bool AudioFlinger::MixerThread::threadLoop()
{
    Vector< sp<Track> > tracksToRemove;
    mixer_state mixerStatus = MIXER_IDLE;
    nsecs_t standbyTime = systemTime();
    size_t mixBufferSize = mFrameCount * mFrameSize;
    // FIXME: Relaxed timing because of a certain device that can't meet latency
    // Should be reduced to 2x after the vendor fixes the driver issue
    // increase threshold again due to low power audio mode. The way this warning threshold is
    // calculated and its usefulness should be reconsidered anyway.
    nsecs_t maxPeriod = seconds(mFrameCount) / mSampleRate * 15;
    nsecs_t lastWarning = 0;
    bool longStandbyExit = false;
    uint32_t activeSleepTime = activeSleepTimeUs();
    uint32_t idleSleepTime = idleSleepTimeUs();
    uint32_t sleepTime = idleSleepTime;
    uint32_t sleepTimeShift = 0;
    Vector< sp<EffectChain> > effectChains;
    CpuStats cpuStats;

    acquireWakeLock();

    while (!exitPending())
    {
        cpuStats.sample();
        processConfigEvents();

        mixerStatus = MIXER_IDLE;