Merge "libmetricslogger: Refactor Tron metrics histogram logging out of bootstat."
This commit is contained in:
commit
64984aaa6e
|
@ -16,7 +16,6 @@
|
|||
|
||||
bootstat_lib_src_files = [
|
||||
"boot_event_record_store.cpp",
|
||||
"histogram_logger.cpp",
|
||||
"uptime_parser.cpp",
|
||||
]
|
||||
|
||||
|
@ -27,15 +26,12 @@ cc_defaults {
|
|||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
|
||||
// 524291 corresponds to sysui_histogram, from
|
||||
// frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
|
||||
"-DHISTOGRAM_LOG_TAG=524291",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"liblog",
|
||||
"libmetricslogger",
|
||||
],
|
||||
whole_static_libs: ["libgtest_prod"],
|
||||
// Clang is required because of C++14
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include "histogram_logger.h"
|
||||
#include "uptime_parser.h"
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -35,9 +35,9 @@
|
|||
#include <android-base/parseint.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <metricslogger/metrics_logger.h>
|
||||
|
||||
#include "boot_event_record_store.h"
|
||||
#include "histogram_logger.h"
|
||||
#include "uptime_parser.h"
|
||||
|
||||
namespace {
|
||||
|
@ -49,7 +49,7 @@ void LogBootEvents() {
|
|||
|
||||
auto events = boot_event_store.GetAllBootEvents();
|
||||
for (auto i = events.cbegin(); i != events.cend(); ++i) {
|
||||
bootstat::LogHistogram(i->first, i->second);
|
||||
android::metricslogger::LogHistogram(i->first, i->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,18 +317,18 @@ void RecordFactoryReset() {
|
|||
|
||||
if (current_time_utc < 0) {
|
||||
// UMA does not display negative values in buckets, so convert to positive.
|
||||
bootstat::LogHistogram(
|
||||
android::metricslogger::LogHistogram(
|
||||
"factory_reset_current_time_failure", std::abs(current_time_utc));
|
||||
|
||||
// Logging via BootEventRecordStore to see if using bootstat::LogHistogram
|
||||
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
|
||||
// is losing records somehow.
|
||||
boot_event_store.AddBootEventWithValue(
|
||||
"factory_reset_current_time_failure", std::abs(current_time_utc));
|
||||
return;
|
||||
} else {
|
||||
bootstat::LogHistogram("factory_reset_current_time", current_time_utc);
|
||||
android::metricslogger::LogHistogram("factory_reset_current_time", current_time_utc);
|
||||
|
||||
// Logging via BootEventRecordStore to see if using bootstat::LogHistogram
|
||||
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
|
||||
// is losing records somehow.
|
||||
boot_event_store.AddBootEventWithValue(
|
||||
"factory_reset_current_time", current_time_utc);
|
||||
|
@ -347,9 +347,9 @@ void RecordFactoryReset() {
|
|||
// Calculate and record the difference in time between now and the
|
||||
// factory_reset time.
|
||||
time_t factory_reset_utc = record.second;
|
||||
bootstat::LogHistogram("factory_reset_record_value", factory_reset_utc);
|
||||
android::metricslogger::LogHistogram("factory_reset_record_value", factory_reset_utc);
|
||||
|
||||
// Logging via BootEventRecordStore to see if using bootstat::LogHistogram
|
||||
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
|
||||
// is losing records somehow.
|
||||
boot_event_store.AddBootEventWithValue(
|
||||
"factory_reset_record_value", factory_reset_utc);
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright 2017 The Android Open Source Project
|
||||
|
||||
metricslogger_lib_src_files = [
|
||||
"metrics_logger.cpp",
|
||||
]
|
||||
|
||||
cc_defaults {
|
||||
name: "metricslogger_defaults",
|
||||
|
||||
clang: true,
|
||||
host_supported: true,
|
||||
|
||||
export_include_dirs: ["include"],
|
||||
local_include_dirs: ["include"],
|
||||
shared_libs: ["liblog"],
|
||||
whole_static_libs: ["libgtest_prod"],
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
|
||||
// 524291 corresponds to sysui_histogram, from
|
||||
// frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
|
||||
"-DHISTOGRAM_LOG_TAG=524291",
|
||||
],
|
||||
}
|
||||
|
||||
// metricslogger shared library
|
||||
// -----------------------------------------------------------------------------
|
||||
cc_library_shared {
|
||||
name: "libmetricslogger",
|
||||
srcs: metricslogger_lib_src_files,
|
||||
defaults: ["metricslogger_defaults"],
|
||||
}
|
||||
|
||||
// metricslogger shared library, debug
|
||||
// -----------------------------------------------------------------------------
|
||||
cc_library_shared {
|
||||
name: "libmetricslogger_debug",
|
||||
srcs: metricslogger_lib_src_files,
|
||||
defaults: ["metricslogger_defaults"],
|
||||
|
||||
target: {
|
||||
host: {
|
||||
cflags: ["-UNDEBUG"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Native tests
|
||||
// -----------------------------------------------------------------------------
|
||||
cc_test {
|
||||
name: "metricslogger_tests",
|
||||
defaults: ["metricslogger_defaults"],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libmetricslogger_debug",
|
||||
],
|
||||
srcs: [
|
||||
"metrics_logger_test.cpp",
|
||||
"testrunner.cpp",
|
||||
],
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,10 +17,12 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace bootstat {
|
||||
namespace android {
|
||||
namespace metricslogger {
|
||||
|
||||
// Builds an EventLog buffer named |event| containing |data| and writes
|
||||
// the log into the Tron histogram logs.
|
||||
// Logs a Tron histogram metric named |event| containing |data| to the Tron log
|
||||
// buffer.
|
||||
void LogHistogram(const std::string& event, int32_t data);
|
||||
|
||||
} // namespace bootstat
|
||||
} // namespace metricslogger
|
||||
} // namespace android
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,19 +14,19 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "histogram_logger.h"
|
||||
#include "metricslogger/metrics_logger.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <log/log_event_list.h>
|
||||
|
||||
namespace bootstat {
|
||||
namespace android {
|
||||
namespace metricslogger {
|
||||
|
||||
void LogHistogram(const std::string& event, int32_t data) {
|
||||
LOG(INFO) << "Logging histogram: " << event << " " << data;
|
||||
android_log_event_list log(HISTOGRAM_LOG_TAG);
|
||||
log << event << data << LOG_ID_EVENTS;
|
||||
}
|
||||
|
||||
} // namespace bootstat
|
||||
} // namespace metricslogger
|
||||
} // namespace android
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metricslogger/metrics_logger.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(MetricsLoggerTest, AddSingleBootEvent) {
|
||||
android::metricslogger::LogHistogram("test_event", 42);
|
||||
/*pid_t pid = getpid();
|
||||
struct logger_list *logger_list = android_logger_list_open(
|
||||
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, pid);
|
||||
|
||||
logger_list = NULL;
|
||||
log_msg log_msg;
|
||||
android_logger_list_read(logger_list, &log_msg);
|
||||
std::cout << log_msg.len() << std::endl;*/
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
android::base::InitLogging(argv, android::base::StderrLogger);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue