1# Copyright (C) 2017 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15service traced /system/bin/traced 16 class late_start 17 disabled 18 socket traced_consumer stream 0666 root root 19 socket traced_producer stream 0666 root root 20 user nobody 21 group nobody 22 task_profiles ProcessCapacityHigh 23 24# traced_relay relays its local producer's data to a central traced service 25# running in a different VM or in the host. traced and traced_relay are mutually 26# exclusive, therefore make sure they aren't running at the same time. 27# 28# Note: 29# * The relay socket name is specified by the |traced_relay.relay_port| 30# system property. 31service traced_relay /system/bin/traced_relay 32 class late_start 33 disabled 34 socket traced_producer stream 0666 root root 35 user nobody 36 group nobody 37 task_profiles ProcessCapacityHigh 38 39service traced_probes /system/bin/traced_probes 40 class late_start 41 disabled 42 user nobody 43 # Despite the "log" group below, traced_probes is allowed to read log 44 # only on userdebug/eng via selinux (see traced_probes.te). 45 group nobody readproc log readtracefs 46 task_profiles ProcessCapacityHigh 47 # Clean up procfs configuration even if traced_probes crashes 48 # unexpectedly. 49 onrestart exec_background - nobody shell -- /system/bin/traced_probes --cleanup-after-crash 50 file /dev/kmsg w 51 capabilities DAC_READ_SEARCH 52 shared_kallsyms 53 54on property:persist.device_config.global_settings.sys_traced=1 55 setprop persist.traced.enable 1 56 57on property:persist.device_config.global_settings.sys_traced=0 58 setprop persist.traced.enable 0 59 60on property:debug.atrace.user_initiated=1 61 stop traced_probes 62 63on property:persist.traced.enable=1 && property:debug.atrace.user_initiated="" 64 start traced_probes 65 66# Possible values of persist.traced.enable: 67# - 0=disabled 68# - 1=enabled 69# - 2=relay_mode 70on property:persist.traced.enable=0 71 stop traced 72 stop traced_relay 73 stop traced_probes 74 75on property:persist.traced.enable=1 76 # Trace files need to be: 77 # - Written by either uid:shell or uid:statsd. 78 # - Read by shell and incidentd. 79 mkdir /data/misc/perfetto-traces 0773 root shell 80 81 # Traces in this directory are only accessed by dumpstate (read+unlink) and 82 # by the bug reporting UI (ls+getattr). 83 mkdir /data/misc/perfetto-traces/bugreport 0773 root shell 84 85 # Traces in this directory are only accessed by system server 86 mkdir /data/misc/perfetto-traces/profiling 0777 root shell 87 88 # This directory allows shell to save configs file in a place where the 89 # perfetto cmdline client can read then. /data/local/tmp/ isn't safe because 90 # too many other domains can write into that. See b/170404111. 91 mkdir /data/misc/perfetto-configs 0775 root shell 92 93 stop traced_relay 94 start traced 95 start traced_probes 96 97on property:persist.traced.enable=2 98 stop traced 99 start traced_relay 100 start traced_probes 101 102# Reset the Perfetto guard rail state on boot: 103on post-fs-data 104 rm /data/misc/perfetto-traces/.guardraildata 105 106############################################################################# 107# perfetto_trace_on_boot - Starts a perfetto trace on boot 108############################################################################# 109# 110# There are two separate actions (a trigger action and a start action) to make 111# sure that perfetto_trace_on_boot is started only once on boot (otherwise, 112# whenever persist.debug.perfetto.boottrace=1 is set, perfetto_trace_on_boot 113# would start immediately). 114# 115# persist.debug.perfetto.boottrace=1 can be manually set after boot (to record 116# a trace on the next reboot) and we don't want to immediately start a trace 117# when setting the debug property. So we turn "ro.persistent_properties.ready" 118# into a trigger, and then check whether we should start tracing when the 119# trigger fires. 120on perfetto_maybe_trace_on_boot && property:persist.debug.perfetto.boottrace=1 && property:persist.traced.enable=1 121 setprop persist.debug.perfetto.boottrace "" 122 rm /data/misc/perfetto-traces/boottrace.perfetto-trace 123 # Set by traced after listen()ing on the consumer socket. Without this, 124 # perfetto could try to connect to traced before traced is ready to listen. 125 wait_for_prop sys.trace.traced_started 1 126 start perfetto_trace_on_boot 127 128on property:ro.persistent_properties.ready=true 129 trigger perfetto_maybe_trace_on_boot 130 131service perfetto_trace_on_boot /system/bin/perfetto -c /data/misc/perfetto-configs/boottrace.pbtxt --txt -o /data/misc/perfetto-traces/boottrace.perfetto-trace 132 disabled 133 gentle_kill 134 oneshot 135 user shell 136 group nobody 137 138# This is meant to stop the boot tracing. 139# To use this, add a trigger with mode STOP_TRACING in the configuration used in perfetto_trace_on_boot. 140# Then create a new config which contains `activate_triggers: <trigger name>` where <trigger name> is 141# the name specified in configuration used in perfetto_trace_on_boot. 142on property:sys.boot_completed=1 && property:init.svc.perfetto_trace_on_boot=running 143 exec -- /system/bin/perfetto -c /data/misc/perfetto-configs/stopboottracetrigger.pbtxt --txt 144 145# Forcefully enable select userspace (atrace) tracing categories early into the 146# userspace boot. This is primarily for capturing zygote events without waiting 147# for perfetto daemons or the /data partition. 148on late-init && property:ro.boot.fastboot.boottrace=enabled 149 setprop debug.atrace.tags.enableflags 802922 150 151# disable on boot complete when using textual ftrace tracing without perfetto. 152on property:sys.boot_completed=1 && property:ro.boot.fastboot.boottrace=enabled && property:init.svc.perfetto_trace_on_boot= 153 setprop debug.atrace.tags.enableflags 0 154 write /sys/kernel/debug/tracing/tracing_on 0 155 write /sys/kernel/tracing/tracing_on 0 156 157# These must be set as soon as possible for processes guarded by 158# android.sdk_sysprop_guard to find and cache the memory locations of 159# where these sysprops are stored, particularly SurfaceFlinger which starts 160# very early. 161# TODO(b/281329340): remove this when no longer needed. 162on init 163 setprop debug.perfetto.sdk_sysprop_guard_generation 0 164 setprop debug.hwui.skia_tracing_enabled false 165 setprop debug.hwui.skia_use_perfetto_track_events false 166 setprop debug.renderengine.skia_tracing_enabled false 167 setprop debug.renderengine.skia_use_perfetto_track_events false 168 169############################################################################## 170# perfetto_persistent_sysui_tracing_for_bugreport - Keeps a persistent active 171# tracing session, for debugging purposes 172############################################################################## 173 174on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport=1 && property:persist.traced.enable=1 && property:ro.debuggable=1 175 # Set by traced after listen()ing on the consumer socket. Without this, 176 # perfetto could try to connect to traced before traced is ready to listen. 177 wait_for_prop sys.trace.traced_started 1 178 start perfetto_persistent_sysui_tracing_for_bugreport 179 180# If something disables traced, we don't want init to respawn the service (that will fail) continuously. 181on property:persist.traced.enable=0 182 stop perfetto_persistent_sysui_tracing_for_bugreport 183 184on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport=0 185 setprop persist.debug.perfetto.persistent_sysui_tracing_for_bugreport "" 186 187on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport="" 188 stop perfetto_persistent_sysui_tracing_for_bugreport 189 190service perfetto_persistent_sysui_tracing_for_bugreport /system/bin/perfetto -c /system/etc/perfetto/persistent_cfg.pbtxt --txt -o /dev/null 191 disabled 192 timeout_period 86400 193 restart_period 60 194 user nobody 195 group nobody 196