Skip to content

Commit

Permalink
Rollback added line numbers and file names feature (open #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemklevtsov committed Jul 28, 2016
1 parent b529650 commit 3036916
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 59 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Type: Package
Title: An Alternative Display Profiling Data as Tree Structure
Description: An alternative data structure for the profiling information
generated by Rprof().
Version: 0.2.0
Version: 0.1.1
Author: Artem Kelvtsov [aut, cre]
Maintainer: Artem Kelvtsov <[email protected]>
URL: https://github.com/artemklevtsov/prof.tree
Expand Down
5 changes: 0 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# prof.tree 0.2.0

- Added file names and line numbers for the line profiling.
- Improved print results.

# prof.tree 0.1.0

* Initial release.
14 changes: 2 additions & 12 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ parse_log <- function(filename) {
metadata <- get_prof_info(proflog[1L])
proflog <- proflog[-1L]
calls <- unique(proflog, fromLast = TRUE)
if (metadata$line.profiling) {
ind <- grep("#File ", calls, fixed = TRUE)
fnames <- sub("#File \\d+: ?", "", calls[ind])
calls <- calls[-ind]
tmp <- strsplit(gsub(".*(\\d#\\d).*", "\\1", calls), "#", fixed = TRUE)
tmp <- lapply(tmp, as.integer)
fnums <- vapply(tmp, .subset2, 1L, FUN.VALUE = 1L)
files <- fnames[fnums]
lines <- vapply(tmp, .subset2, 2L, FUN.VALUE = 1L)
}
if (metadata$line.profiling)
calls <- calls[!grepl("#File ", calls, fixed = TRUE)]
real.time <- tabulate(match(proflog, calls)) * metadata$interval
total.time <- sum(real.time)
pct.time <- real.time / total.time
Expand All @@ -28,8 +20,6 @@ parse_log <- function(filename) {
calls <- lapply(strsplit(calls, split = " ", fixed = TRUE), rev)
calls <- vapply(calls, function(x) paste(c(" \u00B0", x), collapse = "/"), character(1L))
res <- list(pathString = calls, real = real.time, percent = pct.time)
if (metadata$line.profiling)
res <- append(res, list(file = files, line = lines))
class(res) <- "data.frame"
attr(res, "row.names") <- .set_row_names(length(calls))
res
Expand Down
14 changes: 2 additions & 12 deletions R/prof-tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ prof.tree <- function(filename = "Rprof.out") {
traversal = "post-order", filterFun = isNotLeaf)
tree$Do(function(node) node$env <- get_envname(node$name), filterFun = isNotRoot)
tree$Do(function(node) node$name <- sprintf("`%s`", node$name), filterFun = isNotRoot)
if ("line" %in% tree$fieldsAll) {
tree$Do(function(node) node$file <- node$parent$file,
traversal = "pre-order", filterFun = function(node) is.null(node$file))
tree$Do(function(node) node$line <- node$parent$line,
traversal = "pre-order", filterFun = function(node) is.null(node$line))
}
SetFormat(tree, "percent", function(x) FormatPercent(x, digits = 1))
class(tree) <- c("ProfTree", class(tree))
return(tree)
Expand All @@ -42,10 +36,6 @@ prof.tree <- function(filename = "Rprof.out") {
#' @export
#'
print.ProfTree <- function(x, limit = 25, ...) {
if ("line" %in% x$fieldsAll)
NextMethod("print", x, "real", "percent", "env", "file", "line",
pruneMethod = "dist", limit = limit)
else
NextMethod("print", x, "real", "percent", "env",
pruneMethod = "dist", limit = limit)
NextMethod("print", x, "real", "percent", "env",
pruneMethod = "dist", limit = limit)
}
23 changes: 0 additions & 23 deletions tests/testthat/test-lines.R

This file was deleted.

6 changes: 0 additions & 6 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ test_that("Print contains", {
expect_output(print(tree), " \u00B0")
expect_output(print(tree), "100.0 %")
})

test_that("Print contains", {
tree <- prof.tree("logs/Rprof-line.out")
expect_output(print(tree), "file")
expect_output(print(tree), "line")
})

0 comments on commit 3036916

Please sign in to comment.