Skip to content

Commit 2aaea10

Browse files
committed
Add timing stats for IdString garbage collection
1 parent 1631bf9 commit 2aaea10

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

kernel/driver.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ int main(int argc, char **argv)
709709
total_ns += it.second->runtime_ns + 1;
710710
timedat.insert(make_tuple(it.second->runtime_ns + 1, it.second->call_counter, it.first));
711711
}
712+
timedat.insert(make_tuple(RTLIL::OwningIdString::garbage_collection_ns() + 1,
713+
RTLIL::OwningIdString::garbage_collection_count(), "id_gc"));
712714

713715
if (timing_details)
714716
{

kernel/register.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ void Pass::post_execute(Pass::pre_post_exec_state_t state)
129129
int64_t time_ns = PerformanceTimer::query() - state.begin_ns;
130130
runtime_ns += time_ns;
131131
current_pass = state.parent_pass;
132+
subtract_from_current_runtime_ns(time_ns);
133+
}
134+
135+
void Pass::subtract_from_current_runtime_ns(int64_t time_ns)
136+
{
132137
if (current_pass)
133138
current_pass->runtime_ns -= time_ns;
134139
}

kernel/register.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct Pass
9595
bool experimental_flag = false;
9696
bool internal_flag = false;
9797

98+
static void subtract_from_current_runtime_ns(int64_t time_ns);
99+
98100
void experimental() {
99101
experimental_flag = true;
100102
}

kernel/rtlil.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,12 @@ struct IdStringCollector {
243243
std::unordered_set<int> live;
244244
};
245245

246+
int64_t RTLIL::OwningIdString::gc_ns;
247+
int RTLIL::OwningIdString::gc_count;
248+
246249
void RTLIL::OwningIdString::collect_garbage()
247250
{
251+
int64_t start = PerformanceTimer::query();
248252
#ifndef YOSYS_NO_IDS_REFCNT
249253
IdStringCollector collector;
250254
for (auto &[idx, design] : *RTLIL::Design::get_all_designs()) {
@@ -288,6 +292,10 @@ void RTLIL::OwningIdString::collect_garbage()
288292
it = global_negative_id_prefix_storage_.erase(it);
289293
}
290294
#endif
295+
int64_t time_ns = PerformanceTimer::query() - start;
296+
Pass::subtract_from_current_runtime_ns(time_ns);
297+
gc_ns += time_ns;
298+
++gc_count;
291299
}
292300

293301
dict<std::string, std::string> RTLIL::constpad;

kernel/rtlil.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ struct RTLIL::OwningIdString : public RTLIL::IdString {
576576

577577
// Collect all non-owning references.
578578
static void collect_garbage();
579+
static int64_t garbage_collection_ns() { return gc_ns; }
580+
static int garbage_collection_count() { return gc_count; }
579581

580582
// Used by the ID() macro to create an IdString with no destructor whose string will
581583
// never be released. If ID() creates a closure-static `OwningIdString` then
@@ -587,6 +589,9 @@ struct RTLIL::OwningIdString : public RTLIL::IdString {
587589
return result;
588590
}
589591
private:
592+
static int64_t gc_ns;
593+
static int gc_count;
594+
590595
void get_reference()
591596
{
592597
get_reference(index_);

0 commit comments

Comments
 (0)