Skip to content

Commit 08d3c8a

Browse files
author
Radosław Cybulski
committed
Update backtrace with source locations of resume points
Add resume point locations to `tasktrace` object. Update `formatter::format` to print source location of next resume alone with task type.
1 parent 706bd36 commit 08d3c8a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Diff for: include/seastar/util/backtrace.hh

+3
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,17 @@ class tasktrace {
139139
public:
140140
using entry = std::variant<shared_backtrace, task_entry>;
141141
using vector_type = boost::container::static_vector<entry, 16>;
142+
using vector_resume_points_type = boost::container::static_vector<std::source_location, 16>;
142143
private:
143144
simple_backtrace _main;
144145
vector_type _prev;
146+
vector_resume_points_type _prev_resume_points;
145147
scheduling_group _sg;
146148
size_t _hash;
147149
public:
148150
tasktrace() = default;
149151
tasktrace(simple_backtrace main, vector_type prev, size_t prev_hash, scheduling_group sg) noexcept;
152+
tasktrace(simple_backtrace main, vector_type prev, vector_resume_points_type prev_resume_points, size_t prev_hash, scheduling_group sg) noexcept;
150153
tasktrace(const tasktrace&) = default;
151154
tasktrace& operator=(const tasktrace&) = default;
152155
~tasktrace();

Diff for: src/util/backtrace.cc

+20-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module;
3030
#include <cerrno>
3131
#include <cstring>
3232
#include <iostream>
33+
#include <source_location>
3334
#include <variant>
3435
#include <vector>
3536
#include <boost/container/static_vector.hpp>
@@ -135,6 +136,7 @@ tasktrace current_tasktrace() noexcept {
135136
auto main = current_backtrace_tasklocal();
136137

137138
tasktrace::vector_type prev;
139+
tasktrace::vector_resume_points_type prev_resume_points;
138140
size_t hash = 0;
139141
if (local_engine && g_current_context) {
140142
task* tsk = nullptr;
@@ -148,6 +150,7 @@ tasktrace current_tasktrace() noexcept {
148150

149151
while (tsk && prev.size() < prev.max_size()) {
150152
shared_backtrace bt = tsk->get_backtrace();
153+
prev_resume_points.push_back(tsk->get_resume_point());
151154
hash *= 31;
152155
if (bt) {
153156
hash ^= bt->hash();
@@ -161,7 +164,7 @@ tasktrace current_tasktrace() noexcept {
161164
}
162165
}
163166

164-
return tasktrace(std::move(main), std::move(prev), hash, current_scheduling_group());
167+
return tasktrace(std::move(main), std::move(prev), std::move(prev_resume_points), hash, current_scheduling_group());
165168
}
166169

167170
saved_backtrace current_backtrace() noexcept {
@@ -175,6 +178,14 @@ tasktrace::tasktrace(simple_backtrace main, tasktrace::vector_type prev, size_t
175178
, _hash(_main.hash() * 31 ^ prev_hash)
176179
{ }
177180

181+
tasktrace::tasktrace(simple_backtrace main, tasktrace::vector_type prev, vector_resume_points_type prev_resume_points, size_t prev_hash, scheduling_group sg) noexcept
182+
: _main(std::move(main))
183+
, _prev(std::move(prev))
184+
, _prev_resume_points(std::move(prev_resume_points))
185+
, _sg(sg)
186+
, _hash(_main.hash() * 31 ^ prev_hash)
187+
{ }
188+
178189
bool tasktrace::operator==(const tasktrace& o) const noexcept {
179190
return _hash == o._hash && _main == o._main && _prev == o._prev;
180191
}
@@ -203,8 +214,15 @@ auto formatter<seastar::tasktrace>::format(const seastar::tasktrace& b, format_c
203214
-> decltype(ctx.out()) {
204215
auto out = ctx.out();
205216
out = fmt::format_to(out, "{}", b._main);
206-
for (auto&& e : b._prev) {
217+
for(auto i = 0u; i < b._prev.size(); ++i) {
218+
const auto &e = b._prev[i];
219+
auto resume_loc = i < b._prev_resume_points.size() ? b._prev_resume_points[i] : std::source_location{};
220+
207221
out = fmt::format_to(out, "\n --------");
222+
223+
if (resume_loc.file_name()[0] != 0) {
224+
out = fmt::format_to(out, "\n {}:{}:{}", resume_loc.file_name(), resume_loc.line(), resume_loc.column());
225+
}
208226
out = std::visit(seastar::make_visitor(
209227
[&] (const seastar::shared_backtrace& sb) {
210228
return fmt::format_to(out, "\n{}", sb);

0 commit comments

Comments
 (0)