blob: f5aaea322b8d0a1931e24ad3611764c6bb3204df [file] [log] [blame]
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -08001/*
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
Glenn Kastenec2e1322012-04-05 13:41:56 -070017#define LOG_TAG "Trace"
18
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080019#include <cutils/properties.h>
20#include <utils/Log.h>
21#include <utils/Trace.h>
Dianne Hackbornc1309d72012-05-08 18:54:22 -070022#include <utils/misc.h>
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080023
24namespace android {
25
26volatile int32_t Tracer::sIsReady = 0;
27int Tracer::sTraceFD = -1;
Andy McFadden45ad8f42012-10-29 16:49:44 -070028uint64_t Tracer::sEnabledTags = ATRACE_TAG_NOT_READY;
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080029Mutex Tracer::sMutex;
30
Dianne Hackbornc1309d72012-05-08 18:54:22 -070031void Tracer::changeCallback() {
32 Mutex::Autolock lock(sMutex);
33 if (sIsReady && sTraceFD >= 0) {
34 loadSystemProperty();
35 }
36}
37
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080038void Tracer::init() {
39 Mutex::Autolock lock(sMutex);
40
41 if (!sIsReady) {
Dianne Hackbornc1309d72012-05-08 18:54:22 -070042 add_sysprop_change_callback(changeCallback, 0);
43
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080044 const char* const traceFileName =
45 "/sys/kernel/debug/tracing/trace_marker";
46 sTraceFD = open(traceFileName, O_WRONLY);
47 if (sTraceFD == -1) {
48 ALOGE("error opening trace file: %s (%d)", strerror(errno), errno);
Andy McFadden45ad8f42012-10-29 16:49:44 -070049 sEnabledTags = 0; // no tracing can occur
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080050 } else {
Dianne Hackbornc1309d72012-05-08 18:54:22 -070051 loadSystemProperty();
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080052 }
53
54 android_atomic_release_store(1, &sIsReady);
55 }
56}
57
Dianne Hackbornc1309d72012-05-08 18:54:22 -070058void Tracer::loadSystemProperty() {
59 char value[PROPERTY_VALUE_MAX];
60 property_get("debug.atrace.tags.enableflags", value, "0");
61 sEnabledTags = (strtoll(value, NULL, 0) & ATRACE_TAG_VALID_MASK)
62 | ATRACE_TAG_ALWAYS;
63}
64
Jamie Gennis2ccfe1a2012-02-23 11:28:28 -080065} // namespace andoid