Skip to content

Instantly share code, notes, and snippets.

@avadhpatel
Created May 3, 2012 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avadhpatel/2585792 to your computer and use it in GitHub Desktop.
Save avadhpatel/2585792 to your computer and use it in GitHub Desktop.
Small R Script to generate graphs from periodic dump files for Marss and similar tools
#!/usr/bin/env Rscript
# First read in the file
args <- commandArgs(trailingOnly=TRUE)
# print(args)
# Arguments are like following:
# Operation output_file <operation specific #options...>
# Create a png image
create_png <- function(file_name, scale) {
png(paste(file_name, ".png", sep=""), width=10000, height=scale*200, res=scale*20, pointsize=6)
}
create_png_low_res <- function(file_name, scale) {
png(paste(file_name, ".png", sep=""), width=10000, height=scale*200, res=scale*10, pointsize=6)
}
plot_ipc <- function(data, type, coreid, col="red", ylab="IPC", newPlot=TRUE) {
ipc_col <- c()
if (type == "atom") {
ipc_col <- paste("base_machine.atom_", coreid, ".thread_0.commit.ipc",
sep="")
} else if (type == "ooo") {
ipc_col <- paste("base_machine.ooo_", coreid, "_", coreid,
".thread0.commit.ipc", sep="")
}
ipc_data <- data[[ipc_col]]
if (newPlot) {
plot(data$sim_cycle, ipc_data, type="n", xaxs="i", xlab="Cycles",
ylab=ylab,
xaxp=c(0, 10^9, 1000))
}
lines(data$sim_cycle, ipc_data, type="l", col=col, ylab=ylab)
}
# Helper function that returns cache data
get_cache_data <- function(data, cache_name) {
cd <- list()
cd[["read_hit"]] <- data[[paste("base_machine.", cache_name, ".cpurequest.count.hit.read.hit", sep="")]]
cd[["write_hit"]] <- data[[paste("base_machine.", cache_name, ".cpurequest.count.hit.write.hit", sep="")]]
cd[["read_miss"]] <- data[[paste("base_machine.", cache_name, ".cpurequest.count.miss.read", sep="")]]
cd[["write_miss"]] <- data[[paste("base_machine.", cache_name, ".cpurequest.count.miss.write", sep="")]]
cd[["total_hit"]] <- cd$read_hit + cd$write_hit
cd[["total_miss"]] <- cd$read_miss + cd$write_miss
cd[["total_access"]] <- cd$total_hit + cd$total_miss
cd
}
plot_miss_ratio <- function(data, cache_id, coreid, col="red", ylab=NULL,
newPlot=TRUE) {
cd <- get_cache_data(data, paste(cache_id,"_",coreid,sep=""))
miss_ratio <- cd$total_miss/cd$total_access
if (newPlot) {
yrange <- range(0.0, 1.0)
xrange <- range(0, max(data$sim_cycle))
plot(xrange, yrange, type="n", xaxs="i", xlab="Cycles",
ylab="Miss Ratio", xaxp=c(0, 10^9, 1000))
}
lines(data$sim_cycle, miss_ratio, type="l", col=col, ylab=ylab)
}
plot_miss_rate <- function(data, cache_id, coreid, col="red", ylab=NULL,
newPlot=TRUE) {
cd <- get_cache_data(data, paste(cache_id,"_",coreid,sep=""))
if (newPlot) {
plot(data$sim_cycle, cd$total_miss, type="n", xaxs="i", xlab="Cycles",
ylab="Miss Ratio", xaxp=c(0, 10^9, 1000))
}
lines(data$sim_cycle, cd$total_miss, type="l", col=col, ylab=ylab)
}
plot_branchpred <- function(data, type, coreid, col="red", ylab=NULL,
newPlot=TRUE, separateYaxis=FALSE) {
if (type == "ooo") {
pred_hit <- data[[paste("base_machine.ooo_", coreid, "_", coreid,
".thread0.branchpred.summary.correct",
sep="")]]
pred_miss <- data[[paste("base_machine.ooo_", coreid, "_", coreid,
".thread0.branchpred.summary.mispred",
sep="")]]
pred_total <- pred_hit + pred_miss
} else if (type == "atom") {
pred_total <- data[[paste("base_machine.atom_", coreid,
".thread_0.branch_predictions.predictions",
sep="")]]
pred_miss <- data[[paste("base_machine.atom_", coreid,
".thread_0.branch_predictions.fail",
sep="")]]
pred_hit <- pred_total - pred_miss
}
pred_miss_ratio <- pred_miss / pred_total
if (newPlot) {
if (separateYaxis) {
plot(data$sim_cycle, pred_miss_ratio, xaxs="i", type="n",
yaxt="n", xaxt="n", ylab=NULL)
} else {
plot(data$sim_cycle, pred_miss_ratio, xaxs="i", type="n",
xlab="Cycles", xaxp=c(0, 10^9, 1000),
ylab="BP Miss Ratio")
}
}
if (separateYaxis) {
axis(4)
}
lines(data$sim_cycle, pred_miss_ratio, type="l", col=col, ylab=ylab)
}
# IPC of OOO
# Specific Arugments [3..]: data number_of_cores
ipc_ooo <- function(args) {
out_file_name <- args[2]
data <- read.csv(args[3])
num_cores <- strtoi(args[4])
create_png(out_file_name, num_cores)
par(mfrow=c(num_cores,1))
for(i in seq(0, num_cores-1)) {
plot_ipc(data, "ooo", i)
}
}
# IPC of atom
# Specifc Argumments [3..] : data number_of_cores
ipc_atom <- function(args) {
out_file_name <- args[2]
data <- read.csv(args[3])
num_cores <- strtoi(args[4])
create_png(out_file_name, num_cores)
par(mfrow=c(num_cores,1))
for(i in seq(0, num_cores-1)) {
plot_ipc(data, "atom", i)
}
}
# IPC Mix - Merge atom and ooo ipc in one graph
# Specific Arguments [3..] : ooo_data atom_data number_of_cores
ipc_mix <- function(args) {
out_file_name <- args[2]
ooo_data <- read.csv(args[3])
atom_data <- read.csv(args[4])
num_cores <- strtoi(args[5])
create_png(out_file_name, num_cores)
par(mfrow=c(num_cores,1))
colors <- rainbow(2)
for(i in seq(0, num_cores-1)) {
plot_ipc(ooo_data, "ooo", i, col=colors[1])
plot_ipc(atom_data, "atom", i, col=colors[2], newPlot=FALSE)
legend('topleft',lwd=c(1),col=colors,legend=c("atom","ooo"))
}
}
# L1-D Miss Ratio
# Sepcific Arguments [3..] : data number_of_l1d_caches
l1d_l2_miss_ratio <- function(args) {
out_file_name <- args[2]
data <- read.csv(args[3])
num_caches <- strtoi(args[4])
create_png(out_file_name, num_caches)
par(mfrow=c(num_caches,1))
colors = rainbow(2)
for(i in seq(0, num_caches-1)) {
labels <- c(paste("L1-D-",i,sep=""), paste("L2-",i,sep=""))
plot_miss_ratio(data, "L1_D", i, col=colors[1], ylab=labels[1])
plot_miss_ratio(data, "L2", i, col=colors[2], ylab=labels[2],
newPlot=FALSE)
legend('topleft',lwd=c(1),col=colors,legend=labels)
}
}
# L1-D L1-I and L2 Miss Rate
# Sepcific Arguments [3..] : data number_of_l1d_caches
l1_l2_miss_rate <- function(args) {
out_file_name <- args[2]
data <- read.csv(args[3])
num_caches <- strtoi(args[4])
create_png(out_file_name, num_caches)
par(mfrow=c(num_caches,1))
colors = rainbow(3)
for(i in seq(0, num_caches-1)) {
labels <- c(paste("L1-D-",i,sep=""), paste("L1-I-",i,sep=""), paste("L2-",i,sep=""))
plot_miss_rate(data, "L1_D", i, col=colors[1], ylab=labels[1])
plot_miss_rate(data, "L1_I", i, col=colors[2], ylab=labels[2],
newPlot=FALSE)
plot_miss_rate(data, "L2", i, col=colors[3], ylab=labels[3],
newPlot=FALSE)
legend('topleft',lwd=c(1),col=colors,legend=labels)
}
}
# IPC L1-D L1-I and L2 Miss Rate
# Sepcific Arguments [3..] : data number_of_l1d_caches
ipc_l1_l2_miss_rate <- function(args) {
out_file_name <- args[2]
data <- read.csv(args[3])
num_caches <- strtoi(args[4])
create_png_low_res(out_file_name, num_caches*2)
par(mfrow=c(num_caches*2,1))
colors = rainbow(5)
for(i in seq(0, num_caches-1)) {
plot_ipc(data, "ooo", i)
labels <- c(paste("L1-D-",i,sep=""), paste("L1-I-",i,sep=""), paste("L2-",i,sep=""))
plot_miss_rate(data, "L1_D", i, col=colors[1], ylab=labels[1])
plot_miss_rate(data, "L1_I", i, col=colors[2], ylab=labels[2],
newPlot=FALSE)
plot_miss_rate(data, "L2", i, col=colors[3], ylab=labels[3],
newPlot=FALSE)
legend('topleft',lwd=c(1),col=colors,legend=labels)
}
}
do.call(args[1], list(args))
warnings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment