1 /*
2 * Copyright (C) 2023 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 "trace_enabler.h"
18
19 #include <cutils/properties.h>
20 #include <cutils/trace.h>
21 #include <log/log.h>
22
set_property_or_die(const char * key,const char * value)23 void set_property_or_die(const char* key, const char* value) {
24 LOG_ALWAYS_FATAL_IF(property_set(key, value) < 0, "Failed to set %s", key);
25 }
26
disable_app_atrace()27 void disable_app_atrace() {
28 set_property_or_die("debug.atrace.app_number", "");
29 set_property_or_die("debug.atrace.app_0", "");
30 atrace_update_tags();
31 }
32
enable_atrace_for_single_app(const char * name)33 void enable_atrace_for_single_app(const char* name) {
34 set_property_or_die("debug.atrace.app_number", "1");
35 set_property_or_die("debug.atrace.app_0", name);
36 atrace_update_tags();
37 }
38