diff options
author | Andrew Kaster <akaster@serenityos.org> | 2023-01-01 22:45:28 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-07 14:51:04 +0100 |
commit | 4e7bdcfeea8db8bae7cd908217983f237cd344ef (patch) | |
tree | d3f633d3c161baf7b7743b72fc289ecec51c8ffd /Userland | |
parent | 88957b42e9c415e87f7223aba618607a37bd774d (diff) | |
download | serenity-4e7bdcfeea8db8bae7cd908217983f237cd344ef.zip |
LibJS: Only start ElapsedTimer for GC metrics when printing is enabled
We don't need to be checking the current time unconditionally when we
only observe the results if we're going to dump the GC stats.
This saves two trips to clock_gettime at the cost of an extra branch.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Heap/Heap.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index a2c95203b6..d8fe220e8b 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/Userland/Libraries/LibJS/Heap/Heap.cpp @@ -96,7 +96,10 @@ void Heap::collect_garbage(CollectionType collection_type, bool print_report) perf_event(PERF_EVENT_SIGNPOST, gc_perf_string_id, global_gc_counter++); #endif - auto collection_measurement_timer = Core::ElapsedTimer::start_new(); + Core::ElapsedTimer collection_measurement_timer; + if (print_report) + collection_measurement_timer.start(); + if (collection_type == CollectionType::CollectGarbage) { if (m_gc_deferrals) { m_should_gc_when_deferral_ends = true; @@ -304,9 +307,8 @@ void Heap::sweep_dead_cells(bool print_report, Core::ElapsedTimer const& measure }); } - int time_spent = measurement_timer.elapsed(); - if (print_report) { + Time const time_spent = measurement_timer.elapsed_time(); size_t live_block_count = 0; for_each_block([&](auto&) { ++live_block_count; @@ -315,7 +317,7 @@ void Heap::sweep_dead_cells(bool print_report, Core::ElapsedTimer const& measure dbgln("Garbage collection report"); dbgln("============================================="); - dbgln(" Time spent: {} ms", time_spent); + dbgln(" Time spent: {} ms", time_spent.to_milliseconds()); dbgln(" Live cells: {} ({} bytes)", live_cells, live_cell_bytes); dbgln("Collected cells: {} ({} bytes)", collected_cells, collected_cell_bytes); dbgln(" Live blocks: {} ({} bytes)", live_block_count, live_block_count * HeapBlock::block_size); |