ref: f801657f77f3923ec2388c25bdcb036c8019ba89
dir: /prog/kconsole.c/
#include <u.h> #include "dat.h" #include "fns.h" #include "mem.h" #include "libkern/kern.h" #define KLOG_MSGLEN 48 #define KLOG_LOGLEN (sizeof(vlong) + KLOG_MSGLEN) static Queue* kconsoleq; void printinit(void) { kconsoleq = qopen(3 * KLOG_LOGLEN, 0, nil, nil); } void kconsole(void*) { printinit(); vlong *ts; char msg[KLOG_LOGLEN]; while(qread(kconsoleq, msg, KLOG_LOGLEN) > 0) { ts = (vlong*)msg; print("%07lld.%03lld %s\n", *ts / 1000, *ts % 1000, &msg[sizeof(vlong)]); } } Proc* prog_kconsole(void) { Proc* p; p = newprog("kconsole", kconsole, nil, 0, 1024); return p; } int kprint(char *fmt, ...) { va_list arg; char buf[KLOG_LOGLEN]; int n; va_start(arg, fmt); n = vseprint(buf + sizeof(vlong), buf+sizeof(buf), fmt, arg) - buf; va_end(arg); // if(qfull(kconsoleq)) // qflush(kconsoleq); buf[sizeof(vlong) + n - 1] = 0; *((vlong*)buf) = (vlong)(TK2MS(MACHP(0)->ticks)); qwrite(kconsoleq, buf, KLOG_MSGLEN); return n; }