github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/metrics/report/report_dockerfile/network-cpu.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 "cpu-information" 16 ) 17 18 resultsfilesshort=c( 19 "CPU" 20 ) 21 22 data=c() 23 rstats=c() 24 rstats_rows=c() 25 rstats_cols=c() 26 27 Gdenom = (1000.0 * 1000.0 * 1000.0) 28 29 # For each set of results 30 for (currentdir in resultdirs) { 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$ips=fdata$Results$"instructions per cycle"$Result 50 fdata$Gcycles=fdata$Results$cycles$Result / Gdenom 51 fdata$Ginstructions=fdata$Results$instructions$Result / Gdenom 52 fdata$variant=rep(datasetvariant, length(fdata$Result) ) 53 fdata$Runtime=rep(datasetname, length(fdata$Result) ) 54 55 # Store away the bits we need 56 data=rbind(data, data.frame( 57 Result=fdata$ips, 58 Type="ips", 59 Runtime=fdata$Runtime, 60 variant=fdata$variant ) ) 61 data=rbind(data, data.frame( 62 Result=fdata$Gcycles, 63 Type="Gcycles", 64 Runtime=fdata$Runtime, 65 variant=fdata$variant ) ) 66 data=rbind(data, data.frame( 67 Result=fdata$Ginstructions, 68 Type="Ginstr", 69 Runtime=fdata$Runtime, 70 variant=fdata$variant ) ) 71 72 # Store away some stats for the text table 73 dirstats=rbind(dirstats, round(fdata$ips, digits=2) ) 74 dirstats=rbind(dirstats, round(fdata$Gcycles, digits=2) ) 75 dirstats=rbind(dirstats, round(fdata$Ginstructions, digits=2) ) 76 } 77 rstats=cbind(rstats, dirstats) 78 rstats_cols=append(rstats_cols, datasetname) 79 } 80 81 rstats_rows=c("IPS", "GCycles", "GInstr") 82 83 unts=c("Ins/Cyc", "G", "G") 84 rstats=cbind(rstats, unts) 85 rstats_cols=append(rstats_cols, "Units") 86 87 # If we have only 2 sets of results, then we can do some more 88 # stats math for the text table 89 if (length(resultdirs) == 2) { 90 # This is a touch hard wired - but we *know* we only have two 91 # datasets... 92 diff=c() 93 for (n in 1:3) { 94 difference = (as.double(rstats[n,2]) - as.double(rstats[n,1])) 95 val = 100 * (difference/as.double(rstats[n,1])) 96 diff=rbind(diff, round(val, digits=2)) 97 } 98 rstats=cbind(rstats, diff) 99 rstats_cols=append(rstats_cols, "Diff %") 100 } 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=rstats_rows, cols=rstats_cols 106 )) 107 108 # plot how samples varioed over 'time' 109 ipsdata <- subset(data, Type %in% c("ips")) 110 ips_plot <- ggplot() + 111 geom_bar(data=ipsdata, aes(Type, Result, fill=Runtime), stat="identity", position="dodge") + 112 xlab("Measure") + 113 ylab("IPS") + 114 ggtitle("Instructions Per Cycle") + 115 ylim(0, NA) + 116 theme(axis.text.x=element_text(angle=90)) 117 118 cycdata <- subset(data, Type %in% c("Gcycles", "Ginstr")) 119 cycles_plot <- ggplot() + 120 geom_bar(data=cycdata, aes(Type, Result, fill=Runtime), stat="identity", position="dodge", show.legend=FALSE) + 121 xlab("Measure") + 122 ylab("Count (G)") + 123 ggtitle("Cycles and Instructions") + 124 ylim(0, NA) + 125 theme(axis.text.x=element_text(angle=90)) 126 127 master_plot = grid.arrange( 128 ips_plot, 129 cycles_plot, 130 stats_plot, 131 nrow=2, 132 ncol=2 ) 133