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

     1  #!/usr/bin/env Rscript
     2  # Copyright (c) 2018 Intel Corporation
     3  #
     4  # SPDX-License-Identifier: Apache-2.0
     5  
     6  # Analyse the runtime component memory footprint data.
     7  
     8  library(ggplot2)					# ability to plot nicely.
     9  							# So we can plot multiple graphs
    10  library(gridExtra)					# together.
    11  suppressMessages(suppressWarnings(library(ggpubr)))	# for ggtexttable.
    12  suppressMessages(library(jsonlite))			# to load the data.
    13  
    14  testnames=c(
    15  	"memory-footprint",
    16  	"memory-footprint-ksm"
    17  )
    18  
    19  resultsfilesshort=c(
    20  	"noKSM",
    21  	"KSM"
    22  )
    23  
    24  data=c()
    25  rstats=c()
    26  rstats_names=c()
    27  
    28  # For each set of results
    29  for (currentdir in resultdirs) {
    30  	count=1
    31  	dirstats=c()
    32  	# For the two different types of memory footprint measures
    33  	for (testname in testnames) {
    34  		# R seems not to like double path slashes '//' ?
    35  		fname=paste(inputdir, currentdir, testname, '.json', sep="")
    36  		if ( !file.exists(fname)) {
    37  			warning(paste("Skipping non-existent file: ", fname))
    38  			next
    39  		}
    40  
    41  		# Derive the name from the test result dirname
    42  		datasetname=basename(currentdir)
    43  		datasetvariant=resultsfilesshort[count]
    44  
    45  		# Import the data
    46  		fdata=fromJSON(fname)
    47  		fdata=fdata[[testname]]
    48  		# Copy the average result into a shorter, more accesible name
    49  		fdata$Result=fdata$Results$average$Result
    50  		fdata$variant=rep(datasetvariant, length(fdata$Result) )
    51  		fdata$Runtime=rep(datasetname, length(fdata$Result) )
    52  		fdata$Count=seq_len(length(fdata$Result))
    53  
    54  		# Calculate some stats
    55  		fdata.mean = mean(fdata$Result)
    56  		fdata.min = min(fdata$Result)
    57  		fdata.max = max(fdata$Result)
    58  		fdata.sd = sd(fdata$Result)
    59  		fdata.cov = (fdata.sd / fdata.mean) * 100
    60  
    61  		# Store away the bits we need
    62  		data=rbind(data, data.frame(
    63  			Result=fdata$Result,
    64  			Count=fdata$Count,
    65  			Runtime=fdata$Runtime,
    66  			variant=fdata$variant ) )
    67  
    68  		# Store away some stats for the text table
    69  		dirstats[count]=round(fdata.mean, digits=2)
    70  
    71  		count = count + 1
    72  	}
    73  	rstats=rbind(rstats, dirstats)
    74  	rstats_names=rbind(rstats_names, datasetname)
    75  }
    76  
    77  rstats=cbind(rstats_names, rstats)
    78  unts=rep("Kb", length(resultdirs))
    79  
    80  # If we have only 2 sets of results, then we can do some more
    81  # stats math for the text table
    82  if (length(resultdirs) == 2) {
    83  	# This is a touch hard wired - but we *know* we only have two
    84  	# datasets...
    85  	diff=c("diff")
    86  	difference = (as.double(rstats[2,2]) - as.double(rstats[1,2]))
    87  	val = 100 * (difference/as.double(rstats[1,2]))
    88  	diff[2] = round(val, digits=2)
    89  	difference = (as.double(rstats[2,3]) - as.double(rstats[1,3]))
    90  	val = 100 * (difference/as.double(rstats[1,3]))
    91  	diff[3] = round(val, digits=2)
    92  	rstats=rbind(rstats, diff)
    93  
    94  	unts[3]="%"
    95  }
    96  
    97  rstats=cbind(rstats, unts)
    98  
    99  # Set up the text table headers
   100  colnames(rstats)=c("Results", resultsfilesshort, "Units")
   101  
   102  # Build us a text table of numerical results
   103  stats_plot = suppressWarnings(ggtexttable(data.frame(rstats),
   104  	theme=ttheme(base_size=10),
   105  	rows=NULL
   106  	))
   107  
   108  # plot how samples varioed over  'time'
   109  point_plot <- ggplot() +
   110  	geom_point( data=data, aes(Runtime, Result, color=variant), position=position_dodge(0.1)) +
   111  	xlab("Dataset") +
   112  	ylab("Size (Kb)") +
   113  	ggtitle("Average PSS footprint", subtitle="per container") +
   114  	ylim(0, NA) +
   115  	theme(axis.text.x=element_text(angle=90))
   116  
   117  master_plot = grid.arrange(
   118  	point_plot,
   119  	stats_plot,
   120  	nrow=1,
   121  	ncol=2 )
   122