github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/metrics/report/report_dockerfile/dut-details.R (about)

     1  #!/usr/bin/env Rscript
     2  # Copyright (c) 2018-2021 Intel Corporation
     3  #
     4  # SPDX-License-Identifier: Apache-2.0
     5  
     6  # Display details for the 'Device Under Test', for all data sets being processed.
     7  
     8  suppressMessages(suppressWarnings(library(tidyr)))	# for gather().
     9  library(tibble)
    10  suppressMessages(suppressWarnings(library(plyr)))	# rbind.fill
    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  # A list of all the known results files we might find the information inside.
    17  resultsfiles=c(
    18  	"boot-times.json",
    19  	"memory-footprint.json",
    20  	"memory-footprint-ksm.json",
    21  	"memory-footprint-inside-container.json"
    22  	)
    23  
    24  data=c()
    25  stats=c()
    26  stats_names=c()
    27  
    28  # For each set of results
    29  for (currentdir in resultdirs) {
    30  	count=1
    31  	dirstats=c()
    32  	for (resultsfile in resultsfiles) {
    33  		fname=paste(inputdir, currentdir, resultsfile, sep="/")
    34  		if ( !file.exists(fname)) {
    35  			#warning(paste("Skipping non-existent file: ", fname))
    36  			next
    37  		}
    38  
    39  		# Derive the name from the test result dirname
    40  		datasetname=basename(currentdir)
    41  
    42  		# Import the data
    43  		fdata=fromJSON(fname)
    44  
    45  		if (length(fdata$'kata-env') != 0 ) {
    46  			# We have kata-runtime data
    47  			dirstats=tibble("Run Ver"=as.character(fdata$'kata-env'$Runtime$Version$Semver))
    48  			dirstats=cbind(dirstats, "Run SHA"=as.character(fdata$'kata-env'$Runtime$Version$Commit))
    49  
    50  			pver=as.character(fdata$'kata-env'$Proxy$Version)
    51  			pver=sub("^[[:alpha:][:blank:]-]*", "", pver)
    52  			# uncomment if you want to drop the commit sha as well
    53  			#pver=sub("([[:digit:].]*).*", "\\1", pver)
    54  			dirstats=cbind(dirstats, "Proxy Ver"=pver)
    55  
    56  			# Trim the shim string
    57  			sver=as.character(fdata$'kata-env'$Shim$Version)
    58  			sver=sub("^[[:alpha:][:blank:]-]*", "", sver)
    59  			# uncomment if you want to drop the commit sha as well
    60  			#sver=sub("([[:digit:].]*).*", "\\1", sver)
    61  			dirstats=cbind(dirstats, "Shim Ver"=sver)
    62  
    63  			# Default QEMU ver string is far too long and noisy - trim.
    64  			hver=as.character(fdata$'kata-env'$Hypervisor$Version)
    65  			hver=sub("^[[:alpha:][:blank:]]*", "", hver)
    66  			hver=sub("([[:digit:].]*).*", "\\1", hver)
    67  			dirstats=cbind(dirstats, "Hyper Ver"=hver)
    68  
    69  			iver=as.character(fdata$'kata-env'$Image$Path)
    70  			iver=sub("^[[:alpha:]/-]*", "", iver)
    71  			dirstats=cbind(dirstats, "Image Ver"=iver)
    72  
    73  			kver=as.character(fdata$'kata-env'$Kernel$Path)
    74  			kver=sub("^[[:alpha:]/-]*", "", kver)
    75  			dirstats=cbind(dirstats, "Guest Krnl"=kver)
    76  
    77  			dirstats=cbind(dirstats, "Host arch"=as.character(fdata$'kata-env'$Host$Architecture))
    78  			dirstats=cbind(dirstats, "Host Distro"=as.character(fdata$'kata-env'$Host$Distro$Name))
    79  			dirstats=cbind(dirstats, "Host DistVer"=as.character(fdata$'kata-env'$Host$Distro$Version))
    80  			dirstats=cbind(dirstats, "Host Model"=as.character(fdata$'kata-env'$Host$CPU$Model))
    81  			dirstats=cbind(dirstats, "Host Krnl"=as.character(fdata$'kata-env'$Host$Kernel))
    82  			dirstats=cbind(dirstats, "runtime"=as.character(fdata$test$runtime))
    83  
    84  			break
    85  		} else {
    86  			if (length(fdata$'runc-env') != 0 ) {
    87  				dirstats=tibble("Run Ver"=as.character(fdata$'runc-env'$Version$Semver))
    88  				dirstats=cbind(dirstats, "Run SHA"=as.character(fdata$'runc-env'$Version$Commit))
    89  				dirstats=cbind(dirstats, "runtime"=as.character(fdata$test$runtime))
    90  			} else {
    91  				dirstats=tibble("runtime"="Unknown")
    92  			}
    93  			break
    94  		}
    95  	}
    96  
    97  	if ( length(dirstats) == 0 ) {
    98  		warning(paste("No valid data found for directory ", currentdir))
    99  	}
   100  
   101  	# use plyr rbind.fill so we can combine disparate version info frames
   102  	stats=rbind.fill(stats, dirstats)
   103  	stats_names=rbind(stats_names, datasetname)
   104  }
   105  
   106  rownames(stats) = stats_names
   107  
   108  # Rotate the tibble so we get data dirs as the columns
   109  spun_stats = as_tibble(cbind(What=names(stats), t(stats)))
   110  
   111  # Build us a text table of numerical results
   112  stats_plot = suppressWarnings(ggtexttable(data.frame(spun_stats, check.names=FALSE),
   113  	theme=ttheme(base_size=6),
   114  	rows=NULL
   115  	))
   116  
   117  # It may seem odd doing a grid of 1x1, but it should ensure we get a uniform format and
   118  # layout to match the other charts and tables in the report.
   119  master_plot = grid.arrange(
   120  	stats_plot,
   121  	nrow=1,
   122  	ncol=1 )
   123