Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Add R script for analysing log span timings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie authored and Jordan Mackie committed Mar 11, 2023
1 parent bca36c4 commit 3bc4c7d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/log-analysis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logs.ndjson
plot.png
45 changes: 45 additions & 0 deletions scripts/log-analysis/main.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
library(magrittr)
library(ggplot2)

logs <- jsonlite::stream_in(file("logs.ndjson"), verbose = FALSE)

parse_duration <- function(s) {
n <- as.numeric(substr(s, 1, nchar(s) - 2))
ifelse(endsWith(s, "ms"), n, n / 1000)
}

is_outlier <- function(ms) {
# outliers are greater than 10ms
return(ms > 10)
}

data <- dplyr::bind_rows(
phase = logs$span$name,
file = logs$span$source_name,
duration_ms = parse_duration(logs$fields$time.busy)
) %>%
dplyr::filter(
phase %in% c("parse_cst", "check_module", "generate_javascript")
) %>%
dplyr::mutate(
phase = dplyr::recode(phase,
parse_cst = "Parse",
check_module = "Typecheck",
generate_javascript = "Codegen"
),
outlier = ifelse(is_outlier(duration_ms), file, as.numeric(NA))
)

plot <- ggplot(
data,
aes(
x = factor(phase, levels = c("Parse", "Typecheck", "Codegen")),
y = duration_ms
)
) +
geom_boxplot() +
geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.1, size = 3) +
xlab("Phase") +
ylab("Time (milliseconds)")

ggsave("plot.png", plot = plot)
13 changes: 13 additions & 0 deletions scripts/log-analysis/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let pkgs = import ../../nixpkgs.nix { };
in pkgs.mkShell {
buildInputs = [
(pkgs.rWrapper.override {
packages = with pkgs.rPackages; [
languageserver
jsonlite
dplyr
ggplot2
];
})
];
}

0 comments on commit 3bc4c7d

Please sign in to comment.