Audioflinger dumpsys: Use libjsoncpp for json dump
Test: dumpsys media.audio_flinger --json
Bug: 68148948
Change-Id: Ieebe2c52e3613e48a5ec5cbb2b1f167a32d5a47d
diff --git a/services/audioflinger/FastMixerDumpState.cpp b/services/audioflinger/FastMixerDumpState.cpp
index ffdc117..c67ddad 100644
--- a/services/audioflinger/FastMixerDumpState.cpp
+++ b/services/audioflinger/FastMixerDumpState.cpp
@@ -24,6 +24,7 @@
#include <cpustats/ThreadCpuUsage.h>
#endif
#endif
+#include <json/json.h>
#include <string>
#include <utils/Debug.h>
#include <utils/Log.h>
@@ -205,14 +206,13 @@
}
}
-// TODO get rid of extraneous lines and use better key names.
-// TODO may go back to using a library to do the json formatting.
-std::string FastMixerDumpState::getJsonString() const
+Json::Value FastMixerDumpState::getJsonDump() const
{
+ Json::Value root(Json::objectValue);
if (mCommand == FastMixerState::INITIAL) {
- return " {\n \"status\": \"uninitialized\"\n }";
+ root["status"] = "uninitialized";
+ return root;
}
- std::string jsonStr = " {\n";
#ifdef FAST_THREAD_STATISTICS
// find the interval of valid samples
const uint32_t bounds = mBounds;
@@ -230,31 +230,25 @@
}
// 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
- std::string jsonWallStr = " \"wall_clock_time\":[";
- std::string jsonLoadNsStr = " \"raw_cpu_load\":[";
+ Json::Value jsonWall(Json::arrayValue);
+ Json::Value jsonLoadNs(Json::arrayValue);
// loop over all the samples
for (uint32_t j = 0; j < n; ++j) {
size_t i = oldestClosed++ & (mSamplingN - 1);
uint32_t wallNs = mMonotonicNs[i];
- if (j != 0) {
- jsonWallStr += ',';
- jsonLoadNsStr += ',';
- }
- /* jsonObject["wall"].append(wallNs); */
- jsonWallStr += std::to_string(wallNs);
+ jsonWall.append(wallNs);
uint32_t sampleLoadNs = mLoadNs[i];
- jsonLoadNsStr += std::to_string(sampleLoadNs);
+ jsonLoadNs.append(sampleLoadNs);
}
- jsonWallStr += ']';
- jsonLoadNsStr += ']';
if (n) {
- jsonStr += jsonWallStr + ",\n" + jsonLoadNsStr + "\n";
+ root["wall_clock_time_ns"] = jsonWall;
+ root["raw_cpu_load_ns"] = jsonLoadNs;
+ root["status"] = "ok";
} else {
- //dprintf(fd, " No FastMixer statistics available currently\n");
+ root["status"] = "unavailable";
}
#endif
- jsonStr += " }";
- return jsonStr;
+ return root;
}
} // android