github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/metrics/report/report_dockerfile/lifecycle-time.R (about) 1 #!/usr/bin/env Rscript 2 # Copyright (c) 2018 Intel Corporation 3 # 4 # SPDX-License-Identifier: Apache-2.0 5 6 # Display how long the various phases of a container lifecycle (run, execute, die etc. 7 # take. 8 9 library(ggplot2) # ability to plot nicely. 10 suppressMessages(suppressWarnings(library(tidyr))) # for gather(). 11 # So we can plot multiple graphs 12 library(gridExtra) # together. 13 suppressMessages(suppressWarnings(library(ggpubr))) # for ggtexttable. 14 suppressMessages(library(jsonlite)) # to load the data. 15 16 testnames=c( 17 "boot-times" 18 ) 19 20 data=c() 21 stats=c() 22 rstats=c() 23 rstats_names=c() 24 25 # For each set of results 26 for (currentdir in resultdirs) { 27 count=1 28 dirstats=c() 29 for (testname in testnames) { 30 fname=paste(inputdir, currentdir, testname, '.json', 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 specific name 42 fdata=fdata[[testname]] 43 44 cdata=data.frame(workload=as.numeric(fdata$Results$'to-workload'$Result)) 45 cdata=cbind(cdata, quit=as.numeric(fdata$Results$'to-quit'$Result)) 46 47 cdata=cbind(cdata, tokernel=as.numeric(fdata$Results$'to-kernel'$Result)) 48 cdata=cbind(cdata, inkernel=as.numeric(fdata$Results$'in-kernel'$Result)) 49 cdata=cbind(cdata, total=as.numeric(fdata$Results$'total'$Result)) 50 51 cdata=cbind(cdata, count=seq_len(length(cdata[,"workload"]))) 52 cdata=cbind(cdata, runtime=rep(datasetname, length(cdata[, "workload"]) )) 53 54 # Calculate some stats for total time 55 sdata=data.frame(workload_mean=mean(cdata$workload)) 56 sdata=cbind(sdata, workload_min=min(cdata$workload)) 57 sdata=cbind(sdata, workload_max=max(cdata$workload)) 58 sdata=cbind(sdata, workload_sd=sd(cdata$workload)) 59 sdata=cbind(sdata, workload_cov=((sdata$workload_sd / sdata$workload_mean) * 100)) 60 sdata=cbind(sdata, runtime=datasetname) 61 62 sdata=cbind(sdata, quit_mean = mean(cdata$quit)) 63 sdata=cbind(sdata, quit_min = min(cdata$quit)) 64 sdata=cbind(sdata, quit_max = max(cdata$quit)) 65 sdata=cbind(sdata, quit_sd = sd(cdata$quit)) 66 sdata=cbind(sdata, quit_cov = (sdata$quit_sd / sdata$quit_mean) * 100) 67 68 sdata=cbind(sdata, tokernel_mean = mean(cdata$tokernel)) 69 sdata=cbind(sdata, inkernel_mean = mean(cdata$inkernel)) 70 sdata=cbind(sdata, total_mean = mean(cdata$total)) 71 72 # Store away as a single set 73 data=rbind(data, cdata) 74 stats=rbind(stats, sdata) 75 76 # Store away some stats for the text table 77 dirstats[count]=round(sdata$tokernel_mean, digits=2) 78 count = count + 1 79 dirstats[count]=round(sdata$inkernel_mean, digits=2) 80 count = count + 1 81 dirstats[count]=round(sdata$workload_mean, digits=2) 82 count = count + 1 83 dirstats[count]=round(sdata$quit_mean, digits=2) 84 count = count + 1 85 dirstats[count]=round(sdata$total_mean, digits=2) 86 count = count + 1 87 } 88 rstats=rbind(rstats, dirstats) 89 rstats_names=rbind(rstats_names, datasetname) 90 } 91 92 unts=c("s", "s", "s", "s", "s") 93 rstats=rbind(rstats, unts) 94 rstats_names=rbind(rstats_names, "Units") 95 96 97 # If we have only 2 sets of results, then we can do some more 98 # stats math for the text table 99 if (length(resultdirs) == 2) { 100 # This is a touch hard wired - but we *know* we only have two 101 # datasets... 102 diff=c() 103 for( i in 1:5) { 104 difference = as.double(rstats[2,i]) - as.double(rstats[1,i]) 105 val = 100 * (difference/as.double(rstats[1,i])) 106 diff[i] = paste(round(val, digits=2), "%", sep=" ") 107 } 108 109 rstats=rbind(rstats, diff) 110 rstats_names=rbind(rstats_names, "Diff") 111 } 112 113 rstats=cbind(rstats_names, rstats) 114 115 # Set up the text table headers 116 colnames(rstats)=c("Results", "2k", "ik", "2w", "2q", "tot") 117 118 119 # Build us a text table of numerical results 120 stats_plot = suppressWarnings(ggtexttable(data.frame(rstats, check.names=FALSE), 121 theme=ttheme(base_size=8), 122 rows=NULL 123 )) 124 125 # plot how samples varioed over 'time' 126 line_plot <- ggplot() + 127 geom_line( data=data, aes(count, workload, color=runtime)) + 128 geom_smooth( data=data, aes(count, workload, color=runtime), se=FALSE, method="loess") + 129 xlab("Iteration") + 130 ylab("Time (s)") + 131 ggtitle("Boot to workload", subtitle="First container") + 132 ylim(0, NA) + 133 theme(axis.text.x=element_text(angle=90)) 134 135 boot_boxplot <- ggplot() + 136 geom_boxplot( data=data, aes(runtime, workload, color=runtime), show.legend=FALSE) + 137 ylim(0, NA) + 138 ylab("Time (s)") 139 140 # convert the stats to a long format so we can more easily do a side-by-side barplot 141 longstats <- gather(stats, measure, value, workload_mean, quit_mean, inkernel_mean, tokernel_mean, total_mean) 142 143 bar_plot <- ggplot() + 144 geom_bar( data=longstats, aes(measure, value, fill=runtime), stat="identity", position="dodge", show.legend=FALSE) + 145 xlab("Phase") + 146 ylab("Time (s)") + 147 ggtitle("Lifecycle phase times", subtitle="Mean") + 148 ylim(0, NA) + 149 theme(axis.text.x=element_text(angle=90)) 150 151 master_plot = grid.arrange( 152 bar_plot, 153 line_plot, 154 stats_plot, 155 boot_boxplot, 156 nrow=2, 157 ncol=2 ) 158