(
metrics, start, end, delta, cumulative = true, useDuration = false)
| 394 | } |
| 395 | |
| 396 | getAccumulatedTimeMetrics( |
| 397 | metrics, start, end, delta, cumulative = true, useDuration = false) { |
| 398 | // Returns an array of the following format: |
| 399 | // [ [start, acc(metric0, start, start), acc(metric1, ...), ...], |
| 400 | // [start+delta, acc(metric0, start, start+delta), ...], |
| 401 | // [start+delta*2, acc(metric0, start, start+delta*2), ...], |
| 402 | // ... |
| 403 | // ] |
| 404 | if (end <= start) throw `Invalid ranges [${start},${end}]`; |
| 405 | const timespan = end - start; |
| 406 | const kSteps = Math.ceil(timespan / delta); |
| 407 | // To reduce the time spent iterating over the funktions of this script |
| 408 | // we iterate once over all funktions and add the metric changes to each |
| 409 | // timepoint: |
| 410 | // [ [0, 300, ...], [1, 15, ...], [2, 100, ...], [3, 0, ...] ... ] |
| 411 | // In a second step we accumulate all values: |
| 412 | // [ [0, 300, ...], [1, 315, ...], [2, 415, ...], [3, 415, ...] ... ] |
| 413 | // |
| 414 | // To limit the number of data points required in the resulting graphs, |
| 415 | // only the rows for entries with actual changes are created. |
| 416 | |
| 417 | const metricProperties = ["time"]; |
| 418 | metrics.forEach(each => { |
| 419 | metricProperties.push(each + 'Timestamp'); |
| 420 | if (useDuration) metricProperties.push(each + 'Duration'); |
| 421 | }); |
| 422 | // Create a packed {rowTemplate} which is copied later-on. |
| 423 | let indexToTime = (t) => (start + t * delta) / kSecondsToMillis; |
| 424 | let rowTemplate = [indexToTime(0)]; |
| 425 | for (let i = 1; i < metricProperties.length; i++) rowTemplate.push(0.0); |
| 426 | // Create rows with 0-time entry. |
| 427 | let rows = new Array(rowTemplate.slice()); |
| 428 | for (let t = 1; t <= kSteps; t++) rows.push(null); |
| 429 | // Create the real metric's property name on the Funktion object. |
| 430 | // Add the increments of each Funktion's metric to the result. |
| 431 | this.forEach(funktionOrScript => { |
| 432 | // Iterate over the Funktion's metric names, skipping position 0 which |
| 433 | // is the time. |
| 434 | const kMetricIncrement = useDuration ? 2 : 1; |
| 435 | for (let i = 1; i < metricProperties.length; i += kMetricIncrement) { |
| 436 | let timestampPropertyName = metricProperties[i]; |
| 437 | let timestamp = funktionOrScript[timestampPropertyName]; |
| 438 | if (timestamp === undefined) continue; |
| 439 | if (timestamp < start || end < timestamp) continue; |
| 440 | timestamp -= start; |
| 441 | let index = Math.floor(timestamp / delta); |
| 442 | let row = rows[index]; |
| 443 | if (row === null) { |
| 444 | // Add a new row if it didn't exist, |
| 445 | row = rows[index] = rowTemplate.slice(); |
| 446 | // .. add the time offset. |
| 447 | row[0] = indexToTime(index); |
| 448 | } |
| 449 | // Add the metric value. |
| 450 | row[i] += funktionOrScript.getMetricBytes(timestampPropertyName); |
| 451 | if (!useDuration) continue; |
| 452 | let durationPropertyName = metricProperties[i + 1]; |
| 453 | row[i + 1] += funktionOrScript.getMetricDuration(durationPropertyName); |
no test coverage detected