]> git.lizzy.rs Git - rust.git/commitdiff
Moved log method into logger class better than scheduler fixes #2495
authorArkaitz Jimenez <arkaitzj@gmail.com>
Mon, 4 Jun 2012 00:53:24 +0000 (01:53 +0100)
committerArkaitz Jimenez <arkaitzj@gmail.com>
Mon, 4 Jun 2012 00:53:24 +0000 (01:53 +0100)
src/rt/rust_log.cpp
src/rt/rust_log.h
src/rt/rust_sched_loop.cpp
src/rt/rust_sched_loop.h
src/rt/rust_shape.cpp

index 29d35e27c21d82ac14cb4cc8c319f613fe7d436f..774a549fe8b191f34c013aa48b1141386fb68d92 100644 (file)
@@ -89,6 +89,22 @@ append_string(char *buffer, const char *format, ...) {
     return buffer;
 }
 
+void
+rust_log::log(rust_task* task, uint32_t level, char const *fmt, ...) {
+    char buf[BUF_BYTES];
+    va_list args;
+    va_start(args, fmt);
+    int formattedbytes = vsnprintf(buf, sizeof(buf), fmt, args);
+    if( formattedbytes and (unsigned)formattedbytes > BUF_BYTES ){
+        const char truncatedstr[] = "[...]";
+        memcpy( &buf[BUF_BYTES-sizeof(truncatedstr)],
+                truncatedstr,
+                sizeof(truncatedstr));
+    }
+    trace_ln(task, level, buf);
+    va_end(args);
+}
+
 void
 rust_log::trace_ln(char *prefix, char *message) {
     char buffer[BUF_BYTES] = "";
@@ -302,6 +318,7 @@ void update_log_settings(void* crate_map, char* settings) {
     free(buffer);
 }
 
+
 //
 // Local Variables:
 // mode: C++
index c66f65d00ab1ca941f04fc086af446b180373dbe..62824481eb63b882ec511e6b8a8f843293f2cc88 100644 (file)
@@ -23,7 +23,7 @@ const uint32_t log_debug = 3;
     do {                                                        \
         rust_sched_loop* _d_ = sched_loop;                      \
         if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) {     \
-            _d_->log(task, lvl, __VA_ARGS__);                   \
+            _d_->get_log().log(task, lvl, __VA_ARGS__);         \
         }                                                       \
     } while (0)
 
@@ -45,6 +45,7 @@ public:
     rust_log(rust_sched_loop *sched_loop);
     virtual ~rust_log();
 
+    void log(rust_task* task, uint32_t level, char const *fmt, ...);
     void trace_ln(rust_task *task, uint32_t level, char *message);
     void trace_ln(char *prefix, char *message);
     bool is_tracing(uint32_t type_bits);
index 83540cdf6b19bab05368f75dd4edeef9a0ea42d9..e6297ec475c5e6fba31133fc7cc0e8c69897590a 100644 (file)
@@ -49,26 +49,10 @@ rust_sched_loop::activate(rust_task *task) {
     DLOG(this, task, "task has returned");
 }
 
-// FIXME #2495: This logging code doesn't belong in the scheduler
-void
-rust_sched_loop::log(rust_task* task, uint32_t level, char const *fmt, ...) {
-    char buf[BUF_BYTES];
-    va_list args;
-    va_start(args, fmt);
-    int formattedbytes = vsnprintf(buf, sizeof(buf), fmt, args);
-    if( formattedbytes and (unsigned)formattedbytes > BUF_BYTES ){
-        const char truncatedstr[] = "[...]";
-        memcpy( &buf[BUF_BYTES-sizeof(truncatedstr)],
-                truncatedstr,
-                sizeof(truncatedstr));
-    }
-    _log.trace_ln(task, level, buf);
-    va_end(args);
-}
 
 void
 rust_sched_loop::fail() {
-    log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
+    _log.log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
         name, this);
     kernel->fail();
 }
@@ -168,18 +152,18 @@ rust_sched_loop::log_state() {
     if (log_rt_task < log_debug) return;
 
     if (!running_tasks.is_empty()) {
-        log(NULL, log_debug, "running tasks:");
+        _log.log(NULL, log_debug, "running tasks:");
         for (size_t i = 0; i < running_tasks.length(); i++) {
-            log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR,
+            _log.log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR,
                 running_tasks[i]->name,
                 running_tasks[i]);
         }
     }
 
     if (!blocked_tasks.is_empty()) {
-        log(NULL, log_debug, "blocked tasks:");
+        _log.log(NULL, log_debug, "blocked tasks:");
         for (size_t i = 0; i < blocked_tasks.length(); i++) {
-            log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR
+            _log.log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR
                 ", blocked on: 0x%" PRIxPTR " '%s'",
                 blocked_tasks[i]->name, blocked_tasks[i],
                 blocked_tasks[i]->get_cond(),
index 7f60f7e449d163902f1211d58e790aa45f9c1025..f8e52e0498b3e87442d73d79ceef58b650a440e4 100644 (file)
@@ -96,7 +96,6 @@ public:
     // domain.
     rust_sched_loop(rust_scheduler *sched, int id);
     void activate(rust_task *task);
-    void log(rust_task *task, uint32_t level, char const *fmt, ...);
     rust_log & get_log();
     void fail();
 
index c5f6a39b6c8bc36493aca74fc5f9509cc70b7adb..47d1f2bd1ef78ab2689b2fece84416681aa2c65d 100644 (file)
@@ -624,6 +624,6 @@ shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
 
     log.walk();
 
-    task->sched_loop->log(task, level, "%s", ss.str().c_str());
+    task->sched_loop->get_log().log(task, level, "%s", ss.str().c_str());
 }