99
1010@pytest .fixture
1111def trace_file ():
12- return Path (__file__ ).parent .parent / "code_to_optimize/code_directories/simple_tracer_e2e/codeflash.trace.sqlite3 "
12+ return Path (__file__ ).parent .parent / "code_to_optimize/code_directories/simple_tracer_e2e/codeflash.trace"
1313
1414
1515@pytest .fixture
@@ -58,8 +58,8 @@ def test_load_function_stats(function_ranker):
5858 # Verify funcA specific values
5959 assert func_a_stats ["function_name" ] == "funcA"
6060 assert func_a_stats ["call_count" ] == 1
61- assert func_a_stats ["own_time_ns" ] == 27000
62- assert func_a_stats ["cumulative_time_ns" ] == 1629000
61+ assert func_a_stats ["own_time_ns" ] == 153000
62+ assert func_a_stats ["cumulative_time_ns" ] == 5960000
6363
6464
6565def test_get_function_ttx_score (function_ranker , workload_functions ):
@@ -73,8 +73,8 @@ def test_get_function_ttx_score(function_ranker, workload_functions):
7373 ttx_score = function_ranker .get_function_ttx_score (func_a )
7474
7575 # Expected ttX score: own_time + (time_in_callees * call_count)
76- # = 27000 + ((1629000 - 27000 ) * 1) = 1629000
77- assert ttx_score == 1629000
76+ # = 153000 + ((5960000 - 153000 ) * 1) = 5960000
77+ assert ttx_score == 5960000
7878
7979
8080def test_rank_functions (function_ranker , workload_functions ):
@@ -112,9 +112,9 @@ def test_get_function_stats_summary(function_ranker, workload_functions):
112112
113113 assert stats is not None
114114 assert stats ["function_name" ] == "funcA"
115- assert stats ["own_time_ns" ] == 27000
116- assert stats ["cumulative_time_ns" ] == 1629000
117- assert stats ["ttx_score" ] == 1629000
115+ assert stats ["own_time_ns" ] == 153000
116+ assert stats ["cumulative_time_ns" ] == 5960000
117+ assert stats ["ttx_score" ] == 5960000
118118
119119
120120
@@ -134,5 +134,39 @@ def test_importance_calculation(function_ranker):
134134 assert func_a_stats is not None
135135 importance = func_a_stats ["own_time_ns" ] / total_program_time
136136
137- # funcA importance should be approximately 0.33% (27000/8242000)
138- assert abs (importance - 0.00327 ) < 0.001
137+ # funcA importance should be approximately 1.0% (153000/15281000)
138+ assert abs (importance - 0.01001 ) < 0.001
139+
140+
141+ def test_simple_model_predict_stats (function_ranker , workload_functions ):
142+ # Find SimpleModel::predict function
143+ predict_func = None
144+ for func in workload_functions :
145+ if func .function_name == "predict" :
146+ predict_func = func
147+ break
148+
149+ assert predict_func is not None
150+
151+ stats = function_ranker .get_function_stats_summary (predict_func )
152+ assert stats is not None
153+ assert stats ["function_name" ] == "predict"
154+ assert stats ["call_count" ] == 1
155+ assert stats ["own_time_ns" ] == 2368000
156+ assert stats ["cumulative_time_ns" ] == 4103000
157+ assert stats ["ttx_score" ] == 4103000
158+
159+ # Test ttX score calculation
160+ ttx_score = function_ranker .get_function_ttx_score (predict_func )
161+ # Expected ttX score: own_time + (time_in_callees * call_count)
162+ # = 2368000 + ((4103000 - 2368000) * 1) = 4103000
163+ assert ttx_score == 4103000
164+
165+ # Test importance calculation for predict function
166+ total_program_time = sum (
167+ s ["own_time_ns" ] for s in function_ranker ._function_stats .values ()
168+ if s .get ("own_time_ns" , 0 ) > 0
169+ )
170+ importance = stats ["own_time_ns" ] / total_program_time
171+ # predict importance should be approximately 15.5% (2368000/15281000)
172+ assert abs (importance - 0.155 ) < 0.01
0 commit comments