better diagnostics

This commit is contained in:
Mark Nadal 2020-02-12 09:19:18 -08:00
parent 4aadd43248
commit 35414daa20
3 changed files with 18 additions and 10 deletions

4
gun.js
View File

@ -2155,7 +2155,7 @@
dup_track(id).via = peer;
mesh.leap = null; // warning! mesh.leap could be buggy.
//if(LOG && !msg.nts && (ST = (console.STAT.hd = +new Date) - S) > 9){ opt.log(S, ST, 'msg', msg['#'], JSON.stringify(console.STAT)) }
if(LOG && !msg.nts && (ST = (console.STAT.hd = +new Date) - S) > 9){ opt.log(S, ST, 'msg', msg['#']); if(ST > 5000){ try{ var m = Type.obj.to(msg, {put: Object.keys(msg.put||{})}); require('./lib/email').send({text: ""+ST+"ms "+JSON.stringify(msg)+" | "+JSON.stringify(console.STAT), from: "mark@gun.eco", to: "mark@gun.eco", subject: "GUN MSG"}, noop); }catch(e){} } } // this is ONLY turned on if ENV CONFIGS have email/password to send out from.
if(LOG && !msg.nts && (ST = (console.STAT.hd = +new Date) - S) > 9){ opt.log(S, ST, 'msg', msg['#']); if(ST > 2000){ try{ var m = Type.obj.to(msg, {put: Object.keys(msg.put||{})}); require('./lib/email').send({text: ""+ST+"ms "+JSON.stringify(msg)+" | "+JSON.stringify(console.STAT), from: "mark@gun.eco", to: "mark@gun.eco", subject: "GUN MSG"}, noop); }catch(e){} } } // this is ONLY turned on if ENV CONFIGS have email/password to send out from.
return;
}
@ -2221,7 +2221,7 @@
peer.batch = '['; // TODO: Prevent double JSON!
var S, ST; LOG && (S = +new Date);
setTimeout(function(){
LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, '0ms TO', peer.id);
LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, '0ms TO', id, peer.id);
flush(peer);
}, opt.gap);
send(raw, peer);

View File

@ -86,7 +86,8 @@
var q = s.q || [], i = 0, ack;
var S = +new Date;
while(ack = q[i++]){ ack(err, ok) }
LOG && opt.log(S, +new Date - S, 'rad acks', q.length, ename(s.file));
LOG && opt.log(S, +new Date - S, 'rad acks', ename(s.file));
LOG && opt.log(S, q.length, 'rad acks #', ename(s.file));
}
r.find(key, s.find);
}
@ -271,7 +272,7 @@
LOG && opt.log(S, +new Date - S, 'read disk', JSON.stringify(file), ++RPC, 'total all parses.');
delete Q[file];
LOG && opt.log(S, q.length, "read queue #");
if((p.err = err) || (p.not = !data)){ map(q, p.ack); return }
if((p.err = err) || (p.not = !data)){ p.map(q, p.ack); return }
if('string' !== typeof data){
try{
if(opt.pack <= data.length){
@ -280,7 +281,7 @@
data = data.toString(); // If it crashes, it crashes here. How!?? We check size first!
}
}catch(e){ p.err = e }
if(p.err){ map(q, p.ack); return }
if(p.err){ p.map(q, p.ack); return }
}
info.parsed = data.length;
LOG && (S = +new Date);
@ -289,17 +290,25 @@
var json = JSON.parse(data); // TODO: this caused a out-of-memory crash!
p.disk.$ = json;
LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, 'rad parsed JSON');
map(q, p.ack);
p.map(q, p.ack);
return;
}catch(e){ tmp = e }
if('{' === data[0]){
p.err = tmp || "JSON error!";
map(q, p.ack);
p.map(q, p.ack);
return;
}
}
p.radec(err, data);
}
p.map = function(q){
var i = 0, ack;
var S = +new Date;
var err = p.err, data = p.not? u : p.disk;
while(ack = q[i++]){ ack(err, data, info) }
LOG && opt.log(S, +new Date - S, 'rad packs', ename(s.file));
LOG && opt.log(S, q.length, 'rad packs #', ename(s.file));
}
p.ack = function(cb){
if(!cb){ return }
if(p.err || p.not){
@ -313,7 +322,7 @@
var tmp = p.split(data), pre = [], i, k, v;
if(!tmp || 0 !== tmp[1]){
p.err = "File '"+file+"' does not have root radix! ";
map(q, p.ack);
p.map(q, p.ack);
return;
}
while(tmp){
@ -334,7 +343,7 @@
tmp = p.split(tmp[2]);
}
LOG && opt.log(S, +new Date - S, 'parsed RAD');
map(q, p.ack);
p.map(q, p.ack);
};
p.split = function(t){
if(!t){ return }

View File

@ -18,7 +18,6 @@ Gun.on('create', function(root){
tmp = soul+esc+key; // soul+key; // be nice to move away from escaping
var S = (console.STAT||'').rp = +new Date;
dare(tmp, {':': val, '>': state}, function(err, ok){
LOG && Gun.log(S, +new Date - S, 'put2');
if(msg.ack){ msg.ack(err, ok || 1) } return; // REVISE THIS IN FUTURE!!!
if(err){ root.on('in', {'@': id, err: err}); return }
root.on('in', {'@': id, ok: ok});