-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to properly handle @Profile decorators for CPU time attributi…
…on (#637) * Updates to properly handle @Profile decorators. * Added some additional smoketests * Added more error printing * Corrected checking * Corrected checking * Update doc, remove disabled code. * Fixed smoketest --------- Co-authored-by: Sam Stern <[email protected]>
- Loading branch information
1 parent
101ad2b
commit cadb8f4
Showing
6 changed files
with
166 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
import numpy as np | ||
|
||
#import math | ||
|
||
# from numpy import linalg as LA | ||
|
||
arr = [i for i in range(1,1000)] | ||
|
||
@profile | ||
def doit1(x): | ||
# x = [i*i for i in range(1,1000)][0] | ||
y = 1 | ||
# w, v = LA.eig(np.diag(arr)) # (1, 2, 3, 4, 5, 6, 7, 8, 9, 10))) | ||
x = [i*i for i in range(0,100000)][99999] | ||
y1 = [i*i for i in range(0,200000)][199999] | ||
z1 = [i for i in range(0,300000)][299999] | ||
z = x * y | ||
# z = np.multiply(x, y) | ||
return z | ||
|
||
def doit2(x): | ||
i = 0 | ||
# zarr = [math.cos(13) for i in range(1,100000)] | ||
# z = zarr[0] | ||
z = 0.1 | ||
while i < 100000: | ||
# z = math.cos(13) | ||
# z = np.multiply(x,x) | ||
# z = np.multiply(z,z) | ||
# z = np.multiply(z,z) | ||
z = z * z | ||
z = x * x | ||
z = z * z | ||
z = z * z | ||
i += 1 | ||
return z | ||
|
||
@profile | ||
def doit3(x): | ||
for i in range(1000000): | ||
z = x + 1 | ||
z = x + 1 | ||
z = x + 1 | ||
z = x + z | ||
z = x + z | ||
# z = np.cos(x) | ||
return z | ||
|
||
def stuff(): | ||
# y = np.random.randint(1, 100, size=50000000)[49999999] | ||
x = 1.01 | ||
for i in range(1,3): | ||
# print(i) | ||
for j in range(1,3): | ||
x = doit1(x) | ||
x = doit2(x) | ||
x = doit3(x) | ||
x = 1.01 | ||
return x | ||
|
||
import sys | ||
# print("TESTME") | ||
# print(sys.argv) | ||
stuff() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import sys | ||
import json | ||
|
||
def smoketest(fname): | ||
proc = subprocess.run( [sys.executable, "-m", "scalene", "--cli", "--json", "--outfile", "/dev/stderr", fname] ,capture_output=True) | ||
if proc.returncode != 0: | ||
print("Exited with a non-zero code:", proc.returncode) | ||
print("Stdout:", proc.stdout.decode('utf-8')) | ||
print("Stderr:", proc.stderr.decode('utf-8')) | ||
|
||
exit(proc.returncode) | ||
|
||
stderr = proc.stderr.decode('utf-8') | ||
try: | ||
scalene_json = json.loads(stderr) | ||
except json.JSONDecodeError: | ||
print("Invalid JSON", stderr) | ||
exit(1) | ||
if len(scalene_json) == 0: | ||
print("No JSON output") | ||
exit(1) | ||
files = scalene_json['files'] | ||
if not len(files) > 0: | ||
print("No files found in output") | ||
exit(1) | ||
_fname = list(files.keys())[0] | ||
function_list = files[_fname]['functions'] | ||
exit_code = 0 | ||
|
||
# if 'doit1' not in function_dict: | ||
expected_functions = ['doit1', 'doit3'] | ||
unexpected_functions = ['doit2'] | ||
for fn_name in expected_functions: | ||
if not any(fn_name in f['line'] for f in function_list): | ||
print(f"Expected function '{fn_name}' not returned") | ||
exit_code = 1 | ||
for fn_name in unexpected_functions: | ||
if any(fn_name in f['line'] for f in function_list): | ||
print(f"Unexpected function '{fn_name}' returned") | ||
exit_code = 1 | ||
if exit_code != 0: | ||
print(function_list) | ||
exit(exit_code) | ||
|
||
if __name__ == '__main__': | ||
smoketest('test/profile_annotation_test.py') |