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

Commit 6ec27552 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Pull CPU statistics code out of threadLoop()

This is to prepare for the threadLoop() merge

Change-Id: I118c7d5c6b011b5d5b95ec7d63fb03feb166a9cf
parent be3835c6
Loading
Loading
Loading
Loading
+42 −31
Original line number Diff line number Diff line
@@ -1932,39 +1932,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;
@@ -1972,7 +1956,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,
@@ -1986,6 +1970,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;