MCPcopy Create free account
hub / github.com/dbt-labs/ade-bench / import_cprofile_data

Function import_cprofile_data

scripts_python/profiling_statistics.py:185–260  ·  view source on GitHub ↗
(cursor: sqlite3.Cursor, run_id: int, prof_path: Path)

Source from the content-addressed store, hash-verified

183
184
185def import_cprofile_data(cursor: sqlite3.Cursor, run_id: int, prof_path: Path):
186 if not prof_path.exists():
187 return
188
189 stats = pstats.Stats(str(prof_path))
190
191 cursor.execute(
192 """
193 UPDATE profiling_runs
194 SET total_function_calls = ?,
195 primitive_calls = ?,
196 total_time_seconds = ?
197 WHERE id = ?
198 """,
199 (stats.total_calls, stats.prim_calls, stats.total_tt, run_id),
200 )
201
202 for func_tuple, (cc, nc, tt, ct, callers) in stats.stats.items():
203 function_id = get_or_create_function(cursor, func_tuple)
204
205 time_per_call = tt / nc if nc > 0 else 0
206 cumulative_per_call = ct / cc if cc > 0 else 0
207 time_percentage = (tt / stats.total_tt * 100) if stats.total_tt > 0 else 0
208
209 cursor.execute(
210 """
211 INSERT INTO function_stats
212 (run_id, function_id, call_count, primitive_call_count,
213 total_time, cumulative_time, time_per_call, cumulative_per_call, time_percentage)
214 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
215 """,
216 (
217 run_id,
218 function_id,
219 nc,
220 cc,
221 tt,
222 ct,
223 time_per_call,
224 cumulative_per_call,
225 time_percentage,
226 ),
227 )
228
229 for caller_tuple, caller_stats in callers.items():
230 caller_function_id = get_or_create_function(cursor, caller_tuple)
231
232 if isinstance(caller_stats, tuple):
233 caller_nc, caller_cc, caller_tt, caller_ct = caller_stats
234 cursor.execute(
235 """
236 INSERT INTO call_relationships
237 (run_id, caller_function_id, callee_function_id, call_count, total_time, cumulative_time)
238 VALUES (?, ?, ?, ?, ?, ?)
239 """,
240 (run_id, caller_function_id, function_id, caller_nc, caller_tt, caller_ct),
241 )
242 else:

Callers 1

import_single_folderFunction · 0.70

Calls 1

get_or_create_functionFunction · 0.70

Tested by

no test coverage detected