Skip to content

Commit

Permalink
benchmarks/iperf: fix JS TypeError when parsing iperf result with an …
Browse files Browse the repository at this point in the history
…error (#3925) (#3928)

Co-authored-by: Leo Huang <[email protected]>
  • Loading branch information
cbreezier and Leo Huang authored Oct 25, 2024
1 parent fbd16d3 commit 5c4e3a2
Showing 1 changed file with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,55 @@ function result_to_html(elements) {

// only if test did already run
if ('result' in element) {
var result = element.result,
start = result.start,
connection = start.connected[0],
intervals = result.intervals,
test_end = result.end,
cpu = test_end.cpu_utilization_percent;
// General
output += "<h3>{{ lang._('General') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Time') }}", start.timestamp.time);
output += table_tr_kv("{{ lang._('Duration') }}", start.test_start.duration);
output += table_tr_kv("{{ lang._('Block Size') }}", start.test_start.blksize);
output += "</table>";
// connection
output += "<h3>{{ lang._('Connection') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Local Host') }}", connection.local_host);
output += table_tr_kv("{{ lang._('Local Port') }}", connection.local_port);
output += table_tr_kv("{{ lang._('Remote Host') }}", connection.remote_host);
output += table_tr_kv("{{ lang._('Remote Port') }}", connection.remote_port);
output += "</table>";
// CPU Usage
output += "<h3>{{ lang._('CPU Usage') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Host Total') }}", cpu.host_total.toFixed(2));
output += table_tr_kv("{{ lang._('Host User') }}", cpu.host_user.toFixed(2));
output += table_tr_kv("{{ lang._('Host System') }}", cpu.host_system.toFixed(2));
output += table_tr_kv("{{ lang._('Remote Total') }}", cpu.remote_total.toFixed(2));
output += table_tr_kv("{{ lang._('Remote User') }}", cpu.remote_user.toFixed(2));
output += table_tr_kv("{{ lang._('Remote System') }}", cpu.remote_system.toFixed(2));
output += "</table>";
// performance data
output += "<h3>{{ lang._('Performance Data') }}</h3>";
output += '<table class="table table-striped">';
var fields = ['sum_sent', 'sum_received'];
output += table_tr_transpose("{{ lang._('Start') }}","start",fields, test_end);
output += table_tr_transpose("{{ lang._('End') }}","end",fields, test_end);
output += table_tr_transpose("{{ lang._('Seconds') }}","seconds",fields, test_end);
output += table_tr_transpose("{{ lang._('Bytes') }}","bytes",fields, test_end);
output += table_tr_transpose("{{ lang._('Bits Per Second') }}","bits_per_second",fields, test_end);
output += "</table>";
var result = element.result;
if ('error' in result) {
// We can't assume that any other fields exist when there's an error
output += "<h3>{{ lang._('Error') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Error message') }}", result.error);
output += "</table>";
} else {
var start = result.start,
connection = start.connected[0],
intervals = result.intervals,
test_end = result.end,
cpu = test_end.cpu_utilization_percent;
// General
output += "<h3>{{ lang._('General') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Time') }}", start.timestamp.time);
output += table_tr_kv("{{ lang._('Duration') }}", start.test_start.duration);
output += table_tr_kv("{{ lang._('Block Size') }}", start.test_start.blksize);
output += "</table>";
// connection
output += "<h3>{{ lang._('Connection') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Local Host') }}", connection.local_host);
output += table_tr_kv("{{ lang._('Local Port') }}", connection.local_port);
output += table_tr_kv("{{ lang._('Remote Host') }}", connection.remote_host);
output += table_tr_kv("{{ lang._('Remote Port') }}", connection.remote_port);
output += "</table>";
// CPU Usage
output += "<h3>{{ lang._('CPU Usage') }}</h3>";
output += '<table class="table table-striped">';
output += table_tr_kv("{{ lang._('Host Total') }}", cpu.host_total.toFixed(2));
output += table_tr_kv("{{ lang._('Host User') }}", cpu.host_user.toFixed(2));
output += table_tr_kv("{{ lang._('Host System') }}", cpu.host_system.toFixed(2));
output += table_tr_kv("{{ lang._('Remote Total') }}", cpu.remote_total.toFixed(2));
output += table_tr_kv("{{ lang._('Remote User') }}", cpu.remote_user.toFixed(2));
output += table_tr_kv("{{ lang._('Remote System') }}", cpu.remote_system.toFixed(2));
output += "</table>";
// performance data
output += "<h3>{{ lang._('Performance Data') }}</h3>";
output += '<table class="table table-striped">';
var fields = ['sum_sent', 'sum_received'];
output += table_tr_transpose("{{ lang._('Start') }}","start",fields, test_end);
output += table_tr_transpose("{{ lang._('End') }}","end",fields, test_end);
output += table_tr_transpose("{{ lang._('Seconds') }}","seconds",fields, test_end);
output += table_tr_transpose("{{ lang._('Bytes') }}","bytes",fields, test_end);
output += table_tr_transpose("{{ lang._('Bits Per Second') }}","bits_per_second",fields, test_end);
output += "</table>";
}
}
}
$('#resultcontainer').html(output);
Expand Down

0 comments on commit 5c4e3a2

Please sign in to comment.