Skip to content

Commit dad3007

Browse files
committed
Moved log method into logger class better than scheduler fixes #2495
1 parent 0ecf20c commit dad3007

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

src/rt/rust_log.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ append_string(char *buffer, const char *format, ...) {
8989
return buffer;
9090
}
9191

92+
void
93+
rust_log::log(rust_task* task, uint32_t level, char const *fmt, ...) {
94+
char buf[BUF_BYTES];
95+
va_list args;
96+
va_start(args, fmt);
97+
int formattedbytes = vsnprintf(buf, sizeof(buf), fmt, args);
98+
if( formattedbytes and (unsigned)formattedbytes > BUF_BYTES ){
99+
const char truncatedstr[] = "[...]";
100+
memcpy( &buf[BUF_BYTES-sizeof(truncatedstr)],
101+
truncatedstr,
102+
sizeof(truncatedstr));
103+
}
104+
trace_ln(task, level, buf);
105+
va_end(args);
106+
}
107+
92108
void
93109
rust_log::trace_ln(char *prefix, char *message) {
94110
char buffer[BUF_BYTES] = "";
@@ -302,6 +318,7 @@ void update_log_settings(void* crate_map, char* settings) {
302318
free(buffer);
303319
}
304320

321+
305322
//
306323
// Local Variables:
307324
// mode: C++

src/rt/rust_log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const uint32_t log_debug = 3;
2323
do { \
2424
rust_sched_loop* _d_ = sched_loop; \
2525
if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) { \
26-
_d_->log(task, lvl, __VA_ARGS__); \
26+
_d_->get_log().log(task, lvl, __VA_ARGS__); \
2727
} \
2828
} while (0)
2929

@@ -45,6 +45,7 @@ class rust_log {
4545
rust_log(rust_sched_loop *sched_loop);
4646
virtual ~rust_log();
4747

48+
void log(rust_task* task, uint32_t level, char const *fmt, ...);
4849
void trace_ln(rust_task *task, uint32_t level, char *message);
4950
void trace_ln(char *prefix, char *message);
5051
bool is_tracing(uint32_t type_bits);

src/rt/rust_sched_loop.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,10 @@ rust_sched_loop::activate(rust_task *task) {
4949
DLOG(this, task, "task has returned");
5050
}
5151

52-
// FIXME #2495: This logging code doesn't belong in the scheduler
53-
void
54-
rust_sched_loop::log(rust_task* task, uint32_t level, char const *fmt, ...) {
55-
char buf[BUF_BYTES];
56-
va_list args;
57-
va_start(args, fmt);
58-
int formattedbytes = vsnprintf(buf, sizeof(buf), fmt, args);
59-
if( formattedbytes and (unsigned)formattedbytes > BUF_BYTES ){
60-
const char truncatedstr[] = "[...]";
61-
memcpy( &buf[BUF_BYTES-sizeof(truncatedstr)],
62-
truncatedstr,
63-
sizeof(truncatedstr));
64-
}
65-
_log.trace_ln(task, level, buf);
66-
va_end(args);
67-
}
6852

6953
void
7054
rust_sched_loop::fail() {
71-
log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
55+
_log.log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
7256
name, this);
7357
kernel->fail();
7458
}
@@ -168,18 +152,18 @@ rust_sched_loop::log_state() {
168152
if (log_rt_task < log_debug) return;
169153

170154
if (!running_tasks.is_empty()) {
171-
log(NULL, log_debug, "running tasks:");
155+
_log.log(NULL, log_debug, "running tasks:");
172156
for (size_t i = 0; i < running_tasks.length(); i++) {
173-
log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR,
157+
_log.log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR,
174158
running_tasks[i]->name,
175159
running_tasks[i]);
176160
}
177161
}
178162

179163
if (!blocked_tasks.is_empty()) {
180-
log(NULL, log_debug, "blocked tasks:");
164+
_log.log(NULL, log_debug, "blocked tasks:");
181165
for (size_t i = 0; i < blocked_tasks.length(); i++) {
182-
log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR
166+
_log.log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR
183167
", blocked on: 0x%" PRIxPTR " '%s'",
184168
blocked_tasks[i]->name, blocked_tasks[i],
185169
blocked_tasks[i]->get_cond(),

src/rt/rust_sched_loop.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ struct rust_sched_loop
9696
// domain.
9797
rust_sched_loop(rust_scheduler *sched, int id);
9898
void activate(rust_task *task);
99-
void log(rust_task *task, uint32_t level, char const *fmt, ...);
10099
rust_log & get_log();
101100
void fail();
102101

src/rt/rust_shape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,6 @@ shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
624624

625625
log.walk();
626626

627-
task->sched_loop->log(task, level, "%s", ss.str().c_str());
627+
task->sched_loop->get_log().log(task, level, "%s", ss.str().c_str());
628628
}
629629

0 commit comments

Comments
 (0)