## Permissions to allow system-wide tracing to the kernel trace buffer.
##
on late-init

# Allow writing to the kernel trace log.
    chmod 0222 /sys/kernel/debug/tracing/trace_marker
    chmod 0222 /sys/kernel/tracing/trace_marker

# Scheduler tracepoints require schedstats=enable
    write /proc/sys/kernel/sched_schedstats 1

# Grant unix world read/write permissions to kernel tracepoints.
# Access control to these files is now entirely in selinux policy.
    chmod 0666 /sys/kernel/debug/tracing/trace_clock
    chmod 0666 /sys/kernel/tracing/trace_clock
    chmod 0666 /sys/kernel/debug/tracing/buffer_size_kb
    chmod 0666 /sys/kernel/tracing/buffer_size_kb
    chmod 0666 /sys/kernel/debug/tracing/options/overwrite
    chmod 0666 /sys/kernel/tracing/options/overwrite
    chmod 0666 /sys/kernel/debug/tracing/options/print-tgid
    chmod 0666 /sys/kernel/tracing/options/print-tgid
    chmod 0666 /sys/kernel/debug/tracing/options/record-tgid
    chmod 0666 /sys/kernel/tracing/options/record-tgid
    chmod 0666 /sys/kernel/debug/tracing/saved_cmdlines_size
    chmod 0666 /sys/kernel/tracing/saved_cmdlines_size
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_switch/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_wakeup/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_blocked_reason/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_cpu_hotplug/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_cpu_hotplug/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_pi_setprio/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_pi_setprio/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_process_exit/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_process_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_process_free/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_process_free/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_waking/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_waking/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/enable
    chmod 0666 /sys/kernel/tracing/events/sched/sched_wakeup_new/enable
    chmod 0666 /sys/kernel/debug/tracing/events/cgroup/enable
    chmod 0666 /sys/kernel/tracing/events/cgroup/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
    chmod 0666 /sys/kernel/tracing/events/power/cpu_frequency/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_idle/enable
    chmod 0666 /sys/kernel/tracing/events/power/cpu_idle/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/clock_enable/enable
    chmod 0666 /sys/kernel/tracing/events/power/clock_enable/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/clock_disable/enable
    chmod 0666 /sys/kernel/tracing/events/power/clock_disable/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
    chmod 0666 /sys/kernel/tracing/events/power/clock_set_rate/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency_limits/enable
    chmod 0666 /sys/kernel/tracing/events/power/cpu_frequency_limits/enable
    chmod 0666 /sys/kernel/debug/tracing/events/cpuhp/cpuhp_enter/enable
    chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_enter/enable
    chmod 0666 /sys/kernel/debug/tracing/events/cpuhp/cpuhp_exit/enable
    chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/cpuhp/cpuhp_pause/enable
    chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_pause/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_frequency/enable
    chmod 0666 /sys/kernel/tracing/events/power/gpu_frequency/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_work_period/enable
    chmod 0666 /sys/kernel/tracing/events/power/gpu_work_period/enable
    chmod 0666 /sys/kernel/debug/tracing/events/power/suspend_resume/enable
    chmod 0666 /sys/kernel/tracing/events/power/suspend_resume/enable
    chmod 0666 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
    chmod 0666 /sys/kernel/tracing/events/cpufreq_interactive/enable
    chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
    chmod 0666 /sys/kernel/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
    chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_end/enable
    chmod 0666 /sys/kernel/tracing/events/vmscan/mm_vmscan_direct_reclaim_end/enable
    chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_wake/enable
    chmod 0666 /sys/kernel/tracing/events/vmscan/mm_vmscan_kswapd_wake/enable
    chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_sleep/enable
    chmod 0666 /sys/kernel/tracing/events/vmscan/mm_vmscan_kswapd_sleep/enable
    chmod 0666 /sys/kernel/debug/tracing/tracing_on
    chmod 0666 /sys/kernel/tracing/tracing_on
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_transaction/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_received/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_transaction_received/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_alloc_buf/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_transaction_alloc_buf/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_lock/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_lock/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_locked/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_locked/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_unlock/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_unlock/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_set_priority/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_set_priority/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_command/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_command/enable
    chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_return/enable
    chmod 0666 /sys/kernel/tracing/events/binder/binder_return/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_read/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/i2c_read/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_write/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/i2c_write/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_result/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/i2c_result/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_reply/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/i2c_reply/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_read/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/smbus_read/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_write/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/smbus_write/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_result/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/smbus_result/enable
    chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_reply/enable
    chmod 0666 /sys/kernel/tracing/events/i2c/smbus_reply/enable
    chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/enable
    chmod 0666 /sys/kernel/tracing/events/lowmemorykiller/enable
    chmod 0666 /sys/kernel/debug/tracing/events/sync/enable
    chmod 0666 /sys/kernel/tracing/events/sync/enable
    chmod 0666 /sys/kernel/debug/tracing/events/fence/enable
    chmod 0666 /sys/kernel/tracing/events/fence/enable
    chmod 0666 /sys/kernel/debug/tracing/events/dma_fence/enable
    chmod 0666 /sys/kernel/tracing/events/dma_fence/enable
    chmod 0666 /sys/kernel/debug/tracing/events/kmem/rss_stat/enable
    chmod 0666 /sys/kernel/tracing/events/kmem/rss_stat/enable
    chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_grow/enable
    chmod 0666 /sys/kernel/tracing/events/kmem/ion_heap_grow/enable
    chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_shrink/enable
    chmod 0666 /sys/kernel/tracing/events/kmem/ion_heap_shrink/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ion/ion_stat/enable
    chmod 0666 /sys/kernel/tracing/events/ion/ion_stat/enable
    chmod 0666 /sys/kernel/debug/tracing/events/mm_event/mm_event_record/enable
    chmod 0666 /sys/kernel/tracing/events/mm_event/mm_event_record/enable
    chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_generate/enable
    chmod 0666 /sys/kernel/tracing/events/signal/signal_generate/enable
    chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_deliver/enable
    chmod 0666 /sys/kernel/tracing/events/signal/signal_deliver/enable
    chmod 0666 /sys/kernel/debug/tracing/events/mm_event/mm_event_record/enable
    chmod 0666 /sys/kernel/tracing/events/mm_event/mm_event_record/enable
    chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/lowmemory_kill/enable
    chmod 0666 /sys/kernel/tracing/events/lowmemorykiller/lowmemory_kill/enable
    chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable
    chmod 0666 /sys/kernel/tracing/events/oom/oom_score_adj_update/enable
    chmod 0666 /sys/kernel/debug/tracing/events/oom/mark_victim/enable
    chmod 0666 /sys/kernel/tracing/events/oom/mark_victim/enable
    chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable
    chmod 0666 /sys/kernel/tracing/events/task/task_rename/enable
    chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable
    chmod 0666 /sys/kernel/tracing/events/task/task_newtask/enable
    chmod 0666 /sys/kernel/debug/tracing/events/gpu_mem/gpu_mem_total/enable
    chmod 0666 /sys/kernel/tracing/events/gpu_mem/gpu_mem_total/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/enable
    chmod 0666 /sys/kernel/tracing/events/irq/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/irq_handler_entry/enable
    chmod 0666 /sys/kernel/tracing/events/irq/irq_handler_entry/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/irq_handler_exit/enable
    chmod 0666 /sys/kernel/tracing/events/irq/irq_handler_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_entry/enable
    chmod 0666 /sys/kernel/tracing/events/irq/softirq_entry/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_exit/enable
    chmod 0666 /sys/kernel/tracing/events/irq/softirq_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_raise/enable
    chmod 0666 /sys/kernel/tracing/events/irq/softirq_raise/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_entry/enable
    chmod 0666 /sys/kernel/tracing/events/irq/tasklet_entry/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_exit/enable
    chmod 0666 /sys/kernel/tracing/events/irq/tasklet_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_hi_entry/enable
    chmod 0666 /sys/kernel/tracing/events/irq/tasklet_hi_entry/enable
    chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_hi_exit/enable
    chmod 0666 /sys/kernel/tracing/events/irq/tasklet_hi_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ipi/enable
    chmod 0666 /sys/kernel/tracing/events/ipi/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_entry/enable
    chmod 0666 /sys/kernel/tracing/events/ipi/ipi_entry/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_exit/enable
    chmod 0666 /sys/kernel/tracing/events/ipi/ipi_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_raise/enable
    chmod 0666 /sys/kernel/tracing/events/ipi/ipi_raise/enable
    chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_enable/enable
    chmod 0666 /sys/kernel/tracing/events/clk/clk_disable/enable
    chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_disable/enable
    chmod 0666 /sys/kernel/tracing/events/clk/clk_enable/enable
    chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_set_rate/enable
    chmod 0666 /sys/kernel/tracing/events/clk/clk_set_rate/enable
    chmod 0666 /sys/kernel/debug/tracing/events/printk/console/enable
    chmod 0666 /sys/kernel/tracing/events/printk/console/enable

    # disk
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_get_data_block/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_get_data_block/enable
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_iget/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_iget/enable
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_sync_file_enter/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_enter/enable
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_sync_file_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_exit/enable
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_write_begin/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_begin/enable
    chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_write_end/enable
    chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_end/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_da_write_begin/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_begin/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_da_write_end/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_end/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_es_lookup_extent_enter/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_enter/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_es_lookup_extent_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_exit/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_load_inode/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_load_inode/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_sync_file_enter/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
    chmod 0666 /sys/kernel/tracing/events/ext4/ext4_sync_file_exit/enable
    chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
    chmod 0666 /sys/kernel/tracing/events/block/block_rq_issue/enable
    chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
    chmod 0666 /sys/kernel/tracing/events/block/block_rq_complete/enable
    chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable

    # filemap events for iorapd
    chmod 0666 /sys/kernel/tracing/events/filemap/mm_filemap_add_to_page_cache/enable
    chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_add_to_page_cache/enable
    chmod 0666 /sys/kernel/tracing/events/filemap/mm_filemap_delete_from_page_cache/enable
    chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_delete_from_page_cache/enable

    # thermal
    chmod 0666 /sys/kernel/debug/tracing/events/thermal/thermal_temperature/enable
    chmod 0666 /sys/kernel/tracing/events/thermal/thermal_temperature/enable
    chmod 0666 /sys/kernel/debug/tracing/events/thermal/cdev_update/enable
    chmod 0666 /sys/kernel/tracing/events/thermal/cdev_update/enable

