google / perfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)

Home Page:https://www.perfetto.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot find specified file when initializing TraceProcessor in Python API

joGao01 opened this issue · comments

Hi, I'm trying to use the Python API by passing the trace file to the file_path parameter, as demonstrated in the docs: https://perfetto.dev/docs/analysis/trace-processor#python-api

from perfetto.trace_processor import TraceProcessor
tp = TraceProcessor(file_path='trace.perfetto-trace')

But I get a stack trace error on the second line when initializing the TraceProcessor, saying that the file cannot be found:

Traceback (most recent call last):
  File "C:\Users\joyce\Documents\data\clown.py", line 5, in <module>
    tp = TraceProcessor(file_path='client-trace.perfetto-trace')
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\api.py", line 176, in __init__
    url, self.subprocess = load_shell(
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\shell.py", line 
25, in load_shell
    shell_path = get_loader().get_shell_path(bin_path=bin_path)
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\loader.py", line 64, in get_shell_path
    subprocess.check_output(['chmod', '+x', file.name])
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

I have tried both the absolute and relative path to the file, and verified that the file exists using os.path.exists(). I'm running python version 3.9.1, and the trace file is an output from the Electron function contentTracing.stopRecording(): https://www.electronjs.org/docs/latest/api/content-tracing#contenttracingstoprecordingresultfilepath

The problem appears to be in the chmod of the trace_processor script - obviously chmod doesn't exist on Windows.

We've never really tested the Python API on Windows so not surprising you hit this. Will send a fix.

I'm hoping above CL will fix - please try it out (you'll need to git clone this repo and run setup.py in the python directory) and let us know if it works!

Thanks for the update. I uninstalled the old version of perfetto, cloned this repository, ran python setup.py build and python setup.py install with seemingly no issues, but when I ran my code with the import for TraceProcessor, I get this error:

Traceback (most recent call last):
  File "C:\Users\joyce\Documents\data\clown.py", line 4, in <module>
    from perfetto.trace_processor import TraceProcessor
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\__init__.py", line 16, in <module>
    from perfetto.trace_processor.api import TraceProcessor
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\api.py", line 19, in <module>
    from perfetto.trace_processor.http import TraceProcessorHttp
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\http.py", line 19, in <module>
    from perfetto.trace_processor.protos import ProtoFactory
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\protos.py", line 19, in <module>
    from perfetto.trace_processor.platform import PlatformDelegate
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\platform.py", line 23, in <module>
    from perfetto.trace_uri_resolver.path import PathUriResolver
ModuleNotFoundError: No module named 'perfetto.trace_uri_resolver'

Did I skip a build step? The perfetto package seems to be there.

I missed adding BTP and trace_uri_resolver to the setup.py package - sent https://android-review.googlesource.com/c/platform/external/perfetto/+/1985002 to fix.

@joGao01 the error you were seeing should be fixed with the above - please have another try.

Hi, it seems that the trace uri resolver is still not being found during the build step (this was not present when I ran build and install yesterday):

package init file 'perfetto\trace_uri_resolver\__init__.py' not found (or not a regular file)

which is propogated to the install step:

package init file 'perfetto\trace_uri_resolver\__init__.py' not found (or not a regular file)
package init file 'perfetto\trace_uri_resolver\__init__.py' not found (or not a regular file)

resulting in this error when I try to init TraceProcessor:

Traceback (most recent call last):
  File "C:\Users\joyce\Documents\data\clown.py", line 5, in <module>
    tp = TraceProcessor(file_path='client-trace.perfetto-trace')
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\api.py", line 254, in __init__
    self.http = self._create_tp_http(addr)
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\api.py", line 320, in _create_tp_http
    url, self.subprocess = load_shell(self.config.bin_path,
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\site-packages\perfetto\trace_processor\shell.py", line 39, in load_shell
    p = subprocess.Popen(
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\joyce\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

OK this was not as simple as I hoped. I will need to get myself a Windows install and dig into this further. Will probably be a bit before I look more.

@joGao01 above CL should fix this (tested this myself). Will do a pip release at some point soon (maybe with our next month's release).