# # Copyright (C) 2024 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import textwrap from validation_error import ValidationError ANDROID_SDK_VERSION_T = 33 def create_ftrace_events_string(predefined_ftrace_events, excluded_ftrace_events, included_ftrace_events): if excluded_ftrace_events is not None: for event in excluded_ftrace_events: if event in predefined_ftrace_events: predefined_ftrace_events.remove(event) else: return None, ValidationError(("Cannot remove ftrace event %s from" " config because it is not one" " of the config's ftrace events." % event), ("Please specify one of the following" " possible ftrace events:\n\t %s" % "\n\t ".join(predefined_ftrace_events))) if included_ftrace_events is not None: for event in included_ftrace_events: if event not in predefined_ftrace_events: predefined_ftrace_events.append(event) else: return None, ValidationError(("Cannot add ftrace event %s to config" " because it is already one of the" " config's ftrace events." % event), ("Please do not specify any of the" " following ftrace events that are" " already included:\n\t %s" % "\n\t ".join(predefined_ftrace_events))) ftrace_events_string = ("ftrace_events: \"%s\"" % ("""\" ftrace_events: \"""".join(predefined_ftrace_events))) return ftrace_events_string, None def build_default_config(command, android_sdk_version): if command.dur_ms is None: # This is always defined because it has a default value that is always # set in torq.py. raise ValueError("Cannot create config because a valid dur_ms was not set.") predefined_ftrace_events = [ "dmabuf_heap/dma_heap_stat", "ftrace/print", "gpu_mem/gpu_mem_total", "ion/ion_stat", "kmem/ion_heap_grow", "kmem/ion_heap_shrink", "kmem/rss_stat", "lowmemorykiller/lowmemory_kill", "mm_event/mm_event_record", "oom/mark_victim", "oom/oom_score_adj_update", "power/cpu_frequency", "power/cpu_idle", "power/gpu_frequency", "power/suspend_resume", "power/wakeup_source_activate", "power/wakeup_source_deactivate", "sched/sched_blocked_reason", "sched/sched_process_exit", "sched/sched_process_free", "sched/sched_switch", "sched/sched_wakeup", "sched/sched_wakeup_new", "sched/sched_waking", "task/task_newtask", "task/task_rename", "vmscan/*", "workqueue/*", ] ftrace_events_string, error = create_ftrace_events_string( predefined_ftrace_events, command.excluded_ftrace_events, command.included_ftrace_events) if error is not None: return None, error cpufreq_period_string = "cpufreq_period_ms: 500" if android_sdk_version < ANDROID_SDK_VERSION_T: cpufreq_period_string = "" config = f'''\ <