Skip to content

Commit 5250b6c

Browse files
chore(profiling): clang-tidy fixes
1 parent efceaad commit 5250b6c

File tree

11 files changed

+50
-31
lines changed

11 files changed

+50
-31
lines changed

ddtrace/internal/datadog/profiling/dd_wrapper/include/sample.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Sample
122122
bool push_absolute_ns(int64_t timestamp_ns);
123123

124124
// Interacts with static Sample state
125-
bool is_timeline_enabled() const;
125+
static bool is_timeline_enabled();
126126
static void set_timeline(bool enabled);
127127

128128
// Pytorch GPU metadata

ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ Datadog::internal::StringArena::reset()
2727
std::string_view
2828
Datadog::internal::StringArena::insert(std::string_view s)
2929
{
30-
auto chunk = &chunks.back();
30+
auto* chunk = &chunks.back();
3131
if ((chunk->capacity() - chunk->size()) < s.size()) {
3232
chunk = &chunks.emplace_back();
3333
chunk->reserve(std::max(s.size(), Datadog::internal::StringArena::DEFAULT_SIZE));
3434
}
35-
int base = chunk->size();
35+
auto base = chunk->size();
3636
chunk->insert(chunk->end(), s.begin(), s.end());
3737
return std::string_view(chunk->data() + base, s.size());
3838
}
@@ -532,7 +532,7 @@ Datadog::Sample::push_monotonic_ns(int64_t _monotonic_ns)
532532

533533
// Get the current monotonic time. Use clock_gettime directly because the standard underspecifies
534534
// which clock is actually used in std::chrono
535-
timespec ts;
535+
timespec ts{ 0, 0 };
536536
clock_gettime(CLOCK_MONOTONIC, &ts);
537537
auto monotonic_ns = static_cast<int64_t>(ts.tv_sec) * 1'000'000'000LL + ts.tv_nsec;
538538

@@ -555,7 +555,7 @@ Datadog::Sample::set_timeline(bool enabled)
555555
}
556556

557557
bool
558-
Datadog::Sample::is_timeline_enabled() const
558+
Datadog::Sample::is_timeline_enabled()
559559
{
560560
return timeline_enabled;
561561
}

