feat: add DHAT profiler (#52)

This commit is contained in:
Kevin Caffrey
2023-12-07 15:22:16 -05:00
committed by GitHub
parent 72e1283c11
commit ff6b542114
8 changed files with 404 additions and 5 deletions

View File

@@ -2,10 +2,17 @@ use std::process::{Command, Stdio};
use crate::template::Day;
pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) {
pub fn handle(day: Day, release: bool, time: bool, dhat: bool, submit_part: Option<u8>) {
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];
if release {
if dhat {
cmd_args.extend([
"--profile".to_string(),
"dhat".to_string(),
"--features".to_string(),
"dhat-heap".to_string(),
]);
} else if release {
cmd_args.push("--release".to_string());
}

View File

@@ -52,6 +52,10 @@ macro_rules! solution {
/// The current day.
const DAY: $crate::template::Day = $crate::day!($day);
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() {
use $crate::template::runner::*;
let input = $crate::template::read_file("inputs", DAY);

View File

@@ -31,7 +31,14 @@ fn run_timed<I: Clone, T>(
hook: impl Fn(&T),
) -> (T, Duration, u128) {
let timer = Instant::now();
let result = func(input.clone());
let result = {
let input = input.clone();
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
func(input)
};
let base_time = timer.elapsed();
hook(&result);