Skip to content

Instantly share code, notes, and snippets.

@noamross
Created November 12, 2012 19:09
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 noamross/4061229 to your computer and use it in GitHub Desktop.
Save noamross/4061229 to your computer and use it in GitHub Desktop.
Another way to view R profiling Data
proftable <- function(file) {
require(plyr)
sample.interval <- as.numeric(strsplit(readLines(file, 1), "=")[[1L]][2L])/1e+06
profdata <- as.matrix(read.table(file, header=FALSE, sep=" ", colClasses="character", skip=1, fill=TRUE, na.strings=""))
total.time <- nrow(profdata)*sample.interval
stacktable <- data.frame(table(aaply(profdata, 1, function(x) paste(rev(na.omit(x)), collapse=" > "))))
names(stacktable) <- c("Stack","PctTime")
stacktable$PctTime <- 100*stacktable$PctTime/nrow(profdata)
stacktable <- stacktable[order(stacktable$PctTime, decreasing=TRUE), c("PctTime", "Stack")]
rownames(stacktable) <- NULL
attr(stacktable, "total.time") <- total.time
print(stacktable, row.names=FALSE, right=FALSE, digits=3)
cat(paste("\nTotal Time:", total.time, "seconds"))
invisible(stacktable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment