AudioFlinger: Add thread statistics for process and io timing

Implemented for threads that read/write PCM.

Test: audioflinger dumpsys Play Music, Movies, Video Recording
Bug: 114112762
Change-Id: I866a8b639d18426633088d6a03d9135f4ee09fd3
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 1131b26..4968829 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -512,6 +512,15 @@
                 TimestampVerifier< // For timestamp statistics.
                         int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier;
                 audio_devices_t         mTimestampCorrectedDevices = AUDIO_DEVICE_NONE;
+
+                // ThreadLoop statistics per iteration.
+                int64_t                 mLastIoBeginNs = -1;
+                int64_t                 mLastIoEndNs = -1;
+
+                // This should be read under ThreadBase lock (if not on the threadLoop thread).
+                audio_utils::Statistics<double> mIoJitterMs{0.995 /* alpha */};
+                audio_utils::Statistics<double> mProcessTimeMs{0.995 /* alpha */};
+
                 bool                    mIsMsdDevice = false;
                 // A condition that must be evaluated by the thread loop has changed and
                 // we must not wait for async write callback in the thread loop before evaluating it
@@ -1030,7 +1039,6 @@
     float                           mMasterVolume;
     std::atomic<float>              mMasterBalance{};
     audio_utils::Balance            mBalance;
-    nsecs_t                         mLastWriteTime;
     int                             mNumWrites;
     int                             mNumDelayedWrites;
     bool                            mInWrite;