Skip to content
Snippets Groups Projects
Commit 7868a0d8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add the functionality for logging counters."

parents 8cfd2971 b63072e4
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ cc_defaults { ...@@ -23,6 +23,7 @@ cc_defaults {
// 524291 corresponds to sysui_histogram, from // 524291 corresponds to sysui_histogram, from
// frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags // frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
"-DHISTOGRAM_LOG_TAG=524292", "-DHISTOGRAM_LOG_TAG=524292",
"-DCOUNT_LOG_TAG=524290",
], ],
} }
......
...@@ -24,12 +24,17 @@ namespace metricslogger { ...@@ -24,12 +24,17 @@ namespace metricslogger {
// buffer. // buffer.
void LogHistogram(const std::string& event, int32_t data); 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 // TODO: replace these with the metric_logger.proto definitions
enum { enum {
LOGBUILDER_CATEGORY = 757, LOGBUILDER_CATEGORY = 757,
LOGBUILDER_NAME = 799, LOGBUILDER_NAME = 799,
LOGBUILDER_BUCKET = 801, LOGBUILDER_BUCKET = 801,
LOGBUILDER_VALUE = 802, LOGBUILDER_VALUE = 802,
LOGBUILDER_COUNTER = 803,
LOGBUILDER_HISTOGRAM = 804, LOGBUILDER_HISTOGRAM = 804,
}; };
......
...@@ -26,11 +26,15 @@ namespace metricslogger { ...@@ -26,11 +26,15 @@ namespace metricslogger {
// Mirror com.android.internal.logging.MetricsLogger#histogram(). // Mirror com.android.internal.logging.MetricsLogger#histogram().
void LogHistogram(const std::string& event, int32_t data) { void LogHistogram(const std::string& event, int32_t data) {
android_log_event_list log(HISTOGRAM_LOG_TAG); android_log_event_list log(HISTOGRAM_LOG_TAG);
log << LOGBUILDER_CATEGORY << LOGBUILDER_HISTOGRAM log << LOGBUILDER_CATEGORY << LOGBUILDER_HISTOGRAM << LOGBUILDER_NAME << event
<< LOGBUILDER_NAME << event << LOGBUILDER_BUCKET << data << LOGBUILDER_VALUE << 1 << LOG_ID_EVENTS;
<< 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 } // namespace metricslogger
......
...@@ -22,3 +22,7 @@ TEST(MetricsLoggerTest, AddSingleBootEvent) { ...@@ -22,3 +22,7 @@ TEST(MetricsLoggerTest, AddSingleBootEvent) {
android::metricslogger::LogHistogram("test_event", 42); android::metricslogger::LogHistogram("test_event", 42);
// TODO(jhawkins): Verify the EventLog is updated. // TODO(jhawkins): Verify the EventLog is updated.
} }
TEST(MetricsLoggerTest, AddCounterVal) {
android::metricslogger::LogCounter("test_count", 10);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment