diff options
Diffstat (limited to 'libs/utils/Trace.cpp')
-rw-r--r-- | libs/utils/Trace.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 | |||
21 | namespace android { | ||
22 | |||
23 | volatile int32_t Tracer::sIsReady = 0; | ||
24 | int Tracer::sTraceFD = -1; | ||
25 | uint64_t Tracer::sEnabledTags = 0; | ||
26 | Mutex Tracer::sMutex; | ||
27 | |||
28 | void 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 | ||