Jamie Gennis | f64b1ca | 2012-02-23 11:28:28 -0800 | [diff] [blame] | 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 | |
Glenn Kasten | 84ed800 | 2012-04-05 13:41:56 -0700 | [diff] [blame^] | 17 | #define LOG_TAG "Trace" |
| 18 | |
Jamie Gennis | f64b1ca | 2012-02-23 11:28:28 -0800 | [diff] [blame] | 19 | #include <cutils/properties.h> |
| 20 | #include <utils/Log.h> |
| 21 | #include <utils/Trace.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | volatile int32_t Tracer::sIsReady = 0; |
| 26 | int Tracer::sTraceFD = -1; |
| 27 | uint64_t Tracer::sEnabledTags = 0; |
| 28 | Mutex Tracer::sMutex; |
| 29 | |
| 30 | void Tracer::init() { |
| 31 | Mutex::Autolock lock(sMutex); |
| 32 | |
| 33 | if (!sIsReady) { |
| 34 | const char* const traceFileName = |
| 35 | "/sys/kernel/debug/tracing/trace_marker"; |
| 36 | sTraceFD = open(traceFileName, O_WRONLY); |
| 37 | if (sTraceFD == -1) { |
| 38 | ALOGE("error opening trace file: %s (%d)", strerror(errno), errno); |
Jeff Brown | 45b80c6 | 2012-03-09 14:46:01 -0800 | [diff] [blame] | 39 | // sEnabledTags remains zero indicating that no tracing can occur |
Jamie Gennis | f64b1ca | 2012-02-23 11:28:28 -0800 | [diff] [blame] | 40 | } else { |
| 41 | char value[PROPERTY_VALUE_MAX]; |
| 42 | property_get("atrace.tags.enableflags", value, "0"); |
Jeff Brown | 45b80c6 | 2012-03-09 14:46:01 -0800 | [diff] [blame] | 43 | sEnabledTags = (strtoll(value, NULL, 0) & ATRACE_TAG_VALID_MASK) |
| 44 | | ATRACE_TAG_ALWAYS; |
Jamie Gennis | f64b1ca | 2012-02-23 11:28:28 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | android_atomic_release_store(1, &sIsReady); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | } // namespace andoid |