Skip to content

Commit

Permalink
Merge pull request #613 from etmc/profile_all
Browse files Browse the repository at this point in the history
in the hmc_mk2 profiler, optionally include all timings
  • Loading branch information
kostrzewa authored Apr 24, 2024
2 parents a8ff50b + 1287c06 commit 9593476
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 5 additions & 2 deletions profiling/hmc_mk2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ We use tmLQCD hierarchical timer and R to produce profiles of the HMC.
To collect time informations from the file `example_log.out` type

```
Rscript make_profile.R example_log.out output_basename
Rscript make_profile.R example_log.out output_basename [1]
```

The `make_profile.R` file will first collect the data and then render the file `profile.Rmd`, producing the pdf `output_basename.pdf`, where the name of the output file is set by passing something for `output_basename`.
The last argument is optional and controls whether all timings are included in per-monomial plots and tables or timings below 5% of the total time spent in that particular step (heatbath, derivative, acceptance) for a particular monomial are grouped under the "other" category.

Alternatively, the script can also be sourced from an interactive session:
Alternatively, the script can also be sourced from an interactive session where the variables `infile` and `outbase` must be defined.

```
> infile <- "example_log.out"
> outbase <- "output_basename"
> source("make_profile.R")
```

The treshold for whether all timings should be shown on a per-monomial basis is set via the `other_threshold` variable and defaults to `0.05`.

The R packages `dplyr, data.tree, stringr` and `microseq` are required for data extraction and the R packages `ggplot2, knitr, treemap, hadron` and `kableExtra` are required to render the Rmarkdown document.

The raw and summary data are stored in `profile.RData` which includes the `data.tree` structure `t_tree` which nicely shows the call stack.
12 changes: 10 additions & 2 deletions profiling/hmc_mk2/make_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require(hadron)
require(kableExtra)
require(ggrepel)


# wrapper around base::gregexpr which makes it operate like microseq::gregexpr
extract_gregexpr <- function(pattern, text, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE){
lst <- base::gregexpr(pattern, text, ignore.case, perl, fixed, useBytes)
Expand Down Expand Up @@ -40,16 +41,23 @@ extract_type <- function(str){
if(!interactive()){
args <- commandArgs(trailingOnly=TRUE)
if( length(args) < 2 ){
stop("usage: Rscript make_profile.R <logfile> <output_basename>")
stop("usage: Rscript make_profile.R <logfile> <output_basename> [include_all]")
}
infile <<- args[1]
outbase <<- args[2]
if( length(args) == 3 ){
other_threshold <<- 0.0
}
} else {
if( !exists("infile") | !exists("outbase") ){
stop("When not running interactively, the variables 'infile' (path to log file) and 'outbase' (basename for ouput files) must be defined!")
}
}

if( !exists("other_threshold") ){
other_threshold <<- 0.05
}

stopifnot(file.exists(infile))

# extract the different monomial names from the log file
Expand Down Expand Up @@ -120,7 +128,7 @@ t_tree <- data.tree::as.Node(sum_data)
# and logical unit
sum_data_per_mon <- dplyr::filter(sum_data, nchar(monomial) > 0) %>%
dplyr::group_by(monomial, type, level) %>%
dplyr::mutate(name = ifelse(time < 0.05 * sum(time),
dplyr::mutate(name = ifelse(time < other_threshold * sum(time),
'other', name)) %>%
dplyr::group_by(monomial, type, level, name) %>%
dplyr::summarise(time = sum(time),
Expand Down
6 changes: 3 additions & 3 deletions profiling/hmc_mk2/profile.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cat("\\par\n")
cat(knitr::kable(dplyr::select(hb_acc_der_data, monomial, type, time, prop, invocations, unit_time),
format = 'latex',
booktabs = TRUE,
digits = 1,
digits = 3,
linesep = "") %>%
kableExtra::kable_styling(latex_options = "striped")
)
Expand Down Expand Up @@ -156,7 +156,7 @@ if(!all(is.na(quda_data))){
cat(knitr::kable(plot_data,
format = 'latex',
booktabs = TRUE,
digits = 1,
digits = 2,
caption = sprintf("Time spent in different QUDA regions. Compare to total time of %.1f seconds.",
total_time)) %>%
kableExtra::kable_styling(latex_options = "striped")
Expand Down Expand Up @@ -197,7 +197,7 @@ for( mon in total_per_mon$monomial ){
cat(knitr::kable(dplyr::select(type_data, level, name, time, prop, invocations, unit_time),
format = 'latex',
booktabs = TRUE,
digits = 1,
digits = 3,
linesep = "",
caption = sprintf("%s %s", mon, tp) ) %>%
kable_styling(latex_options = "HOLD_position") %>%
Expand Down

0 comments on commit 9593476

Please sign in to comment.