diff options
author | Ruchi Kandoi <kandoiruchi@google.com> | 2017-05-15 18:03:35 -0700 |
---|---|---|
committer | Ruchi Kandoi <kandoiruchi@google.com> | 2017-05-17 13:18:16 -0700 |
commit | b63072e4d029ee7a0038a0d2f053f70c5fe8b33e (patch) | |
tree | 9df0766889a3b277c8ed0d3c03bf65e31c7e8448 /libmetricslogger | |
parent | 67529d29ca047e934ccf4ae94594c9460a400348 (diff) | |
download | core-b63072e4d029ee7a0038a0d2f053f70c5fe8b33e.tar.gz core-b63072e4d029ee7a0038a0d2f053f70c5fe8b33e.tar.bz2 core-b63072e4d029ee7a0038a0d2f053f70c5fe8b33e.zip |
Add the functionality for logging counters.
Also correct clang-format for libmetricslogger
Test: Run libmetriclogger_test
Change-Id: If61f0bdc394a43e249ec4691da70175eeaf4cec6
Diffstat (limited to 'libmetricslogger')
-rw-r--r-- | libmetricslogger/Android.bp | 1 | ||||
-rw-r--r-- | libmetricslogger/include/metricslogger/metrics_logger.h | 15 | ||||
-rw-r--r-- | libmetricslogger/metrics_logger.cpp | 16 | ||||
-rw-r--r-- | libmetricslogger/metrics_logger_test.cpp | 8 |
4 files changed, 27 insertions, 13 deletions
diff --git a/libmetricslogger/Android.bp b/libmetricslogger/Android.bp index da8afe176..26a041abd 100644 --- a/libmetricslogger/Android.bp +++ b/libmetricslogger/Android.bp @@ -23,6 +23,7 @@ cc_defaults { // 524291 corresponds to sysui_histogram, from // frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags "-DHISTOGRAM_LOG_TAG=524292", + "-DCOUNT_LOG_TAG=524290", ], } diff --git a/libmetricslogger/include/metricslogger/metrics_logger.h b/libmetricslogger/include/metricslogger/metrics_logger.h index 26aa18951..36e124d9c 100644 --- a/libmetricslogger/include/metricslogger/metrics_logger.h +++ b/libmetricslogger/include/metricslogger/metrics_logger.h @@ -24,13 +24,18 @@ namespace metricslogger { // buffer. void LogHistogram(const std::string& event, int32_t data); +// Logs a Tron counter metric named |name| containing |val| count to the Tron +// log buffer. +void LogCounter(const std::string& name, int32_t val); + // TODO: replace these with the metric_logger.proto definitions enum { - LOGBUILDER_CATEGORY = 757, - LOGBUILDER_NAME = 799, - LOGBUILDER_BUCKET = 801, - LOGBUILDER_VALUE = 802, - LOGBUILDER_HISTOGRAM = 804, + LOGBUILDER_CATEGORY = 757, + LOGBUILDER_NAME = 799, + LOGBUILDER_BUCKET = 801, + LOGBUILDER_VALUE = 802, + LOGBUILDER_COUNTER = 803, + LOGBUILDER_HISTOGRAM = 804, }; } // namespace metricslogger diff --git a/libmetricslogger/metrics_logger.cpp b/libmetricslogger/metrics_logger.cpp index 0d08f5cde..6f65e10f1 100644 --- a/libmetricslogger/metrics_logger.cpp +++ b/libmetricslogger/metrics_logger.cpp @@ -25,12 +25,16 @@ namespace metricslogger { // Mirror com.android.internal.logging.MetricsLogger#histogram(). void LogHistogram(const std::string& event, int32_t data) { - android_log_event_list log(HISTOGRAM_LOG_TAG); - log << LOGBUILDER_CATEGORY << LOGBUILDER_HISTOGRAM - << LOGBUILDER_NAME << event - << LOGBUILDER_BUCKET << data - << LOGBUILDER_VALUE << 1 - << LOG_ID_EVENTS; + android_log_event_list log(HISTOGRAM_LOG_TAG); + log << LOGBUILDER_CATEGORY << LOGBUILDER_HISTOGRAM << LOGBUILDER_NAME << event + << LOGBUILDER_BUCKET << data << LOGBUILDER_VALUE << 1 << LOG_ID_EVENTS; +} + +// Mirror com.android.internal.logging.MetricsLogger#count(). +void LogCounter(const std::string& name, int32_t val) { + android_log_event_list log(COUNT_LOG_TAG); + log << LOGBUILDER_CATEGORY << LOGBUILDER_COUNTER << LOGBUILDER_NAME << name << LOGBUILDER_VALUE + << val << LOG_ID_EVENTS; } } // namespace metricslogger diff --git a/libmetricslogger/metrics_logger_test.cpp b/libmetricslogger/metrics_logger_test.cpp index 5a30ad702..440645cb8 100644 --- a/libmetricslogger/metrics_logger_test.cpp +++ b/libmetricslogger/metrics_logger_test.cpp @@ -19,6 +19,10 @@ #include <gtest/gtest.h> TEST(MetricsLoggerTest, AddSingleBootEvent) { - android::metricslogger::LogHistogram("test_event", 42); - // TODO(jhawkins): Verify the EventLog is updated. + android::metricslogger::LogHistogram("test_event", 42); + // TODO(jhawkins): Verify the EventLog is updated. +} + +TEST(MetricsLoggerTest, AddCounterVal) { + android::metricslogger::LogCounter("test_count", 10); } |