pyglove 0.5.0.dev202509300811__py3-none-any.whl → 0.5.0.dev202510020810__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/monitoring.py +13 -1
- pyglove/core/monitoring_test.py +6 -0
- {pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/METADATA +1 -1
- {pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/RECORD +7 -7
- {pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/WHEEL +0 -0
- {pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/licenses/LICENSE +0 -0
- {pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/top_level.txt +0 -0
pyglove/core/monitoring.py
CHANGED
|
@@ -19,10 +19,12 @@ programs.
|
|
|
19
19
|
|
|
20
20
|
import abc
|
|
21
21
|
import collections
|
|
22
|
+
import contextlib
|
|
22
23
|
import math
|
|
23
24
|
import threading
|
|
25
|
+
import time
|
|
24
26
|
import typing
|
|
25
|
-
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
|
|
27
|
+
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
try:
|
|
@@ -194,6 +196,16 @@ class Scalar(Metric):
|
|
|
194
196
|
The distribution of the scalar.
|
|
195
197
|
"""
|
|
196
198
|
|
|
199
|
+
@contextlib.contextmanager
|
|
200
|
+
def record_duration(self, scale: int = 1000, **parameters) -> Iterator[None]:
|
|
201
|
+
"""Context manager that records the duration of code block to the scalar."""
|
|
202
|
+
start_time = time.time()
|
|
203
|
+
try:
|
|
204
|
+
yield
|
|
205
|
+
finally:
|
|
206
|
+
duration = (time.time() - start_time) * scale
|
|
207
|
+
self.record(int(duration), **parameters)
|
|
208
|
+
|
|
197
209
|
|
|
198
210
|
class MetricCollection(metaclass=abc.ABCMeta):
|
|
199
211
|
"""Base class for counter collections."""
|
pyglove/core/monitoring_test.py
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
import time
|
|
15
16
|
import unittest
|
|
16
17
|
from pyglove.core import monitoring
|
|
17
18
|
|
|
@@ -205,6 +206,11 @@ class InMemoryScalarTest(unittest.TestCase):
|
|
|
205
206
|
scalar.distribution()
|
|
206
207
|
self.assertEqual(dist.count, 3)
|
|
207
208
|
|
|
209
|
+
scalar = collection.get_scalar('scalar2', 'scalar description')
|
|
210
|
+
with scalar.record_duration():
|
|
211
|
+
time.sleep(0.1)
|
|
212
|
+
self.assertGreaterEqual(scalar.distribution().mean, 100)
|
|
213
|
+
|
|
208
214
|
def test_scalar_with_parameters(self):
|
|
209
215
|
collection = monitoring.InMemoryMetricCollection('/test')
|
|
210
216
|
scalar = collection.get_scalar(
|
|
@@ -2,8 +2,8 @@ pyglove/__init__.py,sha256=LP1HNk_VVWMHaakX3HZ0NeZ2c4lq2uJaRbalvT8haOg,1352
|
|
|
2
2
|
pyglove/core/__init__.py,sha256=WPTvhQXv63f4-AkYH__RwVKQyr8vHr5e3tGqT2OxRGM,9774
|
|
3
3
|
pyglove/core/logging.py,sha256=zTNLGnWrl6kkjjEjTphQMeNf9FfqFtl1G9VCh2LhnHg,4614
|
|
4
4
|
pyglove/core/logging_test.py,sha256=ioDbmf4S6xQXeyGWihvk6292wfYdldBw_TK1WXvIq5k,1648
|
|
5
|
-
pyglove/core/monitoring.py,sha256=
|
|
6
|
-
pyglove/core/monitoring_test.py,sha256=
|
|
5
|
+
pyglove/core/monitoring.py,sha256=LYGBCtt5LwA1DQP19tGHeydqzDd_Y4NPgI_bT9WA-MY,15536
|
|
6
|
+
pyglove/core/monitoring_test.py,sha256=NqbR7JMahN4mQx6Ub3pKe7eagi3PZzPrTpQn70QCoq4,8757
|
|
7
7
|
pyglove/core/coding/__init__.py,sha256=tuHIg19ZchtkOQbdFVTVLkUpBa5f1eo66XtnKw3lcIU,1645
|
|
8
8
|
pyglove/core/coding/errors.py,sha256=aP3Y4amBzOKdlb5JnESJ3kdoijQXbiBiPDMeA88LNrk,3310
|
|
9
9
|
pyglove/core/coding/errors_test.py,sha256=fwOR8vLiRvLadubsccyE19hLHj-kThlCQt88qmUYk9M,2311
|
|
@@ -218,8 +218,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
|
|
|
218
218
|
pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
|
|
219
219
|
pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
|
|
220
220
|
pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
|
|
221
|
-
pyglove-0.5.0.
|
|
222
|
-
pyglove-0.5.0.
|
|
223
|
-
pyglove-0.5.0.
|
|
224
|
-
pyglove-0.5.0.
|
|
225
|
-
pyglove-0.5.0.
|
|
221
|
+
pyglove-0.5.0.dev202510020810.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
222
|
+
pyglove-0.5.0.dev202510020810.dist-info/METADATA,sha256=lIj3E4MJQcyZRd4KcfcgKagQ4e1tMS-DB9_rNSPxjYc,7089
|
|
223
|
+
pyglove-0.5.0.dev202510020810.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
224
|
+
pyglove-0.5.0.dev202510020810.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
|
|
225
|
+
pyglove-0.5.0.dev202510020810.dist-info/RECORD,,
|
|
File without changes
|
{pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{pyglove-0.5.0.dev202509300811.dist-info → pyglove-0.5.0.dev202510020810.dist-info}/top_level.txt
RENAMED
|
File without changes
|