|
| 1 | +#### Built-in Metrics #### |
| 2 | + |
| 3 | +struct TimeMetric <: AbstractMetric end |
| 4 | +metric_applies(::TimeMetric, _) = true |
| 5 | +metric_type(::TimeMetric) = UInt64 |
| 6 | +start_metric(::TimeMetric) = time_ns() |
| 7 | +stop_metric(::TimeMetric, last::UInt64) = time_ns() - last |
| 8 | + |
| 9 | +struct ThreadTimeMetric <: AbstractMetric end |
| 10 | +metric_applies(::ThreadTimeMetric, _) = true |
| 11 | +metric_type(::ThreadTimeMetric) = UInt64 |
| 12 | +start_metric(::ThreadTimeMetric) = cputhreadtime() |
| 13 | +stop_metric(::ThreadTimeMetric, last::UInt64) = cputhreadtime() - last |
| 14 | + |
| 15 | +struct CompileTimeMetric <: AbstractMetric end |
| 16 | +metric_applies(::CompileTimeMetric, _) = true |
| 17 | +metric_type(::CompileTimeMetric) = Tuple{UInt64, UInt64} |
| 18 | +function start_metric(::CompileTimeMetric) |
| 19 | + Base.cumulative_compile_timing(true) |
| 20 | + return Base.cumulative_compile_time_ns() |
| 21 | +end |
| 22 | +function stop_metric(::CompileTimeMetric, last::Tuple{UInt64, UInt64}) |
| 23 | + Base.cumulative_compile_timing(false) |
| 24 | + return Base.cumulative_compile_time_ns() .- last |
| 25 | +end |
| 26 | + |
| 27 | +struct AllocMetric <: AbstractMetric end |
| 28 | +metric_applies(::AllocMetric, _) = true |
| 29 | +metric_type(::AllocMetric) = Base.GC_Diff |
| 30 | +start_metric(::AllocMetric) = Base.gc_num() |
| 31 | +stop_metric(::AllocMetric, last::Base.GC_Num) = Base.GC_Diff(Base.gc_num(), last) |
| 32 | + |
| 33 | +struct ResultShapeMetric <: AbstractMetric end |
| 34 | +metric_applies(::ResultShapeMetric, _) = true |
| 35 | +metric_type(::ResultShapeMetric) = Union{Dims, Nothing} |
| 36 | +is_result_metric(::ResultShapeMetric) = true |
| 37 | +result_metric(m::ResultShapeMetric, result) = |
| 38 | + result isa AbstractArray ? size(result) : nothing |
| 39 | + |
| 40 | +struct LoadAverageMetric <: AbstractMetric end |
| 41 | +metric_applies(::LoadAverageMetric, _) = true |
| 42 | +metric_type(::LoadAverageMetric) = Tuple{Float64, Float64, Float64} |
| 43 | +start_metric(::LoadAverageMetric) = nothing |
| 44 | +stop_metric(::LoadAverageMetric, _) = (Sys.loadavg()...,) ./ Sys.CPU_THREADS |
| 45 | + |
| 46 | +# TODO: Useful metrics to add |
| 47 | +# perf performance counters |
| 48 | +# BPF probe-collected metrics |
0 commit comments