# Read and truncate the kernel trace.
    chmod 0666 /sys/kernel/debug/tracing/trace
    chmod 0666 /sys/kernel/tracing/trace

# Read and truncate the per-CPU kernel trace.
# Cannot use wildcards in .rc files. Update this if there is a phone with
# more CPUs.
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu0/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu0/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu1/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu1/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu2/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu2/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu3/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu3/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu4/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu4/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu5/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu5/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu6/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu6/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu7/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu7/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu8/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu8/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu9/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu9/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu10/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu10/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu11/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu11/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu12/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu12/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu13/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu13/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu14/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu14/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu15/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu15/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu16/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu16/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu17/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu17/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu18/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu18/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu19/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu19/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu20/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu20/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu21/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu21/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu22/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu22/trace
    chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu23/trace
    chmod 0666 /sys/kernel/tracing/per_cpu/cpu23/trace

# Setup synthetic events
    chmod 0666 /sys/kernel/tracing/synthetic_events
    chmod 0666 /sys/kernel/debug/tracing/synthetic_events
    copy /system/etc/ftrace_synthetic_events.conf /sys/kernel/tracing/synthetic_events
    copy /system/etc/ftrace_synthetic_events.conf /sys/kernel/debug/tracing/synthetic_events

    # allow creating rss_stat event triggers
    chmod 0666 /sys/kernel/tracing/events/kmem/rss_stat/trigger
    chmod 0666 /sys/kernel/debug/tracing/events/kmem/rss_stat/trigger

    # allow enabling rss_stat_throttled
    chmod 0666 /sys/kernel/tracing/events/synthetic/rss_stat_throttled/enable
    chmod 0666 /sys/kernel/debug/tracing/events/synthetic/rss_stat_throttled/enable

    # allow creating suspend_resume triggers
    chmod 0666 /sys/kernel/tracing/events/power/suspend_resume/trigger
    chmod 0666 /sys/kernel/debug/tracing/events/power/suspend_resume/trigger

    # allow enabling suspend_resume_minimal
    chmod 0666 /sys/kernel/tracing/events/synthetic/suspend_resume_minimal/enable
    chmod 0666 /sys/kernel/debug/tracing/events/synthetic/suspend_resume_minimal/enable

