summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Hawkins2017-01-31 13:42:24 -0600
committerJames Hawkins2017-01-31 13:42:24 -0600
commit9aec926f866f54a311bd898b5f51188f9890a357 (patch)
tree08b5f51a1f60e3e3df41c27d49e240867e537864 /libmetricslogger
parent7dde4fa4e2a4949c7d7e6a8376b5c9bda26e38f8 (diff)
downloadplatform-system-core-9aec926f866f54a311bd898b5f51188f9890a357.tar.gz
platform-system-core-9aec926f866f54a311bd898b5f51188f9890a357.tar.xz
platform-system-core-9aec926f866f54a311bd898b5f51188f9890a357.zip
libmetricslogger: Refactor Tron metrics histogram logging out of
bootstat. To be shared with other native components that want to log histograms. Bug: 34456830 Test: libmetricslogger_test Change-Id: I94a1a91c6d33e443d66bc480158dc2470d6c9031
Diffstat (limited to 'libmetricslogger')
-rw-r--r--libmetricslogger/Android.bp64
-rw-r--r--libmetricslogger/include/metricslogger/metrics_logger.h28
-rw-r--r--libmetricslogger/metrics_logger.cpp32
-rw-r--r--libmetricslogger/metrics_logger_test.cpp31
-rw-r--r--libmetricslogger/testrunner.cpp24
5 files changed, 179 insertions, 0 deletions
diff --git a/libmetricslogger/Android.bp b/libmetricslogger/Android.bp
new file mode 100644
index 000000000..ca8af574a
--- /dev/null
+++ b/libmetricslogger/Android.bp
@@ -0,0 +1,64 @@
1// Copyright 2017 The Android Open Source Project
2
3metricslogger_lib_src_files = [
4 "metrics_logger.cpp",
5]
6
7cc_defaults {
8 name: "metricslogger_defaults",
9
10 clang: true,
11 host_supported: true,
12
13 export_include_dirs: ["include"],
14 local_include_dirs: ["include"],
15 shared_libs: ["liblog"],
16 whole_static_libs: ["libgtest_prod"],
17
18 cflags: [
19 "-Wall",
20 "-Wextra",
21 "-Werror",
22
23 // 524291 corresponds to sysui_histogram, from
24 // frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
25 "-DHISTOGRAM_LOG_TAG=524291",
26 ],
27}
28
29// metricslogger shared library
30// -----------------------------------------------------------------------------
31cc_library_shared {
32 name: "libmetricslogger",
33 srcs: metricslogger_lib_src_files,
34 defaults: ["metricslogger_defaults"],
35}
36
37// metricslogger shared library, debug
38// -----------------------------------------------------------------------------
39cc_library_shared {
40 name: "libmetricslogger_debug",
41 srcs: metricslogger_lib_src_files,
42 defaults: ["metricslogger_defaults"],
43
44 target: {
45 host: {
46 cflags: ["-UNDEBUG"],
47 },
48 },
49}
50
51// Native tests
52// -----------------------------------------------------------------------------
53cc_test {
54 name: "metricslogger_tests",
55 defaults: ["metricslogger_defaults"],
56 shared_libs: [
57 "libbase",
58 "libmetricslogger_debug",
59 ],
60 srcs: [
61 "metrics_logger_test.cpp",
62 "testrunner.cpp",
63 ],
64}
diff --git a/libmetricslogger/include/metricslogger/metrics_logger.h b/libmetricslogger/include/metricslogger/metrics_logger.h
new file mode 100644
index 000000000..d30e56c4c
--- /dev/null
+++ b/libmetricslogger/include/metricslogger/metrics_logger.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <cstdint>
18#include <string>
19
20namespace android {
21namespace metricslogger {
22
23// Logs a Tron histogram metric named |event| containing |data| to the Tron log
24// buffer.
25void LogHistogram(const std::string& event, int32_t data);
26
27} // namespace metricslogger
28} // namespace android
diff --git a/libmetricslogger/metrics_logger.cpp b/libmetricslogger/metrics_logger.cpp
new file mode 100644
index 000000000..f8e01745c
--- /dev/null
+++ b/libmetricslogger/metrics_logger.cpp
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "metricslogger/metrics_logger.h"
18
19#include <cstdlib>
20
21#include <log/log_event_list.h>
22
23namespace android {
24namespace metricslogger {
25
26void LogHistogram(const std::string& event, int32_t data) {
27 android_log_event_list log(HISTOGRAM_LOG_TAG);
28 log << event << data << LOG_ID_EVENTS;
29}
30
31} // namespace metricslogger
32} // namespace android
diff --git a/libmetricslogger/metrics_logger_test.cpp b/libmetricslogger/metrics_logger_test.cpp
new file mode 100644
index 000000000..d77199c35
--- /dev/null
+++ b/libmetricslogger/metrics_logger_test.cpp
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "metricslogger/metrics_logger.h"
18
19#include <gtest/gtest.h>
20
21TEST(MetricsLoggerTest, AddSingleBootEvent) {
22 android::metricslogger::LogHistogram("test_event", 42);
23 /*pid_t pid = getpid();
24 struct logger_list *logger_list = android_logger_list_open(
25 LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, pid);
26
27 logger_list = NULL;
28 log_msg log_msg;
29 android_logger_list_read(logger_list, &log_msg);
30 std::cout << log_msg.len() << std::endl;*/
31}
diff --git a/libmetricslogger/testrunner.cpp b/libmetricslogger/testrunner.cpp
new file mode 100644
index 000000000..edbf4d503
--- /dev/null
+++ b/libmetricslogger/testrunner.cpp
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android-base/logging.h>
18#include <gtest/gtest.h>
19
20int main(int argc, char** argv) {
21 ::testing::InitGoogleTest(&argc, argv);
22 android::base::InitLogging(argv, android::base::StderrLogger);
23 return RUN_ALL_TESTS();
24}