blob: 6b11812bddd82433ba597ce58892cafc500eb492 [file] [log] [blame]
Elliott Hughes9e87f2f2014-09-17 14:59:24 -07001/*
2 * Copyright (C) 2014 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
Elliott Hughes5e62b342018-10-25 11:00:00 -070017#pragma once
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070018
Bowgo Tsaid0ecf0b2020-04-13 13:07:43 +080019#include <cutils/trace.h> // For ATRACE_TAG_BIONIC.
20
Josh Gao4956c372019-12-19 16:35:51 -080021#include "platform/bionic/macros.h"
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070022
Bowgo Tsaid0ecf0b2020-04-13 13:07:43 +080023static constexpr char kTraceTagsProp[] = "debug.atrace.tags.enableflags";
24
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070025// Tracing class for bionic. To begin a trace at a specified point:
26// ScopedTrace("Trace message");
27// The trace will end when the contructor goes out of scope.
28
Dan Albertebb6b4a2014-08-13 11:25:01 -070029class __LIBC_HIDDEN__ ScopedTrace {
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070030 public:
31 explicit ScopedTrace(const char* message);
32 ~ScopedTrace();
33
Dimitry Ivanov2a4a5e72017-03-20 10:54:52 -070034 void End();
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070035 private:
Dimitry Ivanov2a4a5e72017-03-20 10:54:52 -070036 bool called_end_;
Elliott Hughes5e62b342018-10-25 11:00:00 -070037 BIONIC_DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
Elliott Hughes9e87f2f2014-09-17 14:59:24 -070038};
39
Bowgo Tsaid0ecf0b2020-04-13 13:07:43 +080040int get_trace_marker_fd();
41bool should_trace(const uint64_t enable_tags = ATRACE_TAG_BIONIC);
42void output_trace(const char* message, const char event = 'B');
43
Dimitry Ivanov2a4a5e72017-03-20 10:54:52 -070044void bionic_trace_begin(const char* message);
45void bionic_trace_end();