on late-init && property:ro.boot.fastboot.boottrace=
    write /sys/kernel/debug/tracing/tracing_on 0
    write /sys/kernel/tracing/tracing_on 0

# Only create the tracing instance if persist.mm_events.enabled
# Attempting to remove the tracing instance after it has been created
# will likely fail with EBUSY as it would be in use by traced_probes.
on post-fs-data && property:persist.mm_events.enabled=true
# Create MM Events Tracing Instance for Kmem Activity Trigger
    mkdir /sys/kernel/debug/tracing/instances/mm_events 0755 system system
    mkdir /sys/kernel/tracing/instances/mm_events 0755 system system

# Read and set per CPU buffer size
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/buffer_size_kb
    chmod 0666 /sys/kernel/tracing/instances/mm_events/buffer_size_kb

# Set the default buffer size to the minimum
    write /sys/kernel/debug/tracing/instances/mm_events/buffer_size_kb 1
    write /sys/kernel/tracing/instances/mm_events/buffer_size_kb 1

# Read and enable tracing
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/tracing_on
    chmod 0666 /sys/kernel/tracing/instances/mm_events/tracing_on

# Tracing disabled by default
    write /sys/kernel/debug/tracing/instances/mm_events/tracing_on 0
    write /sys/kernel/tracing/instances/mm_events/tracing_on 0

