Skip to content

Commit 02aa70a

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 cfd839a commit 02aa70a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-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

+19-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ tasktrace current_tasktrace() noexcept {
135135
auto main = current_backtrace_tasklocal();
136136

137137
tasktrace::vector_type prev;
138+
tasktrace::vector_resume_points_type prev_resume_points;
138139
size_t hash = 0;
139140
if (local_engine && g_current_context) {
140141
task* tsk = nullptr;
@@ -148,6 +149,7 @@ tasktrace current_tasktrace() noexcept {
148149

149150
while (tsk && prev.size() < prev.max_size()) {
150151
shared_backtrace bt = tsk->get_backtrace();
152+
prev_resume_points.push_back(tsk->get_resume_point());
151153
hash *= 31;
152154
if (bt) {
153155
hash ^= bt->hash();
@@ -161,7 +163,7 @@ tasktrace current_tasktrace() noexcept {
161163
}
162164
}
163165

164-
return tasktrace(std::move(main), std::move(prev), hash, current_scheduling_group());
166+
return tasktrace(std::move(main), std::move(prev), std::move(prev_resume_points), hash, current_scheduling_group());
165167
}
166168

167169
saved_backtrace current_backtrace() noexcept {
@@ -175,6 +177,14 @@ tasktrace::tasktrace(simple_backtrace main, tasktrace::vector_type prev, size_t
175177
, _hash(_main.hash() * 31 ^ prev_hash)
176178
{ }
177179

180+
tasktrace::tasktrace(simple_backtrace main, tasktrace::vector_type prev, vector_resume_points_type prev_resume_points, size_t prev_hash, scheduling_group sg) noexcept
181+
: _main(std::move(main))
182+
, _prev(std::move(prev))
183+
, _prev_resume_points(std::move(prev_resume_points))
184+
, _sg(sg)
185+
, _hash(_main.hash() * 31 ^ prev_hash)
186+
{ }
187+
178188
bool tasktrace::operator==(const tasktrace& o) const noexcept {
179189
return _hash == o._hash && _main == o._main && _prev == o._prev;
180190
}
@@ -203,8 +213,15 @@ auto formatter<seastar::tasktrace>::format(const seastar::tasktrace& b, format_c
203213
-> decltype(ctx.out()) {
204214
auto out = ctx.out();
205215
out = fmt::format_to(out, "{}", b._main);
206-
for (auto&& e : b._prev) {
216+
for(auto i = 0u; i < b._prev.size(); ++i) {
217+
const auto &e = b._prev[i];
218+
auto resume_loc = i < b._prev_resume_points.size() ? b._prev_resume_points[i] : std::source_location{};
219+
207220
out = fmt::format_to(out, "\n --------");
221+
222+
if (resume_loc.file_name()[0] != 0) {
223+
out = fmt::format_to(out, "\n {}:{}:{}", resume_loc.file_name(), resume_loc.line(), resume_loc.column());
224+
}
208225
out = std::visit(seastar::make_visitor(
209226
[&] (const seastar::shared_backtrace& sb) {
210227
return fmt::format_to(out, "\n{}", sb);

0 commit comments

Comments
 (0)