Add the functionality for logging counters.

Also correct clang-format for libmetricslogger

Test: Run libmetriclogger_test
Change-Id: If61f0bdc394a43e249ec4691da70175eeaf4cec6
This commit is contained in:
Ruchi Kandoi 2017-05-15 18:03:35 -07:00
parent 67529d29ca
commit b63072e4d0
4 changed files with 27 additions and 13 deletions

View File

@ -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",
],
}

View File

@ -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

View File

@ -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

View File

@ -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);
}