google / perfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)
https://www.perfetto.dev
Apache License 2.0
2.81k stars 350 forks source link

cpu_profiler.py uses tempfile before closing it on window 10 problems #734

Open dvdface opened 7 months ago

dvdface commented 7 months ago

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) `

primiano commented 7 months ago

Can you please send a patch following https://perfetto.dev/docs/contributing/getting-started ?