kenenet 1.0.3__py3-none-any.whl → 1.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kenenet/__init__.py +72 -4
- {kenenet-1.0.3.dist-info → kenenet-1.0.6.dist-info}/METADATA +1 -1
- kenenet-1.0.6.dist-info/RECORD +5 -0
- kenenet-1.0.3.dist-info/RECORD +0 -5
- {kenenet-1.0.3.dist-info → kenenet-1.0.6.dist-info}/WHEEL +0 -0
- {kenenet-1.0.3.dist-info → kenenet-1.0.6.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -286,10 +286,60 @@ _block_timings = defaultdict(float)
|
|
286
286
|
_current_context = None
|
287
287
|
_line_start_time = None
|
288
288
|
_stack = []
|
289
|
-
_ignore_line = {'frame = inspect.currentframe().f_back', 'filename = frame.f_code.co_filename', 'if _current_context is None:', 'sys.settrace(None)', 'Function: currentframe', 'return sys._getframe(1) if hasattr(sys, "_getframe") else None'}
|
289
|
+
_ignore_line = {'frame = inspect.currentframe().f_back', 'filename = frame.f_code.co_filename', 'if _current_context is None:', 'sys.settrace(None)', 'Function: currentframe', 'return sys._getframe(1) if hasattr(sys, "_getframe") else None', ' Function: recurser', 'Function: <listcomp>', 'Function: here', 'Function: _array_repr_implementation', 'Function: wrapper', 'Function: array2string', 'Function: _array2string', 'Function: _formatArray', 'Function: _extendLine_pretty', 'Function: _extendLine', 'Function: __call__', 'Function: _var', 'Function: _std', 'Function: std', 'Function: _leading_trailing', 'Function: __init__'}
|
290
290
|
_seen_lines = set() # Track lines we've already processed
|
291
291
|
_current_function = None
|
292
292
|
_function_lines = defaultdict(set) # Track which lines belong to which function
|
293
|
+
_site_packages_dirs = [] # List to store site-packages directories
|
294
|
+
|
295
|
+
# Patterns for generated code constructs to ignore
|
296
|
+
_ignore_function_patterns = {
|
297
|
+
'<dictcomp>',
|
298
|
+
'<lambda>',
|
299
|
+
'<setcomp>',
|
300
|
+
'<listcomp>',
|
301
|
+
'<genexpr>',
|
302
|
+
'<comprehension>',
|
303
|
+
'<module>'
|
304
|
+
}
|
305
|
+
|
306
|
+
# Initialize site-packages directories
|
307
|
+
import sys
|
308
|
+
import os
|
309
|
+
import inspect
|
310
|
+
import time
|
311
|
+
import re
|
312
|
+
import linecache
|
313
|
+
from collections import defaultdict
|
314
|
+
|
315
|
+
# Get site-packages directories from sys.path
|
316
|
+
for path in sys.path:
|
317
|
+
if 'site-packages' in path or 'dist-packages' in path:
|
318
|
+
_site_packages_dirs.append(path)
|
319
|
+
|
320
|
+
|
321
|
+
def _is_package_code(filename):
|
322
|
+
"""Check if the given filename is from an imported package."""
|
323
|
+
# Skip if it's in site-packages
|
324
|
+
for site_dir in _site_packages_dirs:
|
325
|
+
if filename.startswith(site_dir):
|
326
|
+
return True
|
327
|
+
|
328
|
+
# Skip if it's a built-in module
|
329
|
+
if '<' in filename and '>' in filename: # Handles '<frozen importlib._bootstrap>' etc.
|
330
|
+
return True
|
331
|
+
|
332
|
+
# Skip standard library modules
|
333
|
+
for path in sys.path:
|
334
|
+
if 'python' in path.lower() and os.path.isdir(path) and not path.endswith('site-packages'):
|
335
|
+
if filename.startswith(path):
|
336
|
+
return True
|
337
|
+
|
338
|
+
return False
|
339
|
+
|
340
|
+
def _is_generated_construct(func_name):
|
341
|
+
"""Check if the function name is a generated construct like <dictcomp>, <lambda>, etc."""
|
342
|
+
return any(pattern in func_name for pattern in _ignore_function_patterns)
|
293
343
|
|
294
344
|
|
295
345
|
def time_code(label=None):
|
@@ -313,9 +363,18 @@ def time_code(label=None):
|
|
313
363
|
def trace_function(frame, event, arg):
|
314
364
|
global _line_start_time, _stack, _seen_lines, _current_function, _function_lines
|
315
365
|
|
366
|
+
# Skip tracking for package code
|
367
|
+
if _is_package_code(frame.f_code.co_filename):
|
368
|
+
return trace_function
|
369
|
+
|
316
370
|
# Track function calls and returns
|
317
371
|
if event == 'call':
|
318
372
|
func_name = frame.f_code.co_name
|
373
|
+
|
374
|
+
# Skip recording generated constructs
|
375
|
+
if _is_generated_construct(func_name):
|
376
|
+
return trace_function
|
377
|
+
|
319
378
|
if func_name != 'time_code':
|
320
379
|
_stack.append((func_name, time.time()))
|
321
380
|
_current_function = func_name # Track current function
|
@@ -324,8 +383,11 @@ def time_code(label=None):
|
|
324
383
|
elif event == 'return':
|
325
384
|
if _stack:
|
326
385
|
func_name, start_time = _stack.pop()
|
327
|
-
|
328
|
-
|
386
|
+
|
387
|
+
# Skip recording generated constructs
|
388
|
+
if not _is_generated_construct(func_name):
|
389
|
+
elapsed = time.time() - start_time
|
390
|
+
_block_timings[f"Function: {func_name}"] += elapsed
|
329
391
|
|
330
392
|
# Reset current function if we're returning from it
|
331
393
|
if _current_function == func_name and _stack:
|
@@ -349,6 +411,10 @@ def time_code(label=None):
|
|
349
411
|
# This might be the ending call, let's continue execution
|
350
412
|
return trace_function
|
351
413
|
|
414
|
+
# Skip recording if we're in a generated construct
|
415
|
+
if _current_function and _is_generated_construct(_current_function):
|
416
|
+
return trace_function
|
417
|
+
|
352
418
|
# Record elapsed time since last line
|
353
419
|
current_time = time.time()
|
354
420
|
if _line_start_time is not None:
|
@@ -431,7 +497,9 @@ def time_code(label=None):
|
|
431
497
|
sorted_blocks = sorted(_block_timings.items(), key=lambda x: x[1], reverse=True)
|
432
498
|
|
433
499
|
for block, elapsed in sorted_blocks:
|
434
|
-
|
500
|
+
# Filter out generated constructs and ignored lines
|
501
|
+
if (not any(ignore in block for ignore in _ignore_line) and
|
502
|
+
not any(pattern in block for pattern in _ignore_function_patterns)):
|
435
503
|
percentage = (elapsed / total_time) * 100 if total_time > 0 else 0
|
436
504
|
quick_print(f"{block[:40]:40} | {elapsed:12.6f} | {percentage:10.2f}%")
|
437
505
|
|
@@ -0,0 +1,5 @@
|
|
1
|
+
kenenet/__init__.py,sha256=9-wRVH9wkUX6ivZSU5qp1bmW3zLQ5uzOOs9Fz-wiwhM,21796
|
2
|
+
kenenet-1.0.6.dist-info/METADATA,sha256=eAlg0SPPCd5loqaHciquo2WsrHeoJSwlOVOFO0M7e0Y,1693
|
3
|
+
kenenet-1.0.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
+
kenenet-1.0.6.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
+
kenenet-1.0.6.dist-info/RECORD,,
|
kenenet-1.0.3.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=TFgUSpmlHhk8DSDPJiP7sy-Rd8-rRxt2a7jfEhWiANA,19006
|
2
|
-
kenenet-1.0.3.dist-info/METADATA,sha256=C4jOWMNxXJMbfuoIcoZqmSC1vvrqiSHKc3Y3nrSLJRU,1693
|
3
|
-
kenenet-1.0.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-1.0.3.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-1.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|