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 HighEnergySaving 23 24service traced_probes /system/bin/traced_probes 25 class late_start 26 disabled 27 user nobody 28 # Despite the "log" group below, traced_probes is allowed to read log 29 # only on userdebug/eng via selinux (see traced_probes.te). 30 group nobody readproc log readtracefs 31 task_profiles ProcessCapacityHigh HighEnergySaving 32 # Clean up procfs configuration even if traced_probes crashes 33 # unexpectedly. 34 onrestart exec_background - nobody shell -- /system/bin/traced_probes --cleanup-after-crash 35 file /dev/kmsg w 36 capabilities DAC_READ_SEARCH 37 38on property:persist.device_config.global_settings.sys_traced=1 39 setprop persist.traced.enable 1 40 41on property:persist.device_config.global_settings.sys_traced=0 42 setprop persist.traced.enable 0 43 44on property:debug.atrace.user_initiated=1 45 stop traced_probes 46 47on property:persist.traced.enable=1 && property:debug.atrace.user_initiated="" 48 start traced_probes 49 50on property:persist.traced.enable=1 51 # Trace files need to be: 52 # - Written by either uid:shell or uid:statsd. 53 # - Read by shell and incidentd. 54 mkdir /data/misc/perfetto-traces 0773 root shell 55 56 # Traces in this directory are only accessed by dumpstate (read+unlink) and 57 # by the bug reporting UI (ls+getattr). 58 mkdir /data/misc/perfetto-traces/bugreport 0773 root shell 59 60 # Traces in this directory are only accessed by system server 61 mkdir /data/misc/perfetto-traces/profiling 0777 root shell 62 63 # This directory allows shell to save configs file in a place where the 64 # perfetto cmdline client can read then. /data/local/tmp/ isn't safe because 65 # too many other domains can write into that. See b/170404111. 66 mkdir /data/misc/perfetto-configs 0775 root shell 67 68 start traced 69 start traced_probes 70 71on property:persist.traced.enable=0 72 stop traced 73 stop traced_probes 74 75# Reset the Perfetto guard rail state on boot: 76on post-fs-data 77 rm /data/misc/perfetto-traces/.guardraildata 78 79############################################################################# 80# mm_events - Arms a perfetto trace config that is triggered 81# on memory pressure (kmem_activity trigger) 82############################################################################# 83 84service mm_events /system/bin/mm_events 85 class late_start 86 disabled 87 oneshot 88 user nobody 89 group nobody 90 91on property:persist.mm_events.enabled=true && property:persist.traced.enable=1 92 restart mm_events # Restart to reset backoff interval 93 94on property:persist.mm_events.enabled=false 95 stop mm_events 96 97############################################################################# 98# perfetto_trace_on_boot - Starts a perfetto trace on boot 99############################################################################# 100# 101# There are two separate actions (a trigger action and a start action) to make 102# sure that perfetto_trace_on_boot is started only once on boot (otherwise, 103# whenever persist.debug.perfetto.boottrace=1 is set, perfetto_trace_on_boot 104# would start immediately). 105# 106# persist.debug.perfetto.boottrace=1 can be manually set after boot (to record 107# a trace on the next reboot) and we don't want to immediately start a trace 108# when setting the debug property. So we turn "ro.persistent_properties.ready" 109# into a trigger, and then check whether we should start tracing when the 110# trigger fires. 111on perfetto_maybe_trace_on_boot && property:persist.debug.perfetto.boottrace=1 && property:persist.traced.enable=1 112 setprop persist.debug.perfetto.boottrace "" 113 rm /data/misc/perfetto-traces/boottrace.perfetto-trace 114 # Set by traced after listen()ing on the consumer socket. Without this, 115 # perfetto could try to connect to traced before traced is ready to listen. 116 wait_for_prop sys.trace.traced_started 1 117 start perfetto_trace_on_boot 118 119on property:ro.persistent_properties.ready=true 120 trigger perfetto_maybe_trace_on_boot 121 122service perfetto_trace_on_boot /system/bin/perfetto -c /data/misc/perfetto-configs/boottrace.pbtxt --txt -o /data/misc/perfetto-traces/boottrace.perfetto-trace 123 disabled 124 gentle_kill 125 oneshot 126 user shell 127 group nobody 128 129# This is meant to stop the boot tracing. 130# To use this, add a trigger with mode STOP_TRACING in the configuration used in perfetto_trace_on_boot. 131# Then create a new config which contains `activate_triggers: <trigger name>` where <trigger name> is 132# the name specified in configuration used in perfetto_trace_on_boot. 133on property:sys.boot_completed=1 && property:init.svc.perfetto_trace_on_boot=running 134 exec -- /system/bin/perfetto -c /data/misc/perfetto-configs/stopboottracetrigger.pbtxt --txt 135 136# Forcefully enable select userspace (atrace) tracing categories early into the 137# userspace boot. This is primarily for capturing zygote events without waiting 138# for perfetto daemons or the /data partition. 139on late-init && property:ro.boot.fastboot.boottrace=enabled 140 setprop debug.atrace.tags.enableflags 802922 141 142# disable on boot complete when using textual ftrace tracing without perfetto. 143on property:sys.boot_completed=1 && property:ro.boot.fastboot.boottrace=enabled && property:init.svc.perfetto_trace_on_boot= 144 setprop debug.atrace.tags.enableflags 0 145 write /sys/kernel/debug/tracing/tracing_on 0 146 write /sys/kernel/tracing/tracing_on 0 147 148# These must be set as soon as possible for processes guarded by 149# android.sdk_sysprop_guard to find and cache the memory locations of 150# where these sysprops are stored, particularly SurfaceFlinger which starts 151# very early. 152# TODO(b/281329340): remove this when no longer needed. 153on init 154 setprop debug.perfetto.sdk_sysprop_guard_generation 0 155 setprop debug.hwui.skia_tracing_enabled false 156 setprop debug.hwui.skia_use_perfetto_track_events false 157 setprop debug.renderengine.skia_tracing_enabled false 158 setprop debug.renderengine.skia_use_perfetto_track_events false 159 160############################################################################## 161# perfetto_persistent_sysui_tracing_for_bugreport - Keeps a persistent active 162# tracing session, for debugging purposes 163############################################################################## 164 165on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport=1 && property:persist.traced.enable=1 && property:ro.debuggable=1 166 # Set by traced after listen()ing on the consumer socket. Without this, 167 # perfetto could try to connect to traced before traced is ready to listen. 168 wait_for_prop sys.trace.traced_started 1 169 start perfetto_persistent_sysui_tracing_for_bugreport 170 171# If something disables traced, we don't want init to respawn the service (that will fail) continuously. 172on property:persist.traced.enable=0 173 stop perfetto_persistent_sysui_tracing_for_bugreport 174 175on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport=0 176 setprop persist.debug.perfetto.persistent_sysui_tracing_for_bugreport "" 177 178on property:persist.debug.perfetto.persistent_sysui_tracing_for_bugreport="" 179 stop perfetto_persistent_sysui_tracing_for_bugreport 180 181service perfetto_persistent_sysui_tracing_for_bugreport /system/bin/perfetto -c /system/etc/perfetto/persistent_cfg.pbtxt --txt -o /dev/null 182 disabled 183 timeout_period 86400 184 restart_period 60 185 user nobody 186 group nobody 187