github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/metrics/report/report_dockerfile/footprint-density.R (about)

     1  #!/usr/bin/env Rscript
     2  # Copyright (c) 2018 Intel Corporation
     3  #
     4  # SPDX-License-Identifier: Apache-2.0
     5  
     6  # Show system memory reduction, and hence container 'density', by analysing the
     7  # scaling footprint data results and the 'system free' memory.
     8  
     9  library(ggplot2)					# ability to plot nicely.
    10  							# So we can plot multiple graphs
    11  library(gridExtra)					# together.
    12  suppressMessages(suppressWarnings(library(ggpubr)))	# for ggtexttable.
    13  suppressMessages(library(jsonlite))			# to load the data.
    14  
    15  testnames=c(
    16  	paste("footprint-busybox.*", test_name_extra, sep=""),
    17  	paste("footprint-mysql.*", test_name_extra, sep=""),
    18  	paste("footprint-elasticsearch.*", test_name_extra, sep="")
    19  )
    20  
    21  data=c()
    22  stats=c()
    23  rstats=c()
    24  rstats_names=c()
    25  
    26  for (currentdir in resultdirs) {
    27  	count=1
    28  	dirstats=c()
    29  	for (testname in testnames) {
    30  		matchdir=paste(inputdir, currentdir, sep="")
    31  		matchfile=paste(testname, '\\.json', sep="")
    32  		files=list.files(matchdir, pattern=matchfile)
    33  		if ( length(files) == 0 ) {
    34  			#warning(paste("Pattern [", matchdir, "/", matchfile, "] matched nothing"))
    35  		}
    36  		for (ffound in files) {
    37  			fname=paste(inputdir, currentdir, ffound, sep="")
    38  			if ( !file.exists(fname)) {
    39  				warning(paste("Skipping non-existent file: ", fname))
    40  				next
    41  			}
    42  
    43  			# Derive the name from the test result dirname
    44  			datasetname=basename(currentdir)
    45  
    46  			# Import the data
    47  			fdata=fromJSON(fname)
    48  			# De-nest the test name specific data
    49  			shortname=substr(ffound, 1, nchar(ffound)-nchar(".json"))
    50  			fdata=fdata[[shortname]]
    51  
    52  			payload=fdata$Config$payload
    53  			testname=paste(datasetname, payload)
    54  
    55  			cdata=data.frame(avail_mb=as.numeric(fdata$Results$system$avail)/(1024*1024))
    56  			cdata=cbind(cdata, avail_decr=as.numeric(fdata$Results$system$avail_decr))
    57  			cdata=cbind(cdata, count=seq_len(length(cdata[, "avail_mb"])))
    58  			cdata=cbind(cdata, testname=rep(testname, length(cdata[, "avail_mb"]) ))
    59  			cdata=cbind(cdata, payload=rep(payload, length(cdata[, "avail_mb"]) ))
    60  			cdata=cbind(cdata, dataset=rep(datasetname, length(cdata[, "avail_mb"]) ))
    61  
    62  			# Gather our statistics
    63  			sdata=data.frame(num_containers=length(cdata[, "avail_mb"]))
    64  			# Pick out the last avail_decr value - which in theory should be
    65  			# the most we have consumed...
    66  			sdata=cbind(sdata, mem_consumed=cdata[, "avail_decr"][length(cdata[, "avail_decr"])])
    67  			sdata=cbind(sdata, avg_bytes_per_c=sdata$mem_consumed / sdata$num_containers)
    68  			sdata=cbind(sdata, runtime=testname)
    69  
    70  			# Store away as a single set
    71  			data=rbind(data, cdata)
    72  			stats=rbind(stats, sdata)
    73  
    74  			s = c(
    75  				"Test"=testname,
    76  				"n"=sdata$num_containers,
    77  				"size"=(sdata$mem_consumed) / 1024,
    78  				"kb/n"=round((sdata$mem_consumed / sdata$num_containers) / 1024, digits=1),
    79  				"n/Gb"= round((1*1024*1024*1024) / (sdata$mem_consumed / sdata$num_containers), digits=1)
    80  			)
    81  
    82  			rstats=rbind(rstats, s)
    83  			count = count + 1
    84  		}
    85  	}
    86  }
    87  
    88  # Set up the text table headers
    89  colnames(rstats)=c("Test", "n", "Tot_Kb", "avg_Kb", "n_per_Gb")
    90  
    91  # Build us a text table of numerical results
    92  stats_plot = suppressWarnings(ggtexttable(data.frame(rstats),
    93  	theme=ttheme(base_size=10),
    94  	rows=NULL
    95  	))
    96  
    97  # plot how samples varioed over  'time'
    98  line_plot <- ggplot() +
    99  	geom_point( data=data, aes(count, avail_mb, group=testname, color=payload, shape=dataset)) +
   100  	geom_line( data=data, aes(count, avail_mb, group=testname, color=payload)) +
   101  	xlab("Containers") +
   102  	ylab("System Avail (Mb)") +
   103  	ggtitle("System Memory free") +
   104  	ylim(0, NA) +
   105  	theme(axis.text.x=element_text(angle=90))
   106  
   107  master_plot = grid.arrange(
   108  	line_plot,
   109  	stats_plot,
   110  	nrow=2,
   111  	ncol=1 )
   112