pyglove 0.4.5.dev202410230809__py3-none-any.whl → 0.4.5.dev202410250809__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.
Potentially problematic release.
This version of pyglove might be problematic. Click here for more details.
- pyglove/core/object_utils/profiling.py +34 -0
- pyglove/core/object_utils/profiling_test.py +32 -0
- {pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/METADATA +1 -1
- {pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/RECORD +7 -7
- {pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/LICENSE +0 -0
- {pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/WHEEL +0 -0
- {pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/top_level.txt +0 -0
@@ -41,6 +41,40 @@ class TimeIt:
|
|
41
41
|
"""Returns whether the context has error."""
|
42
42
|
return self.error is not None
|
43
43
|
|
44
|
+
@dataclasses.dataclass
|
45
|
+
class StatusSummary:
|
46
|
+
"""Aggregated summary for repeated calls for `pg.timeit`."""
|
47
|
+
|
48
|
+
@dataclasses.dataclass
|
49
|
+
class Entry:
|
50
|
+
"""Aggregated status from the `pg.timeit` calls of the same name."""
|
51
|
+
|
52
|
+
num_started: int = 0
|
53
|
+
num_ended: int = 0
|
54
|
+
num_failed: int = 0
|
55
|
+
avg_duration: float = 0.0
|
56
|
+
|
57
|
+
def update(self, status: 'TimeIt.Status'):
|
58
|
+
self.avg_duration = (
|
59
|
+
(self.avg_duration * self.num_started + status.elapse)
|
60
|
+
/ (self.num_started + 1)
|
61
|
+
)
|
62
|
+
self.num_started += 1
|
63
|
+
if status.has_ended:
|
64
|
+
self.num_ended += 1
|
65
|
+
if status.has_error:
|
66
|
+
self.num_failed += 1
|
67
|
+
|
68
|
+
breakdown: dict[str, 'TimeIt.StatusSummary.Entry'] = (
|
69
|
+
dataclasses.field(default_factory=dict)
|
70
|
+
)
|
71
|
+
|
72
|
+
def aggregate(self, timeit_obj: 'TimeIt'):
|
73
|
+
for k, v in timeit_obj.status().items():
|
74
|
+
if k not in self.breakdown:
|
75
|
+
self.breakdown[k] = TimeIt.StatusSummary.Entry()
|
76
|
+
self.breakdown[k].update(v)
|
77
|
+
|
44
78
|
def __init__(self, name: str):
|
45
79
|
self._name = name
|
46
80
|
self._start_time = None
|
@@ -101,6 +101,38 @@ class TimeItTest(unittest.TestCase):
|
|
101
101
|
self.assertTrue(r['node.child.grandchild'].has_error)
|
102
102
|
self.assertTrue(t2.has_error)
|
103
103
|
|
104
|
+
def test_timeit_summary(self):
|
105
|
+
summary = profiling.TimeIt.StatusSummary()
|
106
|
+
for i in range(10):
|
107
|
+
with profiling.timeit('node') as t:
|
108
|
+
time.sleep(0.1)
|
109
|
+
with profiling.timeit('child'):
|
110
|
+
time.sleep(0.1)
|
111
|
+
try:
|
112
|
+
with profiling.timeit('grandchild'):
|
113
|
+
time.sleep(0.1)
|
114
|
+
if i < 2:
|
115
|
+
raise ValueError('error')
|
116
|
+
except ValueError:
|
117
|
+
pass
|
118
|
+
summary.aggregate(t)
|
119
|
+
self.assertEqual(
|
120
|
+
list(summary.breakdown.keys()),
|
121
|
+
['node', 'node.child', 'node.child.grandchild']
|
122
|
+
)
|
123
|
+
self.assertEqual(
|
124
|
+
[x.num_started for x in summary.breakdown.values()],
|
125
|
+
[10, 10, 10]
|
126
|
+
)
|
127
|
+
self.assertEqual(
|
128
|
+
[x.num_ended for x in summary.breakdown.values()],
|
129
|
+
[10, 10, 10]
|
130
|
+
)
|
131
|
+
self.assertEqual(
|
132
|
+
[x.num_failed for x in summary.breakdown.values()],
|
133
|
+
[0, 0, 2]
|
134
|
+
)
|
135
|
+
|
104
136
|
|
105
137
|
if __name__ == '__main__':
|
106
138
|
unittest.main()
|
@@ -62,8 +62,8 @@ pyglove/core/object_utils/json_conversion.py,sha256=1XEwz4LzEh8wHsTIC7jL7lD7L5tK
|
|
62
62
|
pyglove/core/object_utils/json_conversion_test.py,sha256=KGt0r628KHi4fTfeCgrhirfINpYXIR45l5ER4z09jjI,11907
|
63
63
|
pyglove/core/object_utils/missing.py,sha256=0liMs9iEyQxxu6UohdJ5hEM246e9Nu05qp0hqriHsl0,1459
|
64
64
|
pyglove/core/object_utils/missing_test.py,sha256=B36p-vqUvAnXWMszAj9GOPBN0_8cq7vVF61AkcsZ9qU,1396
|
65
|
-
pyglove/core/object_utils/profiling.py,sha256=
|
66
|
-
pyglove/core/object_utils/profiling_test.py,sha256=
|
65
|
+
pyglove/core/object_utils/profiling.py,sha256=hNMd4BY2jCOOV3o0VTlweHxZwd8yGylDzW6GgHU1-j8,5385
|
66
|
+
pyglove/core/object_utils/profiling_test.py,sha256=LvFy8qrAJUD-A4O7NBWZJ5YfjSGtc_zpmATCMs9hSp8,4322
|
67
67
|
pyglove/core/object_utils/thread_local.py,sha256=i-CnyY3VREtLfAj4_JndBnsKuQLIgwG29ma8dAyRxbI,4839
|
68
68
|
pyglove/core/object_utils/thread_local_test.py,sha256=EvU1-TF7KqpLQxxBvHd7dxtuY22YUQSIwQ0UcR-NORA,6816
|
69
69
|
pyglove/core/object_utils/value_location.py,sha256=lSFQNTazY2M6_nRLmMbouqZAcZSiOLZQnmQPMD2FDMs,26770
|
@@ -184,8 +184,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
|
|
184
184
|
pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
|
185
185
|
pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
|
186
186
|
pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
|
187
|
-
pyglove-0.4.5.
|
188
|
-
pyglove-0.4.5.
|
189
|
-
pyglove-0.4.5.
|
190
|
-
pyglove-0.4.5.
|
191
|
-
pyglove-0.4.5.
|
187
|
+
pyglove-0.4.5.dev202410250809.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
188
|
+
pyglove-0.4.5.dev202410250809.dist-info/METADATA,sha256=4CGLwQ3fv1z75j3jovVT-998UWzSrZYpiwUYwuGT5kU,6666
|
189
|
+
pyglove-0.4.5.dev202410250809.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
190
|
+
pyglove-0.4.5.dev202410250809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
|
191
|
+
pyglove-0.4.5.dev202410250809.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{pyglove-0.4.5.dev202410230809.dist-info → pyglove-0.4.5.dev202410250809.dist-info}/top_level.txt
RENAMED
File without changes
|