# Read and truncate kernel trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/trace

# Enable trace events
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
    chmod 0666 /sys/kernel/tracing/instances/mm_events/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/events/vmscan/mm_vmscan_kswapd_wake/enable
    chmod 0666 /sys/kernel/tracing/instances/mm_events/events/vmscan/mm_vmscan_kswapd_wake/enable
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/events/compaction/mm_compaction_begin/enable
    chmod 0666 /sys/kernel/tracing/instances/mm_events/events/compaction/mm_compaction_begin/enable

# Read and clear per-CPU raw kernel trace
# Cannot use wildcards in .rc files. Update this if there is a phone with
# more CPUs.
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu0/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu0/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu1/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu1/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu2/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu2/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu3/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu3/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu4/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu4/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu5/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu5/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu6/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu6/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu7/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu7/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu8/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu8/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu9/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu9/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu10/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu10/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu11/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu11/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu12/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu12/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu13/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu13/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu14/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu14/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu15/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu15/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu16/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu16/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu17/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu17/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu18/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu18/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu19/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu19/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu20/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu20/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu21/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu21/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu22/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu22/trace
    chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu23/trace
    chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu23/trace

# Handle hyp tracing instance
on late-init && property:ro.boot.hypervisor.vm.supported=1

# Hypervisor tracing instance doesn't support changing trace_clock
    chmod 0440 /sys/kernel/debug/tracing/hyp/trace_clock
    chmod 0440 /sys/kernel/tracing/hyp/trace_clock

    chmod 0660 /sys/kernel/debug/tracing/hyp/buffer_size_kb
    chmod 0660 /sys/kernel/tracing/hyp/buffer_size_kb

    chmod 0660 /sys/kernel/debug/tracing/hyp/tracing_on
    chmod 0660 /sys/kernel/tracing/hyp/tracing_on

