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