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

Function generate_function_charts

scripts_python/profiling_statistics.py:463–575  ·  view source on GitHub ↗
(conn: sqlite3.Connection, output_dir: Path, pbar: tqdm)

Source from the content-addressed store, hash-verified

461
462
463def generate_function_charts(conn: sqlite3.Connection, output_dir: Path, pbar: tqdm):
464 cursor = conn.cursor()
465
466 cursor.execute("""
467 SELECT DISTINCT f.function_name, f.module_name, f.id, f.is_builtin, f.filename
468 FROM functions f
469 JOIN function_stats fs ON f.id = fs.function_id
470 WHERE f.is_builtin = 0
471 """)
472
473 functions = cursor.fetchall()
474
475 project_functions = []
476 for func_name, module_name, func_id, is_builtin, filename in functions:
477 if is_builtin or not filename or filename == "~":
478 continue
479 if "site-packages" in filename or "/lib/" in filename or "/lib64/" in filename:
480 continue
481 project_functions.append((func_name, module_name, func_id))
482
483 for func_name, module_name, func_id in project_functions:
484 pbar.set_postfix_str(f"Function: {module_name or 'unknown'}_{func_name[:30]}")
485 safe_func_name = (
486 func_name.replace("/", "_").replace("<", "").replace(">", "").replace(":", "_")
487 )
488 safe_module_name = (
489 (module_name or "unknown")
490 .replace("/", "_")
491 .replace("<", "")
492 .replace(">", "")
493 .replace(":", "_")
494 )
495
496 func_dir = output_dir / "functions" / f"{safe_module_name}_{safe_func_name}"
497 func_dir.mkdir(parents=True, exist_ok=True)
498
499 cursor.execute("SELECT call_count FROM function_stats WHERE function_id = ?", (func_id,))
500 call_counts = np.array([row[0] for row in cursor.fetchall()])
501 if len(call_counts) > 0:
502 create_histogram(
503 call_counts,
504 f"Call Count Distribution - {func_name}",
505 "Call Count",
506 func_dir / "hist_call_count.png",
507 )
508
509 cursor.execute(
510 "SELECT primitive_call_count FROM function_stats WHERE function_id = ?", (func_id,)
511 )
512 prim_counts = np.array([row[0] for row in cursor.fetchall()])
513 if len(prim_counts) > 0:
514 create_histogram(
515 prim_counts,
516 f"Primitive Call Count Distribution - {func_name}",
517 "Primitive Call Count",
518 func_dir / "hist_primitive_call_count.png",
519 )
520

Callers 1

generate_all_chartsFunction · 0.70

Calls 2

create_histogramFunction · 0.70
create_scatterplotFunction · 0.70

Tested by

no test coverage detected