powermanager: format seconds into days/hours/minutes/seconds

master
Rob Pilling 2023-04-19 08:58:21 +01:00
parent 9cb21ceb0f
commit 55441d5ef5
1 changed files with 25 additions and 4 deletions

View File

@ -108,7 +108,7 @@ function viewDeferredTable(filename) {
for (var i in rows) { for (var i in rows) {
let c = rows[i]; let c = rows[i];
tableRows += `<tr> tableRows += `<tr>
<td>${(c.time/1000).toFixed(2)}s</td> <td>${timeFormat(c.time)}</td>
<td>${(c.time/sum*100).toFixed(2)}%</td> <td>${(c.time/sum*100).toFixed(2)}%</td>
<td><pre>${c.func}</pre></td>` <td><pre>${c.func}</pre></td>`
} }
@ -118,7 +118,7 @@ function viewDeferredTable(filename) {
var htmlOverview = `<h1>Deferred function calls</h1> var htmlOverview = `<h1>Deferred function calls</h1>
<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>${Math.round((duration)/1000)}s</b>. Timeouts/intervals have run for <b>${Math.round(sum/1000)}s (${(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"> <table class="table table-striped table-hover">
<thead> <thead>
@ -185,7 +185,7 @@ function viewHardwareTable(filename) {
for (var i in rows) { for (var i in rows) {
let c = rows[i]; let c = rows[i];
tableRows += `<tr> tableRows += `<tr>
<td>${(c.time/1000).toFixed(2)}s</td> <td>${timeFormat(c.time)}</td>
<td>${(c.time/duration*100).toFixed(2)}%</td> <td>${(c.time/duration*100).toFixed(2)}%</td>
<td>${c.func}</td>` <td>${c.func}</td>`
} }
@ -194,7 +194,7 @@ function viewHardwareTable(filename) {
var htmlOverview = `<h1>Hardware power</h1> var htmlOverview = `<h1>Hardware power</h1>
<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>
Recorded in a time span of <b>${Math.round(duration/1000)}s</b>. Percentages are calculated from recording time. Recorded in a time span of <b>${timeFormat(duration)}</b>. Percentages are calculated from recording time.
</div> </div>
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
@ -263,6 +263,27 @@ function onInit() {
show(); show();
} }
function timeFormat(time) {
let secs = time / 1000;
if (secs < 60)
return secs.toFixed(2) + "s";
let mins = secs / 60;
secs %= 60;
if (mins < 60)
return mins.toFixed(0) + "m" + secs.toFixed(0) + "s";
let hrs = mins / 60;
mins %= 60;
if (hrs < 24)
return hrs.toFixed(0) + "h" + mins.toFixed(0) + "m" + secs.toFixed(0) + "s";
let days = hrs / 24;
hrs %= 24;
return days.toFixed(0) + "d" + hrs.toFixed(0) + "h" + mins.toFixed(0) + "m" + secs.toFixed(0) + "s";
}
</script> </script>
</body> </body>
</html> </html>