# Tracing disabled by default
    write /sys/kernel/debug/tracing/hyp/tracing_on 0
    write /sys/kernel/tracing/hyp/tracing_on 0

# Read and truncate the hyp trace.
    chmod 0660 /sys/kernel/debug/tracing/hyp/trace
    chmod 0660 /sys/kernel/tracing/hyp/trace

# Read and truncate the per-CPU kernel trace.
# Cannot use wildcards in .rc files. Update this if there is a phone with
# TODO(b/249050813, ioffe): introduce per-cpu wildcard
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu0/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu0/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu1/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu1/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu2/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu2/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu3/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu3/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu4/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu4/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu5/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu5/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu6/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu6/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu7/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu7/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu8/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu8/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu9/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu9/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu10/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu10/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu11/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu11/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu12/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu12/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu13/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu13/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu14/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu14/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu15/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu15/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu16/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu16/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu17/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu17/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu18/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu18/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu19/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu19/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu20/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu20/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu21/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu21/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu22/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu22/trace
    chmod 0660 /sys/kernel/debug/tracing/hyp/per_cpu/cpu23/trace
    chmod 0660 /sys/kernel/tracing/hyp/per_cpu/cpu23/trace

    chmod 0440 /sys/kernel/debug/tracing/hyp/events/header_page
    chmod 0440 /sys/kernel/tracing/hyp/events/header_page

# Hyp events start here

# hyp_enter event
    chmod 0660 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_enter/enable
    chmod 0660 /sys/kernel/tracing/hyp/events/hyp/hyp_enter/enable
# TODO(b/249050813): should this be handled in kernel?
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_enter/format
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/hyp_enter/format
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_enter/id
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/hyp_enter/id

# hyp_exit event
    chmod 0660 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_exit/enable
    chmod 0660 /sys/kernel/tracing/hyp/events/hyp/hyp_exit/enable
# TODO(b/249050813): should this be handled in kernel?
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_exit/format
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/hyp_exit/format
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/hyp_exit/id
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/hyp_exit/id

# host_hcall event
    chmod 0660 /sys/kernel/debug/tracing/hyp/events/hyp/host_hcall/enable
    chmod 0660 /sys/kernel/tracing/hyp/events/hyp/host_hcall/enable
# TODO(b/249050813): should this be handled in kernel?
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_hcall/format
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_hcall/format
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_hcall/id
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_hcall/id

# host_smc event
    chmod 0660 /sys/kernel/debug/tracing/hyp/events/hyp/host_smc/enable
    chmod 0660 /sys/kernel/tracing/hyp/events/hyp/host_smc/enable
# TODO(b/249050813): should this be handled in kernel?
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_smc/format
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_smc/format
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_smc/id
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_smc/id

# host_mem_abort event
    chmod 0660 /sys/kernel/debug/tracing/hyp/events/hyp/host_mem_abort/enable
    chmod 0660 /sys/kernel/tracing/hyp/events/hyp/host_mem_abort/enable
# TODO(b/249050813): should this be handled in kernel?
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_mem_abort/format
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_mem_abort/format
    chmod 0440 /sys/kernel/debug/tracing/hyp/events/hyp/host_mem_abort/id
    chmod 0440 /sys/kernel/tracing/hyp/events/hyp/host_mem_abort/id

on property:persist.debug.atrace.boottrace=1
    start boottrace

# Run atrace with the categories written in a file
service boottrace /system/bin/atrace --async_start -f /data/misc/boottrace/categories
    user root
    disabled
    oneshot
