powermanager - Log timestamps while tracing and tweak table visuals

pull/2746/head
Martin Boonk 2023-05-12 00:00:36 +02:00
parent c32f234e95
commit 9d7bb2d9c8
2 changed files with 61 additions and 27 deletions

View File

@ -42,10 +42,10 @@
let logPower = (type, oldstate, state, app) => { let logPower = (type, oldstate, state, app) => {
logFile.write("p," + type + ',' + (oldstate?1:0) + ',' + (state?1:0) + ',' + app + "\n"); logFile.write(Date.now() + ",p," + type + ',' + (oldstate?1:0) + ',' + (state?1:0) + ',' + app + "\n");
}; };
let logDeferred = (type, duration, source) => { let logDeferred = (type, duration, source) => {
logFile.write(type + ',' + duration + ',' + source.replace(/\n/g, " ").replace(/,/g,"") + "\n"); logFile.write(Date.now() + "," + type + ',' + duration + ',' + source.replace(/\n/g, " ").replace(/,/g,"") + "\n");
}; };
let lastPowerOn = {}; let lastPowerOn = {};
@ -162,4 +162,4 @@
if (!charging) chargeStart = undefined; if (!charging) chargeStart = undefined;
}); });
} }
})(); })();

View File

@ -1,6 +1,15 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="../../css/spectre.min.css"> <link rel="stylesheet" href="../../css/spectre.min.css">
<style>
.table_wrapper{
display: block;
overflow-x: auto;
margin-right: 0.8rem;
white-space: nowrap;
}
</style>
</head> </head>
<body> <body>
<div id="content"></div> <div id="content"></div>
@ -119,18 +128,21 @@ function viewDeferredTable(filename) {
<button class="btn btn-primary" id="back" style="float: right;margin-right: 5px;margin-left: 10px;">Back</button> <button class="btn btn-primary" id="back" style="float: right;margin-right: 5px;margin-left: 10px;">Back</button>
<div> <div>
This are functions used in timeouts and intervals and their accumulated execution times. Recorded in a time span of <b>${timeFormat(duration)}</b>. Timeouts/intervals have run for <b>${timeFormat(sum)} (${(sum/duration*100).toFixed(2)}%)</b>. Percentages are calculated from summarized timeout/interval running time. This are functions used in timeouts and intervals and their accumulated execution times. Recorded in a time span of <b>${timeFormat(duration)}</b>. Timeouts/intervals have run for <b>${timeFormat(sum)} (${(sum/duration*100).toFixed(2)}%)</b>. Percentages are calculated from summarized timeout/interval running time.
</div> </div>
<table class="table table-striped table-hover">
<thead> <div class="table_wrapper">
<tr>
<th>Time</th> <table class="table table-striped table-hover">
<th>Percentage</th> <thead>
<th>Function</th> <tr>
</tr> <th>Time</th>
</thead> <th>Percentage</th>
<tbody>\n`; <th>Function</th>
</tr>
</thead>
<tbody>\n`;
htmlOverview += tableRows; htmlOverview += tableRows;
htmlOverview += `</tbody></table>`; htmlOverview += `</tbody></table></div>`;
domContent.innerHTML = htmlOverview; domContent.innerHTML = htmlOverview;
domContent.querySelector("#back").addEventListener("click",event => { domContent.querySelector("#back").addEventListener("click",event => {
show(); show();
@ -234,24 +246,46 @@ function viewDetailsTable(filename) {
Util.hideModal(); Util.hideModal();
var htmlOverview = `<h1>Detailed logging</h1> var htmlOverview = `<h1>Detailed logging</h1>
This is a trace log of all logged power entries, first column denotes the type. p for power, i for interval and t for timeout. Power is logged with old state, new state and calling app if available. Functions are logged with execution duraion and source if available.
<button class="btn btn-primary" id="back" style="float: right;margin-right: 5px;">Back</button> <button class="btn btn-primary" id="back" style="float: right;margin-right: 5px;">Back</button>
<table class="table table-striped table-hover"> <div>
<tbody>\n`; This is a trace log of all logged entries. Power is logged with type, state transition (old &rarr; new) and calling app if available. Functions are logged with execution duraion and source if available.
</div>
<div class="table_wrapper">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Time</th>
<th>Type</th>
<th>Info</th>
</tr>
</thead>
<tbody>\n`;
let rows = data.trim().split("\n"); let rows = data.trim().split("\n");
let firstTimestamp;
for (var row of rows) { for (var row of rows) {
let cols = row.split(","); let cols = row.split(",");
htmlOverview += `<tr> let col = 0;
<td>${cols[0]}</td> if (!firstTimestamp) firstTimestamp = cols[0];
<td>${cols[1]}</td>
<td>${cols[2]}</td> if (cols[1] == "p"){
<td>${cols[3]}</td> cols[1] = "Power";
<td>${cols[4]}</td> htmlOverview += `<tr>
</tr>` <td>${timeFormat(cols[col++]-firstTimestamp)}</td>
<td>${cols[col++]}</td>
<td>${cols[col++]}</br>${cols[col++]} &rarr; ${cols[col++]}</br>${cols[col++]}</td>
</tr>`
} else {
htmlOverview += `<tr>
<td>${timeFormat(cols[col++]-firstTimestamp)}</td>
<td>${cols[col++]=="t"?"Timeout":"Interval"}</td>
<td>${new Number(cols[col++]).toFixed(0)}ms</br><pre>${cols[col++]}</pre></td>
</tr>`
}
} }
htmlOverview += `</tbody></table>`; htmlOverview += `</tbody></table></div>`;
domContent.innerHTML = htmlOverview; domContent.innerHTML = htmlOverview;
domContent.querySelector("#back").addEventListener("click",event => { domContent.querySelector("#back").addEventListener("click",event => {
show(); show();