@@ -45,20 +45,35 @@ def test_call_script_pytorch_gpu(tmp_path, monkeypatch):
45
45
monkeypatch .setenv ("DD_PROFILING_OUTPUT_PPROF" , filename )
46
46
monkeypatch .setenv ("DD_PROFILING_ENABLED" , "1" )
47
47
monkeypatch .setenv ("DD_PROFILING_PYTORCH_ENABLED" , "1" )
48
+
48
49
stdout , stderr , exitcode , pid = call_program (
49
50
"ddtrace-run" , sys .executable , os .path .join (os .path .dirname (__file__ ), "simple_program_pytorch_gpu.py" )
50
51
)
51
52
52
- output_pprof_filename = filename + "." + str ( pid ) + " .1"
53
+ output_pprof_filename = f" { filename } . { pid } .1"
53
54
print ("filename: " , output_pprof_filename )
54
- with gzip .open (output_pprof_filename , "rb" ) as f :
55
- content = f .read ()
56
- p = pprof .pprof_pb2 .Profile ()
57
- p .ParseFromString (content )
58
- print ("profile contents: " )
59
- print (p )
60
55
61
- assert exitcode == 0
56
+ # Verify the file exists and is not empty
57
+ assert os .path .exists (output_pprof_filename ), f"File { output_pprof_filename } does not exist."
58
+ assert os .path .getsize (output_pprof_filename ) > 0 , "Profiling output file is empty."
59
+
60
+ # Check file header to determine format
61
+ with open (output_pprof_filename , "rb" ) as f :
62
+ header = f .read (2 )
63
+ print (f"File header bytes: { header } " )
64
+ f .seek (0 ) # Reset file pointer
65
+
66
+ if header == b"\x1f \x8b " : # Gzip header
67
+ with gzip .open (output_pprof_filename , "rb" ) as gz :
68
+ content = gz .read ()
69
+ else :
70
+ content = f .read ()
71
+
72
+ p = pprof .pprof_pb2 .Profile ()
73
+ p .ParseFromString (content )
74
+ print ("profile contents: " )
75
+ print (p )
76
+ assert exitcode == 0 , f"Profiler exited with code { exitcode } . Stderr: { stderr } "
62
77
63
78
64
79
def test_call_script_pprof_output (tmp_path , monkeypatch ):
0 commit comments