mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
disable logging
This commit is contained in:
parent
8ee6ad4d96
commit
5ddc97fc3e
4 changed files with 58 additions and 26 deletions
|
@ -2,8 +2,11 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <venti.h>
|
#include <venti.h>
|
||||||
|
|
||||||
|
int ventilogging;
|
||||||
#define log not_the_log_library_call
|
#define log not_the_log_library_call
|
||||||
|
|
||||||
|
static char Eremoved[] = "[removed]";
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{ /* defaults */
|
{ /* defaults */
|
||||||
LogChunkSize = 8192,
|
LogChunkSize = 8192,
|
||||||
|
@ -35,6 +38,9 @@ vtlogopen(char *name, uint size)
|
||||||
char *p;
|
char *p;
|
||||||
VtLog *l, *last;
|
VtLog *l, *last;
|
||||||
|
|
||||||
|
if(!ventilogging)
|
||||||
|
return nil;
|
||||||
|
|
||||||
h = hash(name)%nelem(vl.hash);
|
h = hash(name)%nelem(vl.hash);
|
||||||
qlock(&vl.lk);
|
qlock(&vl.lk);
|
||||||
last = nil;
|
last = nil;
|
||||||
|
@ -65,6 +71,7 @@ vtlogopen(char *name, uint size)
|
||||||
p = (char*)(l->chunk+nc);
|
p = (char*)(l->chunk+nc);
|
||||||
for(i=0; i<nc; i++){
|
for(i=0; i<nc; i++){
|
||||||
l->chunk[i].p = p;
|
l->chunk[i].p = p;
|
||||||
|
l->chunk[i].wp = p;
|
||||||
p += LogChunkSize;
|
p += LogChunkSize;
|
||||||
l->chunk[i].ep = p;
|
l->chunk[i].ep = p;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +81,7 @@ vtlogopen(char *name, uint size)
|
||||||
/* insert */
|
/* insert */
|
||||||
l->next = vl.hash[h];
|
l->next = vl.hash[h];
|
||||||
vl.hash[h] = l;
|
vl.hash[h] = l;
|
||||||
|
l->ref++;
|
||||||
|
|
||||||
l->ref++;
|
l->ref++;
|
||||||
qunlock(&vl.lk);
|
qunlock(&vl.lk);
|
||||||
|
@ -87,9 +95,11 @@ vtlogclose(VtLog *l)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qlock(&vl.lk);
|
qlock(&vl.lk);
|
||||||
if(--l->ref == 0)
|
if(--l->ref == 0){
|
||||||
|
/* must not be in hash table */
|
||||||
|
assert(l->name == Eremoved);
|
||||||
free(l);
|
free(l);
|
||||||
else
|
}else
|
||||||
assert(l->ref > 0);
|
assert(l->ref > 0);
|
||||||
qunlock(&vl.lk);
|
qunlock(&vl.lk);
|
||||||
}
|
}
|
||||||
|
@ -109,6 +119,8 @@ vtlogremove(char *name)
|
||||||
last->next = l->next;
|
last->next = l->next;
|
||||||
else
|
else
|
||||||
vl.hash[h] = l->next;
|
vl.hash[h] = l->next;
|
||||||
|
l->name = Eremoved;
|
||||||
|
l->next = nil;
|
||||||
qunlock(&vl.lk);
|
qunlock(&vl.lk);
|
||||||
vtlogclose(l);
|
vtlogclose(l);
|
||||||
return;
|
return;
|
||||||
|
@ -116,16 +128,35 @@ vtlogremove(char *name)
|
||||||
qunlock(&vl.lk);
|
qunlock(&vl.lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
timefmt(Fmt *fmt)
|
||||||
|
{
|
||||||
|
static uvlong t0;
|
||||||
|
uvlong t;
|
||||||
|
|
||||||
|
if(t0 == 0)
|
||||||
|
t0 = nsec();
|
||||||
|
t = nsec()-t0;
|
||||||
|
return fmtprint(fmt, "T+%d.%04d", (uint)(t/1000000000), (uint)(t%1000000000)/100000);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
vtlogvprint(VtLog *l, char *fmt, va_list arg)
|
vtlogvprint(VtLog *l, char *fmt, va_list arg)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char *p;
|
char *p;
|
||||||
VtLogChunk *c;
|
VtLogChunk *c;
|
||||||
|
static int first = 1;
|
||||||
|
|
||||||
if(l == nil)
|
if(l == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(first){
|
||||||
|
fmtinstall('T', timefmt);
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
qlock(&l->lk);
|
qlock(&l->lk);
|
||||||
c = l->w;
|
c = l->w;
|
||||||
n = c->ep - c->wp;
|
n = c->ep - c->wp;
|
||||||
|
@ -160,8 +191,10 @@ vtlog(char *name, char *fmt, ...)
|
||||||
{
|
{
|
||||||
VtLog *l;
|
VtLog *l;
|
||||||
va_list arg;
|
va_list arg;
|
||||||
|
|
||||||
l = vtlogopen(name, LogSize);
|
l = vtlogopen(name, LogSize);
|
||||||
|
if(l == nil)
|
||||||
|
return;
|
||||||
va_start(arg, fmt);
|
va_start(arg, fmt);
|
||||||
vtlogvprint(l, fmt, arg);
|
vtlogvprint(l, fmt, arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
@ -183,6 +216,5 @@ vtlogdump(int fd, VtLog *l)
|
||||||
c = l->chunk;
|
c = l->chunk;
|
||||||
write(fd, c->p, c->wp-c->p);
|
write(fd, c->p, c->wp-c->p);
|
||||||
}
|
}
|
||||||
vtlogclose(l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ vtrpc(VtConn *z, Packet *p)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uchar tag, buf[2], *top;
|
uchar tag, buf[2], *top;
|
||||||
Rwait *r;
|
Rwait *r, *rr;
|
||||||
|
|
||||||
/* must malloc because stack could be private */
|
/* must malloc because stack could be private */
|
||||||
r = vtmallocz(sizeof(Rwait));
|
r = vtmallocz(sizeof(Rwait));
|
||||||
|
@ -86,16 +86,15 @@ vtrpc(VtConn *z, Packet *p)
|
||||||
muxrpc(z, p);
|
muxrpc(z, p);
|
||||||
}
|
}
|
||||||
z->muxer = 0;
|
z->muxer = 0;
|
||||||
/* if there is anyone else sleeping, wake them to mux */
|
/* if there is anyone else sleeping, wake first unfinished to mux */
|
||||||
if(z->nsleep){
|
if(z->nsleep)
|
||||||
for(i=0; i<256; i++)
|
for(i=0; i<256; i++){
|
||||||
if(z->wait[i] != nil && ((Rwait*)z->wait[i])->sleeping)
|
rr = z->wait[i];
|
||||||
break;
|
if(rr && rr->sleeping && !rr->done){
|
||||||
if(i==256)
|
rwakeup(&rr->r);
|
||||||
fprint(2, "libventi: nsleep botch\n");
|
break;
|
||||||
else
|
}
|
||||||
rwakeup(&((Rwait*)z->wait[i])->r);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = r->p;
|
p = r->p;
|
||||||
|
|
|
@ -10,10 +10,9 @@ static int
|
||||||
_vtsend(VtConn *z, Packet *p)
|
_vtsend(VtConn *z, Packet *p)
|
||||||
{
|
{
|
||||||
IOchunk ioc;
|
IOchunk ioc;
|
||||||
int n;
|
int n, tot;
|
||||||
uchar buf[2];
|
uchar buf[2];
|
||||||
|
|
||||||
|
|
||||||
if(z->state != VtStateConnected) {
|
if(z->state != VtStateConnected) {
|
||||||
werrstr("session not connected");
|
werrstr("session not connected");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -32,18 +31,20 @@ _vtsend(VtConn *z, Packet *p)
|
||||||
ventisendbytes += n+2;
|
ventisendbytes += n+2;
|
||||||
ventisendpackets++;
|
ventisendpackets++;
|
||||||
|
|
||||||
|
tot = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
n = packetfragments(p, &ioc, 1, 0);
|
n = packetfragments(p, &ioc, 1, 0);
|
||||||
if(n == 0)
|
if(n == 0)
|
||||||
break;
|
break;
|
||||||
if(write(z->outfd, ioc.addr, ioc.len) < ioc.len){
|
if(write(z->outfd, ioc.addr, ioc.len) < ioc.len){
|
||||||
vtlog(VtServerLog, "%s: sending packet %p: %r", z->addr, p);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> sending packet %p: %r<br>\n", z->addr, p);
|
||||||
packetfree(p);
|
packetfree(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
packetconsume(p, nil, ioc.len);
|
packetconsume(p, nil, ioc.len);
|
||||||
|
tot += ioc.len;
|
||||||
}
|
}
|
||||||
vtlog(VtServerLog, "%s: sent packet %p", z->addr, p);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> sent packet %p (%d bytes)<br>\n", z->addr, p, tot);
|
||||||
packetfree(p);
|
packetfree(p);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -108,10 +109,10 @@ _vtrecv(VtConn *z)
|
||||||
ventirecvbytes += len;
|
ventirecvbytes += len;
|
||||||
ventirecvpackets++;
|
ventirecvpackets++;
|
||||||
p = packetsplit(p, len);
|
p = packetsplit(p, len);
|
||||||
vtlog(VtServerLog, "%s: read packet %p len %d", z->addr, p, len);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> read packet %p len %d<br>\n", z->addr, p, len);
|
||||||
return p;
|
return p;
|
||||||
Err:
|
Err:
|
||||||
vtlog(VtServerLog, "%s: error reading packet: %r", z->addr);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> error reading packet: %r<br>\n", z->addr);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,12 +142,12 @@ if(first && chattyventi){
|
||||||
while((p = vtrecv(c)) != nil){
|
while((p = vtrecv(c)) != nil){
|
||||||
r = vtmallocz(sizeof(VtReq));
|
r = vtmallocz(sizeof(VtReq));
|
||||||
if(vtfcallunpack(&r->tx, p) < 0){
|
if(vtfcallunpack(&r->tx, p) < 0){
|
||||||
vtlog(VtServerLog, "%s: recv bad packet %p: %r", c->addr, p);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv bad packet %p: %r<br>\n", c->addr, p);
|
||||||
fprint(2, "bad packet on %s: %r\n", sc->dir);
|
fprint(2, "bad packet on %s: %r\n", sc->dir);
|
||||||
packetfree(p);
|
packetfree(p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
vtlog(VtServerLog, "%s: recv packet %p (%F)", c->addr, p, &r->tx);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv packet %p (%F)<br>\n", c->addr, p, &r->tx);
|
||||||
if(chattyventi)
|
if(chattyventi)
|
||||||
fprint(2, "%s <- %F\n", argv0, &r->tx);
|
fprint(2, "%s <- %F\n", argv0, &r->tx);
|
||||||
packetfree(p);
|
packetfree(p);
|
||||||
|
@ -182,7 +182,7 @@ vtgetreq(VtSrv *srv)
|
||||||
VtReq *r;
|
VtReq *r;
|
||||||
|
|
||||||
r = _vtqrecv(srv->q);
|
r = _vtqrecv(srv->q);
|
||||||
vtlog(VtServerLog, "%s: vtgetreq %F\n", ((VtSconn*)r->sc)->c->addr, &r->tx);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> vtgetreq %F<br>\n", ((VtSconn*)r->sc)->c->addr, &r->tx);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,13 +200,13 @@ vtrespond(VtReq *r)
|
||||||
if(chattyventi)
|
if(chattyventi)
|
||||||
fprint(2, "%s -> %F\n", argv0, &r->rx);
|
fprint(2, "%s -> %F\n", argv0, &r->rx);
|
||||||
if((p = vtfcallpack(&r->rx)) == nil){
|
if((p = vtfcallpack(&r->rx)) == nil){
|
||||||
vtlog(VtServerLog, "%s: vtfcallpack %F: %r", sc->c->addr, &r->rx);
|
vtlog(VtServerLog, "%s: vtfcallpack %F: %r<br>\n", sc->c->addr, &r->rx);
|
||||||
fprint(2, "fcallpack on %s: %r\n", sc->dir);
|
fprint(2, "fcallpack on %s: %r\n", sc->dir);
|
||||||
packetfree(p);
|
packetfree(p);
|
||||||
vtfcallclear(&r->rx);
|
vtfcallclear(&r->rx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vtlog(VtServerLog, "%s: send packet %p (%F)", sc->c->addr, p, &r->rx);
|
vtlog(VtServerLog, "<font size=-1>%T %s:</font> send packet %p (%F)<br>\n", sc->c->addr, p, &r->rx);
|
||||||
if(vtsend(sc->c, p) < 0)
|
if(vtsend(sc->c, p) < 0)
|
||||||
fprint(2, "vtsend %F: %r\n", &r->rx);
|
fprint(2, "vtsend %F: %r\n", &r->rx);
|
||||||
scdecref(sc);
|
scdecref(sc);
|
||||||
|
|
Loading…
Reference in a new issue