ddtrace/internal/datadog/profiling/dd_wrapper/src/static_sample_pool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ std::optional<Sample*>
2424
StaticSamplePool::take_sample()
2525
{
2626
for (std::size_t i = 0; i < CAPACITY; ++i) {
27-
Sample* s = pool[i].exchange(nullptr, std::memory_order_acq_rel);
28-
if (s != nullptr) {
29-
return s;
27+
Sample* string = pool[i].exchange(nullptr, std::memory_order_acq_rel);
28+
if (string != nullptr) {
29+
return string;
3030
}
3131
}
3232
return std::nullopt;

ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Datadog::Uploader::Uploader(std::string_view _output_filename,
2020
: output_filename{ _output_filename }
2121
, ddog_exporter{ _ddog_exporter }
2222
, encoded_profile{ _encoded_profile }
23-
, profiler_stats{ std::move(_stats) }
23+
, profiler_stats{ _stats }
2424
{
2525
// Increment the upload sequence number every time we build an uploader.
2626
// Uploaders are use-once-and-destroy.

ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader_builder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Datadog::UploaderBuilder::build()
181181
return errmsg;
182182
}
183183

184-
auto ddog_exporter = &res.ok;
184+
auto* ddog_exporter = &res.ok;
185185

186186
auto set_timeout_result = ddog_prof_Exporter_set_timeout(ddog_exporter, max_timeout_ms);
187187
if (set_timeout_result.tag == DDOG_VOID_RESULT_ERR) {
@@ -226,6 +226,6 @@ Datadog::UploaderBuilder::build()
226226
// This was necessary to avoid double-free from calling ddog_prof_Exporter_drop()
227227
// in the destructor of Uploader. See comments in uploader.hpp for more details.
228228
return std::variant<Datadog::Uploader, std::string>{
229-
std::in_place_type<Datadog::Uploader>, output_filename, *ddog_exporter, encoded.ok, std::move(stats)
229+
std::in_place_type<Datadog::Uploader>, output_filename, *ddog_exporter, encoded.ok, stats
230230
};
231231
}

ddtrace/internal/datadog/profiling/stack/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set_target_properties(
3939
include(FetchContent)
4040
include(AnalysisFunc)
4141
include(FindCppcheck)
42+
include(FindClangtidy)
4243

4344
find_package(Python3 COMPONENTS Interpreter Development)
4445

@@ -71,6 +72,9 @@ add_cppcheck_target(
7172
SRC
7273
${CMAKE_CURRENT_SOURCE_DIR}/src)
7374

75+
# Static analysis
76+
add_clangtidy_target(${EXTENSION_NAME})
77+
7478
# Never build with native unwinding, since this is not currently used
7579
target_compile_definitions(${EXTENSION_NAME} PRIVATE UNWIND_NATIVE_DISABLE)
7680

ddtrace/internal/datadog/profiling/stack/echion/echion/frame.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class Frame
4949

5050
struct _location
5151
{
52-
int line = 0;
53-
int line_end = 0;
54-
int column = 0;
55-
int column_end = 0;
52+
unsigned line = 0;
53+
unsigned line_end = 0;
54+
unsigned column = 0;
55+
unsigned column_end = 0;
5656
} location;
5757

5858
#if PY_VERSION_HEX >= 0x030b0000

ddtrace/internal/datadog/profiling/stack/echion/echion/render.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ class RendererInterface
3434

3535
// If a renderer has its own caching mechanism for frames, this can be used
3636
// to store frame information.
37-
virtual void
38-
frame(uintptr_t key, uintptr_t filename, uintptr_t name, int line, int line_end, int column, int column_end) = 0;
37+
virtual void frame(uintptr_t key,
38+
uintptr_t filename,
39+
uintptr_t name,
40+
unsigned line,
41+
unsigned line_end,
42+
unsigned column,
43+
unsigned column_end) = 0;
3944

4045
// Refers to the frame stored using the renderer's frame function
4146
virtual void frame_ref(uintptr_t key) = 0;
@@ -94,12 +99,12 @@ class NullRenderer : public RendererInterface
9499
bool is_valid() override { return true; }
95100
void header() override {}
96101
void metadata(const std::string&, const std::string&) override {}
97-
void frame(uintptr_t, uintptr_t, uintptr_t, int, int, int, int) override {}
98-
void frame_ref(uintptr_t) override {}
102+
void frame(uintptr_t, uintptr_t, uintptr_t, unsigned, unsigned, unsigned, unsigned) override {}
103+
void frame_ref(uintptr_t) override{}
99104
void frame_kernel(const std::string&) override {}
100105

101106
void string(uintptr_t, const std::string&) override {}
102-
void string_ref(uintptr_t) override {}
107+
void string_ref(uintptr_t) override{}
103108
void render_message(std::string_view) override {}
104109
void render_thread_begin(PyThreadState*, std::string_view, microsecond_t, uintptr_t, unsigned long) override {}
105110
void render_task_begin(std::string, bool) override {}
@@ -150,7 +155,13 @@ class Renderer
150155

151156
void string(uintptr_t key, const std::string& value) { getActiveRenderer()->string(key, value); }
152157

153-
void frame(uintptr_t key, uintptr_t filename, uintptr_t name, int line, int line_end, int column, int column_end)
158+
void frame(uintptr_t key,
159+
uintptr_t filename,
160+
uintptr_t name,
161+
unsigned line,
162+
unsigned line_end,
163+
unsigned column,
164+
unsigned column_end)
154165
{
155166
getActiveRenderer()->frame(key, filename, name, line, line_end, column, column_end);
156167
}

ddtrace/internal/datadog/profiling/stack/include/stack_renderer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class StackRenderer : public RendererInterface
3939
void close() override {}
4040
void header() override {}
4141
void metadata(const std::string&, const std::string&) override {}
42-
void frame(uintptr_t, uintptr_t, uintptr_t, int, int, int, int) override {};
43-
void frame_ref(uintptr_t) override{};
42+
void frame(uintptr_t, uintptr_t, uintptr_t, unsigned, unsigned, unsigned, unsigned) override {};
43+
void frame_ref(uintptr_t) override {};
4444
void frame_kernel(const std::string&) override {};
4545
void string(uintptr_t, const std::string&) override {};
46-
void string_ref(uintptr_t) override{};
46+
void string_ref(uintptr_t) override {};
4747

4848
virtual void render_message(std::string_view msg) override;
4949
virtual void render_thread_begin(PyThreadState* tstate,

ddtrace/internal/datadog/profiling/stack/src/echion/danger.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ safe_memcpy(void* dst, const void* src, size_t n)
148148
safe_memcpy_return_t chunk = std::min(rem, std::min(to_src_pg, to_dst_pg));
149149

150150
// Optional early probe to fault before entering large memcpy
151-
(void)*reinterpret_cast<volatile const uint8_t*>(s);
151+
(void)*static_cast<volatile const uint8_t*>(s);
152152

153153
// If this faults, we'll siglongjmp back to the sigsetjmp above.
154154
(void)memcpy(d, s, static_cast<size_t>(chunk));

0 commit comments

Comments
 (0)