blob: d5322967ad711d2c9a096cfeb20361c02fce2b71 [file] [log] [blame]
Jamie Gennisf64b1ca2012-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
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);
Jeff Brown45b80c62012-03-09 14:46:01 -080037 // sEnabledTags remains zero indicating that no tracing can occur
Jamie Gennisf64b1ca2012-02-23 11:28:28 -080038 } else {
39 char value[PROPERTY_VALUE_MAX];
40 property_get("atrace.tags.enableflags", value, "0");
Jeff Brown45b80c62012-03-09 14:46:01 -080041 sEnabledTags = (strtoll(value, NULL, 0) & ATRACE_TAG_VALID_MASK)
42 | ATRACE_TAG_ALWAYS;
Jamie Gennisf64b1ca2012-02-23 11:28:28 -080043 }
44
45 android_atomic_release_store(1, &sIsReady);
46 }
47}
48
49} // namespace andoid