ソースを参照

profile individual functions easily

Joseph Brandenburg 2 週間 前
親
コミット
522abd34ad
1 ファイル変更、7 行追加、4 行削除
  1. 7 4
      ops_nodegroup.py

+ 7 - 4
ops_nodegroup.py

@@ -290,6 +290,7 @@ class ExecuteNodeTree(Operator):
             sortby = SortKey.TIME
             if 'cum' in environ.get("DOPROFILE").lower():
                 sortby = SortKey.CUMULATIVE
+            profile_function = environ.get("PROFILE_FUNCTION")
             printme1 = ''
             with cProfile.Profile() as pr:
                 tree.update_tree(context, error_popups = pass_error)
@@ -297,8 +298,9 @@ class ExecuteNodeTree(Operator):
                 s1 = io.StringIO()
                 ps1 = pstats.Stats(pr, stream=s1).strip_dirs().sort_stats(sortby)
                 ps1.print_stats(30) # print the top 20
-                # ps1.print_callers("is_signature_in_other_signature")
-                # ps1.print_callees("is_signature_in_other_signature")
+                if profile_function:
+                    ps1.print_callers(profile_function)
+                    ps1.print_callees(profile_function)
                 printme1 += s1.getvalue()
                 printme1 += f"Total profiled time: {ps1.total_tt:.6f} seconds"
             with cProfile.Profile() as pr:
@@ -307,8 +309,9 @@ class ExecuteNodeTree(Operator):
                 s = io.StringIO()
                 ps = pstats.Stats(pr, stream=s).strip_dirs().sort_stats(sortby)
                 ps.print_stats(30) # print the top 20
-                # ps.print_callers("is_signature_in_other_signature")
-                # ps.print_callees("is_signature_in_other_signature")
+                if profile_function:
+                    ps.print_callers(profile_function)
+                    ps.print_callees(profile_function)
                 print (printme1)
                 print(s.getvalue())
                 print(f"Total profiled time: {ps.total_tt:.6f} seconds")