|
| 1 | +#!/usr/bin/env Rscript |
| 2 | +# Copyright (c) 2019 Intel Corporation |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +# Show pod communication latency |
| 7 | + |
| 8 | +suppressMessages(suppressWarnings(library(ggplot2))) # ability to plot nicely. |
| 9 | +suppressMessages(library(jsonlite)) # to load the data. |
| 10 | +library(tibble) # tibbles for tidy data |
| 11 | + |
| 12 | +testnames=c( |
| 13 | + "k8s-scaling-nc.*" |
| 14 | +) |
| 15 | + |
| 16 | +### For developers: uncomment following variables to run this as is in R |
| 17 | +# resultdirs=c("") |
| 18 | +# inputdir="PATH/TO/DIR/CONTAINING/testnames/WITH/ENDING/SLASH/" |
| 19 | + |
| 20 | +# iterate over every set of results (test run) |
| 21 | +for (currentdir in resultdirs) { |
| 22 | + # For every results file we are interested in evaluating |
| 23 | + for (testname in testnames) { |
| 24 | + matchdir=paste(inputdir, currentdir, sep="") |
| 25 | + matchfile=paste(testname, '\\.json', sep="") |
| 26 | + files=list.files(matchdir, pattern=matchfile) |
| 27 | + |
| 28 | + # For every matching results file |
| 29 | + for (ffound in files) { |
| 30 | + fname=paste(inputdir, currentdir, ffound, sep="") |
| 31 | + if (!file.exists(fname)) { |
| 32 | + warning(paste("Skipping non-existent file: ", fname)) |
| 33 | + next |
| 34 | + } |
| 35 | + |
| 36 | + # Derive the name from the test result dirname |
| 37 | + datasetname=basename(currentdir) |
| 38 | + |
| 39 | + # Import the data |
| 40 | + fdata=fromJSON(fname) |
| 41 | + # De-nest the test name specific data |
| 42 | + shortname=substr(ffound, 1, nchar(ffound)-nchar(".json")) |
| 43 | + fdata=fdata[[shortname]] |
| 44 | + testname=datasetname |
| 45 | + |
| 46 | + # All the data we are looking for comes in BootResults, |
| 47 | + # so pick it out to make referencing easier |
| 48 | + br=fdata$BootResults |
| 49 | + |
| 50 | + ######################################################## |
| 51 | + #### Now extract latency time percentiles (ltp) ######## |
| 52 | + ######################################################## |
| 53 | + ltp=br$latency_time$Percentiles |
| 54 | + # Percentile thresholds, for example [5, 25, 50, 75, 95] |
| 55 | + ltp_perc=ltp[[1]] |
| 56 | + perc_count = length(ltp_perc) |
| 57 | + # Measured times |
| 58 | + ltp_meas=matrix(unlist(ltp[c(2:length(ltp))]), nrow=perc_count) |
| 59 | + # Build latency percentiles tibble with nice headings |
| 60 | + ltpt=tibble(n_pods=br$n_pods$Result[c(2:length(br$n_pods$Result))]) |
| 61 | + for (n in seq(perc_count)) { |
| 62 | + p_title = paste0("p", ltp_perc[n]) |
| 63 | + ltpt[p_title] = ltp_meas[n,] |
| 64 | + } |
| 65 | + # ltpt example: with percentiles [5, 50, 95]: |
| 66 | + # n_pods p5 p50 p95 |
| 67 | + # 100 4 8 10 |
| 68 | + # 200 5 11 15 |
| 69 | + # 300 6 14 19 |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +########## Output pod communication latency page ############## |
| 75 | +ltpp = ggplot(data=ltpt, aes(x=n_pods)) + ylab("Latency (ms)") + xlab("pods") |
| 76 | +# Highlight the middle percentile (usually median) |
| 77 | +# and symmetrically belittle other percentage lines |
| 78 | +perc_mid = floor((perc_count+1)/2) |
| 79 | +perc_maxdist = perc_mid - 1 |
| 80 | +for (n in seq(perc_count)) { |
| 81 | + # The sparser the dots the farther away the line is from the middle |
| 82 | + perc_dist = abs(n-perc_mid) |
| 83 | + if (perc_dist != 0) { |
| 84 | + perc_linetype = paste0(2*(1+perc_maxdist-perc_dist), perc_dist+1) |
| 85 | + } else { |
| 86 | + perc_linetype = "solid" |
| 87 | + } |
| 88 | + ltpp = ltpp + geom_line( |
| 89 | + aes_string(y=names(ltpt)[n+1]), |
| 90 | + alpha=1.0 - 0.4 * (perc_dist/perc_maxdist), |
| 91 | + linetype=perc_linetype, |
| 92 | + color="blue") |
| 93 | +} |
| 94 | + |
| 95 | +cat("\n\nLatency percentiles illustrated in the Figure below: ", paste0(ltp_perc, "\\%"), "\n\n") |
| 96 | + |
| 97 | +page1 = grid.arrange(ltpp, ncol=1) |
| 98 | + |
| 99 | +# pagebreak, as the graphs overflow the page otherwise |
| 100 | +cat("\n\n\\pagebreak\n") |
0 commit comments