Skip to content

Commit

Permalink
Profiler/GPUViz: Stop allocating memory
Browse files Browse the repository at this point in the history
These parsing strings are tiny, less than 64 bytes all the time. Just
stack allocate the buffer. Makes it safer to use during extenuating
circumstances as well, like SIGBUS and SIGSEGV.
  • Loading branch information
Sonicadvance1 committed Jan 28, 2025
1 parent ae69c4d commit 657c275
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions FEXCore/Source/Utils/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ void Shutdown() {
void TraceObject(std::string_view const Format, uint64_t Duration) {
if (TraceFD != -1) {
// Print the duration as something that began negative duration ago
fextl::string Event = fextl::fmt::format("{} (lduration=-{})\n", Format, Duration);
write(TraceFD, Event.c_str(), Event.size());
const auto StringSize = Format.size() + strlen(" (lduration=-)\n") + 22;
auto Event = reinterpret_cast<char*>(alloca(StringSize));
auto Res = ::fmt::format_to_n(Event, StringSize, "{} (lduration=-{})\n", Format, Duration);
write(TraceFD, Event, Res.size);
}
}

void TraceObject(std::string_view const Format) {
if (TraceFD != -1) {
fextl::string Event = fextl::fmt::format("{}\n", Format);
write(TraceFD, Event.data(), Event.size());
const auto StringSize = Format.size() + 1;
auto Event = reinterpret_cast<char*>(alloca(StringSize));
auto Res = ::fmt::format_to_n(Event, StringSize, "{}\n", Format);
write(TraceFD, Event, Res.size);
}
}
} // namespace GPUVis
Expand Down

0 comments on commit 657c275

Please sign in to comment.