halib 0.2.13__tar.gz → 0.2.14__tar.gz
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.
- {halib-0.2.13 → halib-0.2.14}/PKG-INFO +4 -1
- {halib-0.2.13 → halib-0.2.14}/README.md +3 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/profiler.py +49 -6
- {halib-0.2.13 → halib-0.2.14}/halib.egg-info/PKG-INFO +4 -1
- {halib-0.2.13 → halib-0.2.14}/setup.py +1 -1
- {halib-0.2.13 → halib-0.2.14}/.gitignore +0 -0
- {halib-0.2.13 → halib-0.2.14}/GDriveFolder.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/LICENSE.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/MANIFEST.in +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/common/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/common/common.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/common/rich_color.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/core/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/core/base_config.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/core/base_exp.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/core/param_gen.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/core/wandb_op.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/data/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/data/dataclass_util.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/data/dataset.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/data/torchloader.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/flop_calc.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/gpu_mon.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/perfcalc.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/perfmetrics.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/perf/perftb.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/viz/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/exp/viz/plot.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/csvfile.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/ipynb.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/jsonfile.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/textfile.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/videofile.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/filetype/yamlfile.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/online/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/online/gdrive.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/online/gdrive_mkdir.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/online/projectmake.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/online/tele_noti.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/system/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/system/_list_pc.csv +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/system/cmd.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/system/filesys.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/system/path.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/utils/__init__.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/utils/dict.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib/utils/list.py +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib.egg-info/SOURCES.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib.egg-info/dependency_links.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib.egg-info/requires.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/halib.egg-info/top_level.txt +0 -0
- {halib-0.2.13 → halib-0.2.14}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.14
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -53,6 +53,9 @@ Dynamic: summary
|
|
|
53
53
|
|
|
54
54
|
# Helper package for coding and automation
|
|
55
55
|
|
|
56
|
+
**Version 0.2.14**
|
|
57
|
+
+ update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
|
|
58
|
+
|
|
56
59
|
**Version 0.2.13**
|
|
57
60
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
58
61
|
+ update `exp/perfcalc.py` to allow save computed performance to csv file (without explicit calling method `calc_perfs`)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Helper package for coding and automation
|
|
2
2
|
|
|
3
|
+
**Version 0.2.14**
|
|
4
|
+
+ update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
|
|
5
|
+
|
|
3
6
|
**Version 0.2.13**
|
|
4
7
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
5
8
|
+ update `exp/perfcalc.py` to allow save computed performance to csv file (without explicit calling method `calc_perfs`)
|
|
@@ -1,19 +1,48 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import time
|
|
3
3
|
import json
|
|
4
|
-
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
from pprint import pprint
|
|
7
6
|
from threading import Lock
|
|
7
|
+
from functools import wraps
|
|
8
8
|
from loguru import logger
|
|
9
9
|
|
|
10
|
+
# Plotting libraries
|
|
10
11
|
from plotly.subplots import make_subplots
|
|
11
12
|
import plotly.graph_objects as go
|
|
12
13
|
import plotly.express as px # for dynamic color scales
|
|
13
14
|
|
|
14
15
|
from ...common.common import ConsoleLog
|
|
16
|
+
from ...system.path import *
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ==========================================
|
|
20
|
+
# 1. The Decorator
|
|
21
|
+
# ==========================================
|
|
22
|
+
def check_enabled(func):
|
|
23
|
+
"""
|
|
24
|
+
Decorator to skip method execution if the profiler is disabled.
|
|
25
|
+
|
|
26
|
+
This acts as a 'guard clause' for the entire function. If the profiler
|
|
27
|
+
instance has 'enabled=False', the decorated function is not executed at all,
|
|
28
|
+
saving processing time and avoiding side effects.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@wraps(func)
|
|
32
|
+
def wrapper(self, *args, **kwargs):
|
|
33
|
+
# Gracefully handle cases where 'enabled' might not be set yet (default to True)
|
|
34
|
+
# print('check_enabled called')
|
|
35
|
+
if not getattr(self, "enabled", True):
|
|
36
|
+
# print('Profiler disabled, skipping function execution.')
|
|
37
|
+
return # Exit immediately, returning None
|
|
38
|
+
return func(self, *args, **kwargs)
|
|
15
39
|
|
|
40
|
+
return wrapper
|
|
16
41
|
|
|
42
|
+
|
|
43
|
+
# ==========================================
|
|
44
|
+
# 2. The Class
|
|
45
|
+
# ==========================================
|
|
17
46
|
class zProfiler:
|
|
18
47
|
"""A singleton profiler to measure execution time of contexts and steps.
|
|
19
48
|
|
|
@@ -41,13 +70,24 @@ class zProfiler:
|
|
|
41
70
|
cls._instance = super().__new__(cls)
|
|
42
71
|
return cls._instance
|
|
43
72
|
|
|
44
|
-
def __init__(
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
def __init__(self, enabled=None):
|
|
74
|
+
"""
|
|
75
|
+
Args:
|
|
76
|
+
enabled (bool, optional):
|
|
77
|
+
- If True/False: Updates the enabled state immediately.
|
|
78
|
+
- If None: Keeps the current state (defaults to True on first init).
|
|
79
|
+
"""
|
|
80
|
+
# 1. First-time initialization
|
|
47
81
|
if not hasattr(self, "_initialized"):
|
|
82
|
+
self.enabled = enabled if enabled is not None else True
|
|
48
83
|
self.time_dict = {}
|
|
49
84
|
self._initialized = True
|
|
50
85
|
|
|
86
|
+
# 2. If initialized, allow updating 'enabled' ONLY if explicitly passed
|
|
87
|
+
elif enabled is not None:
|
|
88
|
+
self.enabled = enabled
|
|
89
|
+
|
|
90
|
+
@check_enabled
|
|
51
91
|
def ctx_start(self, ctx_name="ctx_default"):
|
|
52
92
|
if not isinstance(ctx_name, str) or not ctx_name:
|
|
53
93
|
raise ValueError("ctx_name must be a non-empty string")
|
|
@@ -59,6 +99,7 @@ class zProfiler:
|
|
|
59
99
|
}
|
|
60
100
|
self.time_dict[ctx_name]["report_count"] += 1
|
|
61
101
|
|
|
102
|
+
@check_enabled
|
|
62
103
|
def ctx_end(self, ctx_name="ctx_default", report_func=None):
|
|
63
104
|
if ctx_name not in self.time_dict:
|
|
64
105
|
return
|
|
@@ -67,6 +108,7 @@ class zProfiler:
|
|
|
67
108
|
self.time_dict[ctx_name]["end"] - self.time_dict[ctx_name]["start"]
|
|
68
109
|
)
|
|
69
110
|
|
|
111
|
+
@check_enabled
|
|
70
112
|
def step_start(self, ctx_name, step_name):
|
|
71
113
|
if not isinstance(step_name, str) or not step_name:
|
|
72
114
|
raise ValueError("step_name must be a non-empty string")
|
|
@@ -76,6 +118,7 @@ class zProfiler:
|
|
|
76
118
|
self.time_dict[ctx_name]["step_dict"][step_name] = []
|
|
77
119
|
self.time_dict[ctx_name]["step_dict"][step_name].append([time.perf_counter()])
|
|
78
120
|
|
|
121
|
+
@check_enabled
|
|
79
122
|
def step_end(self, ctx_name, step_name):
|
|
80
123
|
if (
|
|
81
124
|
ctx_name not in self.time_dict
|
|
@@ -167,7 +210,6 @@ class zProfiler:
|
|
|
167
210
|
)
|
|
168
211
|
return report_dict
|
|
169
212
|
|
|
170
|
-
@classmethod
|
|
171
213
|
@classmethod
|
|
172
214
|
def plot_formatted_data(
|
|
173
215
|
cls, profiler_data, outdir=None, file_format="png", do_show=False, tag=""
|
|
@@ -261,7 +303,8 @@ class zProfiler:
|
|
|
261
303
|
file_prefix = ctx if len(tag_str) == 0 else f"{tag_str}_{ctx}"
|
|
262
304
|
file_path = os.path.join(outdir, f"{file_prefix}_summary.{file_format.lower()}")
|
|
263
305
|
fig.write_image(file_path)
|
|
264
|
-
|
|
306
|
+
pprint(f"Saved figure to: 🔽")
|
|
307
|
+
pprint_local_path(file_path)
|
|
265
308
|
|
|
266
309
|
results[ctx] = fig
|
|
267
310
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.14
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -53,6 +53,9 @@ Dynamic: summary
|
|
|
53
53
|
|
|
54
54
|
# Helper package for coding and automation
|
|
55
55
|
|
|
56
|
+
**Version 0.2.14**
|
|
57
|
+
+ update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
|
|
58
|
+
|
|
56
59
|
**Version 0.2.13**
|
|
57
60
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
58
61
|
+ update `exp/perfcalc.py` to allow save computed performance to csv file (without explicit calling method `calc_perfs`)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|