blob: 4468e83f6f866896015d37dc541c44dcf2a17542 [file] [log] [blame]
Alex Ray0a346432012-11-14 17:25: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
Earl Oue4030382016-11-22 17:04:44 +080017#include "trace-dev.inc"
Mark Salyzyn23ed4c22016-09-28 13:33:27 -070018
Earl Oue4030382016-11-22 17:04:44 +080019static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT;
Jamie Gennis774f9292013-02-25 18:15:40 -080020
Jamie Gennisb13ea452013-04-15 18:50:22 -070021// Set whether tracing is enabled in this process. This is used to prevent
22// the Zygote process from tracing.
23void atrace_set_tracing_enabled(bool enabled)
24{
Yabin Cuia8ac32c2015-04-15 14:50:27 -070025 atomic_store_explicit(&atrace_is_enabled, enabled, memory_order_release);
Jamie Gennisb13ea452013-04-15 18:50:22 -070026 atrace_update_tags();
27}
28
Alex Ray0a346432012-11-14 17:25:28 -080029static void atrace_init_once()
30{
Nick Kralevichdee1ef42015-12-16 12:32:26 -080031 atrace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY | O_CLOEXEC);
Alex Ray0a346432012-11-14 17:25:28 -080032 if (atrace_marker_fd == -1) {
33 ALOGE("Error opening trace file: %s (%d)", strerror(errno), errno);
34 atrace_enabled_tags = 0;
35 goto done;
36 }
37
38 atrace_enabled_tags = atrace_get_property();
39
40done:
Yabin Cuia8ac32c2015-04-15 14:50:27 -070041 atomic_store_explicit(&atrace_is_ready, true, memory_order_release);
Alex Ray0a346432012-11-14 17:25:28 -080042}
43
44void atrace_setup()
45{
46 pthread_once(&atrace_once_control, atrace_init_once);
47}
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070048
49void atrace_begin_body(const char* name)
50{
Earl Oue4030382016-11-22 17:04:44 +080051 WRITE_MSG("B|%d|", "%s", name, "");
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070052}
53
Colin Cross9993e792016-09-16 10:12:52 -070054void atrace_end_body()
55{
Earl Oue4030382016-11-22 17:04:44 +080056 WRITE_MSG("E|%d", "%s", "", "");
Christopher Ferris82d84892016-02-23 18:02:20 -080057}
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070058
59void atrace_async_begin_body(const char* name, int32_t cookie)
60{
Earl Oue4030382016-11-22 17:04:44 +080061 WRITE_MSG("S|%d|", "|%" PRId32, name, cookie);
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070062}
63
64void atrace_async_end_body(const char* name, int32_t cookie)
65{
Earl Oue4030382016-11-22 17:04:44 +080066 WRITE_MSG("F|%d|", "|%" PRId32, name, cookie);
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070067}
68
69void atrace_int_body(const char* name, int32_t value)
70{
Earl Oue4030382016-11-22 17:04:44 +080071 WRITE_MSG("C|%d|", "|%" PRId32, name, value);
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070072}
73
74void atrace_int64_body(const char* name, int64_t value)
75{
Earl Oue4030382016-11-22 17:04:44 +080076 WRITE_MSG("C|%d|", "|%" PRId64, name, value);
Chih-Hung Hsieh2d3150e2014-10-13 16:30:24 -070077}