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

[PERF] Use std::call_once to arrange timer record stop #344

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,12 @@ struct TimerRecord {

std::string name;
TimerRecord *parent;
std::once_flag once;
tbb::concurrent_vector<TimerRecord *> children;
i64 start;
i64 end;
i64 user;
i64 sys;
bool stopped = false;
};

void
Expand Down
16 changes: 7 additions & 9 deletions perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ TimerRecord::TimerRecord(std::string name, TimerRecord *parent)
}

void TimerRecord::stop() {
if (stopped)
return;
stopped = true;
std::call_once(once, [&]() {
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);

struct rusage usage;
getrusage(RUSAGE_SELF, &usage);

end = now_nsec();
user = to_nsec(usage.ru_utime) - user;
sys = to_nsec(usage.ru_stime) - sys;
end = now_nsec();
user = to_nsec(usage.ru_utime) - user;
sys = to_nsec(usage.ru_stime) - sys;
});
}

static void print_rec(TimerRecord &rec, i64 indent) {
Expand Down