Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)
`
def record_trace(config, profile_target):
"""Runs Perfetto with the provided configuration to record a trace.
Args:
config: The Perfetto config to be used for tracing/profiling.
profile_target: The directory where the recorded trace is output.
"""
NULL = open(os.devnull)
NO_OUT = {
'stdout': NULL,
'stderr': NULL,
}
if not release_or_newer('T'):
sys.exit("This tool requires Android T+ to run.")
`
def record_trace(config, profile_target):
"""Runs Perfetto with the provided configuration to record a trace.
Args:
config: The Perfetto config to be used for tracing/profiling.
profile_target: The directory where the recorded trace is output.
"""
NULL = open(os.devnull)
NO_OUT = {
'stdout': NULL,
'stderr': NULL,
}
if not release_or_newer('T'):
sys.exit("This tool requires Android T+ to run.")
on Window 10, can't push file before close it. it will cause adb push failure https://raw.githubusercontent.com/google/perfetto/main/tools/cpu_profile
` def record_trace(config, profile_target): """Runs Perfetto with the provided configuration to record a trace.
Args: config: The Perfetto config to be used for tracing/profiling. profile_target: The directory where the recorded trace is output. """ NULL = open(os.devnull) NO_OUT = { 'stdout': NULL, 'stderr': NULL, } if not release_or_newer('T'): sys.exit("This tool requires Android T+ to run.")
Push configuration to the device.
tf = tempfile.NamedTemporaryFile() tf.file.write(config.encode('utf-8')) tf.file.flush() profile_config_path = '/data/misc/perfetto-configs/config-' + UUID adb_check_output(['adb', 'push', tf.name, profile_config_path]) tf.close() `
should change to
` def record_trace(config, profile_target): """Runs Perfetto with the provided configuration to record a trace.
Args: config: The Perfetto config to be used for tracing/profiling. profile_target: The directory where the recorded trace is output. """ NULL = open(os.devnull) NO_OUT = { 'stdout': NULL, 'stderr': NULL, } if not release_or_newer('T'): sys.exit("This tool requires Android T+ to run.")
Push configuration to the device.
tf = tempfile.NamedTemporaryFile(delete=False) tf.file.write(config.encode('utf-8')) tf.file.flush() tf.close() profile_config_path = '/data/misc/perfetto-configs/config-' + UUID adb_check_output(['adb', 'push', tf.name, profile_config_path]) os.remove(tf.name) `