blob: 58f03f78b176285b75ba42cea16c6da1f012a224 [file] [log] [blame]
Primiano Tucci5a304532018-01-09 14:15:43 +00001# 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
Suren Baghdasaryana08f53b2021-06-17 18:48:43 -070022 task_profiles ServiceCapacityLow
Primiano Tucci5a304532018-01-09 14:15:43 +000023
24service traced_probes /system/bin/traced_probes
25 class late_start
26 disabled
27 user nobody
Primiano Tuccia3645202020-08-03 16:28:18 +020028 # Despite the "log" group below, traced_probes is allowed to read log
29 # only on userdebug/eng via selinux (see traced_probes.te).
Primiano Tucci2cb13ea2022-01-14 20:32:15 +000030 group nobody readproc log readtracefs
Suren Baghdasaryana08f53b2021-06-17 18:48:43 -070031 task_profiles ServiceCapacityLow
Florian Mayer7d1a9a22018-02-14 15:17:58 +000032 # 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 Mayera98c6f52018-02-19 13:56:07 +000035 file /dev/kmsg w
Primiano Tuccid6e84852018-03-29 20:26:57 +000036 capabilities DAC_READ_SEARCH
Primiano Tucci5a304532018-01-09 14:15:43 +000037
Hector Dearmanf1d1cd82019-04-05 16:25:10 +010038on property:persist.device_config.global_settings.sys_traced=1
Hector Dearmane9bdfe52018-03-21 13:24:28 +000039 setprop persist.traced.enable 1
40
Hector Dearmanf1d1cd82019-04-05 16:25:10 +010041on property:persist.device_config.global_settings.sys_traced=0
Hector Dearmane9bdfe52018-03-21 13:24:28 +000042 setprop persist.traced.enable 0
43
Lalit Magantidabc5292018-05-23 19:18:55 +010044on 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
Primiano Tucci71758822018-01-25 12:51:45 +000050on property:persist.traced.enable=1
Primiano Tucci7e2b67a2018-01-16 16:38:49 +000051 # Trace files need to be:
52 # - Written by either uid:shell or uid:statsd.
Primiano Tucci34f7ad32020-10-13 21:43:29 +020053 # - Read by shell and incidentd.
Primiano Tucci7e2b67a2018-01-16 16:38:49 +000054 mkdir /data/misc/perfetto-traces 0773 root shell
55
Primiano Tuccif0706d12021-01-14 15:20:16 +010056 # 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
Primiano Tucci34f7ad32020-10-13 21:43:29 +020060 # This directory allows shell to save configs file in a place where the
61 # perfetto cmdline client can read then. /data/local/tmp/ isn't safe because
62 # too many other domains can write into that. See b/170404111.
63 mkdir /data/misc/perfetto-configs 0775 root shell
64
Primiano Tucci5a304532018-01-09 14:15:43 +000065 start traced
66 start traced_probes
Hector Dearman7549fff2018-02-09 17:25:30 +000067
68on property:persist.traced.enable=0
69 stop traced
70 stop traced_probes
Hector Dearmandedfd762019-11-28 18:13:49 +000071
72# Reset the Perfetto guard rail state on boot:
73on post-fs-data
74 rm /data/misc/perfetto-traces/.guardraildata
Kalesh Singh8c1eb4b2021-03-30 11:59:09 -040075
76#############################################################################
77# mm_events - Arms a perfetto trace config that is triggered
78# on memory pressure (kmem_activity trigger)
79#############################################################################
80
81service mm_events /system/bin/mm_events
82 class late_start
83 disabled
84 oneshot
85 user nobody
86 group nobody
87
88on property:persist.mm_events.enabled=true && property:persist.traced.enable=1
89 restart mm_events # Restart to reset backoff interval
90
91on property:persist.mm_events.enabled=false
92 stop mm_events
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +010093
94#############################################################################
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +010095# perfetto_trace_on_boot - Starts a perfetto trace on boot
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +010096#############################################################################
97#
98# There are two separate actions (a trigger action and a start action) to make
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +010099# sure that perfetto_trace_on_boot is started only once on boot (otherwise,
100# whenever persist.debug.perfetto.boottrace=1 is set, perfetto_trace_on_boot
101# would start immediately).
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +0100102#
103# persist.debug.perfetto.boottrace=1 can be manually set after boot (to record
104# a trace on the next reboot) and we don't want to immediately start a trace
105# when setting the debug property. So we turn "ro.persistent_properties.ready"
106# into a trigger, and then check whether we should start tracing when the
107# trigger fires.
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +0100108on perfetto_maybe_trace_on_boot && property:persist.debug.perfetto.boottrace=1 && property:persist.traced.enable=1
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +0100109 setprop persist.debug.perfetto.boottrace ""
110 rm /data/misc/perfetto-traces/boottrace.perfetto-trace
111 # Set by traced after listen()ing on the consumer socket. Without this,
112 # perfetto could try to connect to traced before traced is ready to listen.
113 wait_for_prop sys.trace.traced_started 1
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +0100114 start perfetto_trace_on_boot
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +0100115
116on property:ro.persistent_properties.ready=true
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +0100117 trigger perfetto_maybe_trace_on_boot
Daniele Di Proiettoe84bb9e2021-09-30 17:39:55 +0100118
Daniele Di Proiettobf487cf2021-10-04 17:17:43 +0100119service 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 Proiettoe84bb9e2021-09-30 17:39:55 +0100120 disabled
121 oneshot
122 user shell
123 group nobody