Skip to content

Commit

Permalink
Make xperf output decoding more robust
Browse files Browse the repository at this point in the history
When running IdentifyChromeProcesses.py on a customer trace I hit
decode exceptions due to non-ASCII characters. Setting the encoding to
utf-8 did not resolve them so I also added errors='ignore' because I
want this script to always run to completion and give best-effort
results.

The error messages seen in UIforETW looked like this:

Traceback (most recent call last):
  File "C:\Users\brucedawson\Desktop\etwpackage\bin\IdentifyChromeProcesses.py", line 353, in <module>
    main()
  File "C:\Users\brucedawson\Desktop\etwpackage\bin\IdentifyChromeProcesses.py", line 350, in main
    _IdentifyChromeProcesses(args.trace[0], args.cpuusage, args.tabbed, False)
  File "C:\Users\brucedawson\Desktop\etwpackage\bin\IdentifyChromeProcesses.py", line 130, in _IdentifyChromeProcesses
    line = line.decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 261: ordinal not in range(128)
  • Loading branch information
randomascii committed Jul 28, 2023
1 parent 36785a4 commit 88afed6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/IdentifyChromeProcesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _IdentifyChromeProcesses(tracename, show_cpu_usage, tabbed_output, return_pi

for line in output.splitlines():
# Python 3 needs the line translated from bytes to str.
line = line.decode()
line = line.decode(encoding='utf-8', errors='ignore')
# Split the commandline from the .csv data and then extract the exePath.
# It may or may not be quoted, and may or not have the .exe suffix.
parts = line.split(', ')
Expand Down

0 comments on commit 88afed6

Please sign in to comment.