diff options
author | Andy Hung <hunga@google.com> | 2023-12-27 21:19:04 -0800 |
---|---|---|
committer | Andy Hung <hunga@google.com> | 2024-03-07 20:43:19 -0800 |
commit | 342901abcad3cb473ab381ce270ef4cc7f40bf78 (patch) | |
tree | 62cab39948af4738c86bcb533ea13f3c58a5754d | |
parent | 70b3bee847b186f563a3a612aa19571e1034c7e3 (diff) | |
download | media-342901abcad3cb473ab381ce270ef4cc7f40bf78.tar.gz |
PowerLog: Allow second level multiresolution
And update tests.
Test: adb shell dumpsys media.audio_flinger
Test: atest powerlog_tests
Bug: 271143713
Merged-In: I64bdf857a900168f6c865964b200f2b31e4d6a95
Change-Id: I64bdf857a900168f6c865964b200f2b31e4d6a95
-rw-r--r-- | audio_utils/include/audio_utils/PowerLog.h | 2 | ||||
-rw-r--r-- | audio_utils/tests/powerlog_tests.cpp | 88 |
2 files changed, 89 insertions, 1 deletions
diff --git a/audio_utils/include/audio_utils/PowerLog.h b/audio_utils/include/audio_utils/PowerLog.h index 105f3b3d..7ab439bd 100644 --- a/audio_utils/include/audio_utils/PowerLog.h +++ b/audio_utils/include/audio_utils/PowerLog.h @@ -105,7 +105,7 @@ public: audio_format_t format, size_t entries, size_t framesPerEntry, - size_t levels = 1) + size_t levels = 2) : mChannelCount(channelCount) , mFormat(format) , mSampleRate(sampleRate) diff --git a/audio_utils/tests/powerlog_tests.cpp b/audio_utils/tests/powerlog_tests.cpp index 1c43b180..aa00f1e7 100644 --- a/audio_utils/tests/powerlog_tests.cpp +++ b/audio_utils/tests/powerlog_tests.cpp @@ -18,6 +18,8 @@ #define LOG_TAG "audio_utils_powerlog_tests" #include <audio_utils/PowerLog.h> + +#include <audio_utils/clock.h> #include <gtest/gtest.h> #include <iostream> #include <log/log.h> @@ -105,6 +107,92 @@ Signal power history: */ } +TEST(audio_utils_powerlog, basic_level_2) { + const uint32_t kSampleRate = 48000; + auto plog = std::make_unique<PowerLog>( + kSampleRate /* sampleRate */, + 1 /* channelCount */, + AUDIO_FORMAT_PCM_16_BIT, + 100 /* entries */, + 1 /* framesPerEntry */, + 2 /* levels */); + + // header + EXPECT_EQ((size_t)2, countNewLines(plog->dumpToString())); + + const int16_t zero = 0; + const int16_t half = 0x4000; + const std::vector<int16_t> ary(60, 0x1000); + + plog->log(&half, 1 /* frame */, 0 /* nowNs */); + plog->log(&half, 1 /* frame */, 1 * NANOS_PER_SECOND / kSampleRate); + plog->log(&half, 1 /* frame */, 2 * NANOS_PER_SECOND / kSampleRate); + plog->log(ary.data(), ary.size(), 30 * NANOS_PER_SECOND / kSampleRate); + + EXPECT_EQ((size_t)10, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 0 /* limitNs */, false /* logPlot */))); + + // add logplot + EXPECT_EQ((size_t)28, countNewLines(plog->dumpToString())); + + plog->log(&zero, 1 /* frame */, 100 * NANOS_PER_SECOND / kSampleRate); + // zero termination doesn't change this. + EXPECT_EQ((size_t)28, countNewLines(plog->dumpToString())); + + // but adding next line does. + plog->log(&half, 1 /* frame */, 101 * NANOS_PER_SECOND / kSampleRate); + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString())); + + // truncating on lines (this does not include the logplot). + EXPECT_EQ((size_t)22, countNewLines(plog->dumpToString( + "" /* prefix */, 4 /* lines */))); + + // truncating on time as well. + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 2 /* limitNs */))); + // truncating on different time limit. + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 3 /* limitNs */))); + + // truncating on a larger line count (this doesn't include the logplot). + EXPECT_EQ((size_t)21, countNewLines(plog->dumpToString( + "" /* prefix */, 3 /* lines */, 2 /* limitNs */))); + + plog->dump(0 /* fd (stdout) */); + + // The output below depends on the local time zone. + // The indentation below is exact, check alignment. + /* +Signal power history (resolution: 0.4 ms): + 12-31 16:00:00.000: [ -14.3 -18.1 -18.1 -18.1 +Signal power history (resolution: 0.0 ms): + 12-31 16:00:00.000: [ -6.0 -6.0 -6.0 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.000: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.000: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 ] sum(2.3) + 12-31 16:00:00.002: [ -6.0 + + -6.0 -|*** | + -7.0 -| | + -8.0 -| | + -9.0 -| | + -10.0 -| | + -11.0 -| | + -12.0 -| | + -13.0 -| | + -14.0 -| | + -15.0 -| | + -16.0 -| | + -17.0 -| | + -18.0 -| ************************************************************| + -19.0 -| | + |________________________________________________________________ + */ +} + TEST(audio_utils_powerlog, c) { power_log_t *power_log = power_log_create( 48000 /* sample_rate */, |