Granulate / gprofiler

gProfiler is a system-wide profiler, combining multiple sampling profilers to produce unified visualization of what your CPU is spending time on.
https://profiler.granulate.io
Apache License 2.0
746 stars 54 forks source link

utils: process exceptions: Strict type checks #756

Closed Jongy closed 1 year ago

Jongy commented 1 year ago

I looked at this area because I saw multiple errors like:

[2023-03-28 16:32:39,730] CRITICAL: gprofiler: Running perf failed; consider running gProfiler with '--perf-mode disabled' to avoid using perf
[2023-03-28 16:32:39,731] ERROR: gprofiler: Profiling run failed!
Traceback (most recent call last):
  File "gprofiler/main.py", line 378, in run_continuous
  File "gprofiler/main.py", line 310, in _snapshot
  File "concurrent/futures/_base.py", line 458, in result
  File "concurrent/futures/_base.py", line 403, in __get_result
  File "concurrent/futures/thread.py", line 58, in run
  File "gprofiler/profilers/perf.py", line 483, in snapshot
  File "gprofiler/profilers/perf.py", line 322, in wait_and_script
  File "gprofiler/utils/__init__.py", line 284, in run_process
gprofiler.exceptions.CalledProcessError: <unprintable CalledProcessError object>

These happen because gprofiler.exceptions.CalledProcessError.__str__ raises an exception. I went over the code now and did another pass of validation on the inputs + added runtime asserts to catch such problems earlier.

I assume the problem here was _truncate_stdio adding a string to bytes input. Fixed in this PR.

Jongy commented 1 year ago

I'm satisfied with the tests' coverage, they caught real problems.

Anyway, it should pass now

Jongy commented 1 year ago

I verified that all characters are encoded properly in a way readable in our logs:

In [12]: bytes(bytearray(range(0, 256))).decode("latin-1")                                                                                                                                    
Out[12]: '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0¡¢£¤¥¦§¨©ª«¬\xad®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'