Merge "AudioPolicyManager: Tally max effects memory usage" into nyc-dev
diff --git a/services/audiopolicy/common/managerdefinitions/include/EffectDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/EffectDescriptor.h
index c9783a1..ab650c0 100644
--- a/services/audiopolicy/common/managerdefinitions/include/EffectDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/EffectDescriptor.h
@@ -55,8 +55,9 @@
 private:
     status_t setEffectEnabled(const sp<EffectDescriptor> &effectDesc, bool enabled);
 
-    uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
-    uint32_t mTotalEffectsMemory;  // current memory used by effects
+    uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects (in MIPS)
+    uint32_t mTotalEffectsMemory;  // current memory used by effects (in KB)
+    uint32_t mTotalEffectsMemoryMaxUsed; // maximum memory used by effects (in KB)
 
     /**
      * Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
diff --git a/services/audiopolicy/common/managerdefinitions/src/EffectDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/EffectDescriptor.cpp
index 33d838d..7b2341e 100644
--- a/services/audiopolicy/common/managerdefinitions/src/EffectDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/EffectDescriptor.cpp
@@ -45,7 +45,8 @@
 
 EffectDescriptorCollection::EffectDescriptorCollection() :
     mTotalEffectsCpuLoad(0),
-    mTotalEffectsMemory(0)
+    mTotalEffectsMemory(0),
+    mTotalEffectsMemoryMaxUsed(0)
 {
 
 }
@@ -62,6 +63,9 @@
         return INVALID_OPERATION;
     }
     mTotalEffectsMemory += desc->memoryUsage;
+    if (mTotalEffectsMemory > mTotalEffectsMemoryMaxUsed) {
+        mTotalEffectsMemoryMaxUsed = mTotalEffectsMemory;
+    }
     ALOGV("registerEffect() effect %s, io %d, strategy %d session %d id %d",
             desc->name, io, strategy, session, id);
     ALOGV("registerEffect() memory %d, total memory %d", desc->memoryUsage, mTotalEffectsMemory);
@@ -175,8 +179,9 @@
     const size_t SIZE = 256;
     char buffer[SIZE];
 
-    snprintf(buffer, SIZE, "\nTotal Effects CPU: %f MIPS, Total Effects memory: %d KB\n",
-             (float)mTotalEffectsCpuLoad/10, mTotalEffectsMemory);
+    snprintf(buffer, SIZE,
+            "\nTotal Effects CPU: %f MIPS, Total Effects memory: %d KB, Max memory used: %d KB\n",
+             (float)mTotalEffectsCpuLoad/10, mTotalEffectsMemory, mTotalEffectsMemoryMaxUsed);
     write(fd, buffer, strlen(buffer));
 
     snprintf(buffer, SIZE, "Registered effects:\n");