summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamie Gennis2012-02-23 13:28:28 -0600
committerAlex Ray2013-07-30 15:56:59 -0500
commit2ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0b (patch)
tree76d51e305c8b4746dbaaeac20ec045d0d4e2dd84 /libs/utils
parentb11abadc247e5645832793f3ffff98fe9c6f8480 (diff)
downloadplatform-system-core-2ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0b.tar.gz
platform-system-core-2ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0b.tar.xz
platform-system-core-2ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0b.zip
libutils: add a system-wide tracing utility
This change adds some utility functionality for doing userland tracing into the kernel trace log. Change-Id: Id0a8cee9ea515b1d8765afd1cecf472a88b4b9e8
Diffstat (limited to 'libs/utils')
-rw-r--r--libs/utils/Android.mk3
-rw-r--r--libs/utils/Trace.cpp47
2 files changed, 49 insertions, 1 deletions
diff --git a/libs/utils/Android.mk b/libs/utils/Android.mk
index a96c8e604..57c048a3e 100644
--- a/libs/utils/Android.mk
+++ b/libs/utils/Android.mk
@@ -77,7 +77,8 @@ include $(CLEAR_VARS)
77# we have the common sources, plus some device-specific stuff 77# we have the common sources, plus some device-specific stuff
78LOCAL_SRC_FILES:= \ 78LOCAL_SRC_FILES:= \
79 $(commonSources) \ 79 $(commonSources) \
80 Looper.cpp 80 Looper.cpp \
81 Trace.cpp
81 82
82ifeq ($(TARGET_OS),linux) 83ifeq ($(TARGET_OS),linux)
83LOCAL_LDLIBS += -lrt -ldl 84LOCAL_LDLIBS += -lrt -ldl
diff --git a/libs/utils/Trace.cpp b/libs/utils/Trace.cpp
new file mode 100644
index 000000000..c49278ae4
--- /dev/null
+++ b/libs/utils/Trace.cpp
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2012 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 <cutils/properties.h>
18#include <utils/Log.h>
19#include <utils/Trace.h>
20
21namespace android {
22
23volatile int32_t Tracer::sIsReady = 0;
24int Tracer::sTraceFD = -1;
25uint64_t Tracer::sEnabledTags = 0;
26Mutex Tracer::sMutex;
27
28void Tracer::init() {
29 Mutex::Autolock lock(sMutex);
30
31 if (!sIsReady) {
32 const char* const traceFileName =
33 "/sys/kernel/debug/tracing/trace_marker";
34 sTraceFD = open(traceFileName, O_WRONLY);
35 if (sTraceFD == -1) {
36 ALOGE("error opening trace file: %s (%d)", strerror(errno), errno);
37 } else {
38 char value[PROPERTY_VALUE_MAX];
39 property_get("atrace.tags.enableflags", value, "0");
40 sEnabledTags = strtoll(value, NULL, 0) | ATRACE_TAG_ALWAYS;
41 }
42
43 android_atomic_release_store(1, &sIsReady);
44 }
45}
46
47} // namespace andoid