Skip to content

Commit 11fdb8b

Browse files
perf(profiling): do slightly less work when possible (#15025)
## Description This PR updates a small part of the logic in the Profiler / Stack V2 to only fetch the `filename_str` if we are going to use it (which may not be the case if we are pushing a "Task name frame". ## Risks As far as I can tell, this is a functional no-op as it is effectively only deferring the declaration (and populating) of a variable – `filename_str` – to later in the code.
1 parent c1a6758 commit 11fdb8b

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

ddtrace/internal/datadog/profiling/stack_v2/src/stack_renderer.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,17 @@ StackRenderer::render_frame(Frame& frame)
129129
// some defaults.
130130
static constexpr std::string_view missing_filename = "<unknown file>";
131131
static constexpr std::string_view missing_name = "<unknown function>";
132-
std::string_view filename_str;
133-
std::string_view name_str;
134132

135-
auto maybe_filename_str = string_table.lookup(frame.filename);
136-
if (maybe_filename_str) {
137-
filename_str = maybe_filename_str->get();
138-
} else {
139-
filename_str = missing_filename;
140-
}
133+
auto line = frame.location.line;
141134

135+
std::string_view name_str;
142136
auto maybe_name_str = string_table.lookup(frame.name);
143137
if (maybe_name_str) {
144138
name_str = maybe_name_str->get();
145139
} else {
146140
name_str = missing_name;
147141
}
148142

149-
auto line = frame.location.line;
150-
151143
// DEV: Echion pushes a dummy frame containing task name, and its line
152144
// number is set to 0.
153145
if (line == 0) {
@@ -159,6 +151,14 @@ StackRenderer::render_frame(Frame& frame)
159151
return;
160152
}
161153

154+
std::string_view filename_str;
155+
auto maybe_filename_str = string_table.lookup(frame.filename);
156+
if (maybe_filename_str) {
157+
filename_str = maybe_filename_str->get();
158+
} else {
159+
filename_str = missing_filename;
160+
}
161+
162162
ddup_push_frame(sample, name_str, filename_str, 0, line);
163163
}
164164

ddtrace/internal/datadog/profiling/stack_v2/src/stack_v2.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include "sampler.hpp"
44
#include "thread_span_links.hpp"
55

6-
#include <mutex>
7-
#include <unordered_map>
8-
96
using namespace Datadog;
107

118
static PyObject*

ddtrace/internal/datadog/profiling/stack_v2/src/thread_span_links.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "thread_span_links.hpp"
22

3-
#include <iostream>
43
#include <mutex>
54
#include <optional>
65
#include <stdint.h>

0 commit comments

Comments
 (0)