Skip to content

Commit

Permalink
Add time zone to start and end time in metadata
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
godlygeek committed May 29, 2024
1 parent ba30497 commit 2f02a03
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/611.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/memray/_memray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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())
Expand Down

0 comments on commit 2f02a03

Please sign in to comment.