From 2f02a03ae85294356f4e1988330e7faf83d6a436 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Sun, 26 May 2024 14:11:50 -0400 Subject: [PATCH] Add time zone to start and end time in metadata Prior to this we were including a naive datetime, which did not include enough information to allow it to be localized if a report was viewed on a machine with a different time zone than the one it was generated on. Signed-off-by: Matt Wozniski --- news/611.bugfix.rst | 1 + src/memray/_memray.pyx | 2 +- tests/integration/test_tracking.py | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 news/611.bugfix.rst diff --git a/news/611.bugfix.rst b/news/611.bugfix.rst new file mode 100644 index 0000000000..83cdc9e81a --- /dev/null +++ b/news/611.bugfix.rst @@ -0,0 +1 @@ +Correctly localize the start and end time in the "Stats" modal when an HTML report was generated on a different machine than the one it is being displayed on. diff --git a/src/memray/_memray.pyx b/src/memray/_memray.pyx index 9db72791b6..4c78733370 100644 --- a/src/memray/_memray.pyx +++ b/src/memray/_memray.pyx @@ -735,7 +735,7 @@ def print_greenlet_warning(): cdef millis_to_dt(millis): return datetime.fromtimestamp(millis // 1000).replace( - microsecond=millis % 1000 * 1000) + microsecond=millis % 1000 * 1000).astimezone() cdef _create_metadata(header, peak_memory): diff --git a/tests/integration/test_tracking.py b/tests/integration/test_tracking.py index 0cb71cea00..dbd0d5cfb6 100644 --- a/tests/integration/test_tracking.py +++ b/tests/integration/test_tracking.py @@ -1539,11 +1539,11 @@ def test_get_header(self, monkeypatch, tmpdir): monkeypatch.setattr(sys, "argv", ["python", "-m", "pytest"]) with run_without_tracer(): - start_time = datetime.datetime.now() + start_time = datetime.datetime.now().astimezone() with Tracker(output): for _ in range(100): allocator.valloc(1024) - end_time = datetime.datetime.now() + end_time = datetime.datetime.now().astimezone() reader = FileReader(output) n_records = len(list(reader.get_allocation_records())) @@ -1570,11 +1570,11 @@ def test_get_header_after_snapshot(self, monkeypatch, tmpdir): # WHEN monkeypatch.setattr(sys, "argv", ["python", "-m", "pytest"]) - start_time = datetime.datetime.now() + start_time = datetime.datetime.now().astimezone() with Tracker(output): for _ in range(100): allocator.valloc(1024) - end_time = datetime.datetime.now() + end_time = datetime.datetime.now().astimezone() reader = FileReader(output) peak, *_ = list(reader.get_high_watermark_allocation_records())