Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone on stats modal #611

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/memray/reporters/assets/flamegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function main() {
window.addEventListener("popstate", handleFragments);
window.addEventListener("resize", debounced(onResize));

let statsStartTime = document.getElementById("stats-start-time");
let statsEndTime = document.getElementById("stats-end-time");
statsStartTime.textContent = new Date(statsStartTime.innerText);
statsEndTime.textContent = new Date(statsEndTime.innerText);
// Enable tooltips
$('[data-toggle-second="tooltip"]').tooltip();
$('[data-toggle="tooltip"]').tooltip();
Expand Down
2 changes: 1 addition & 1 deletion src/memray/reporters/templates/assets/flamegraph.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/memray/reporters/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ <h5 class="modal-title" id="statsModalLabel">Memray run stats</h5>
</div>
<div class="modal-body">
Command line: <code>{{ metadata.command_line }}</code><br>
Start time: {{ metadata.start_time }}<br>
End time: {{ metadata.end_time }}<br>
Start time: <span id="stats-start-time"> {{ metadata.start_time }}</span><br>
End time: <span id="stats-end-time"> {{ metadata.end_time }}</span><br>
Total number of allocations: {{ metadata.total_allocations }}<br>
Total number of frames seen: {{ metadata.total_frames }}<br>
Peak memory usage: {{ metadata.peak_memory | filesizeformat(true) }}<br>
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
Loading