$ show Riskified/timeasure
Timeasure is a Ruby gem for transparent method-level runtime profiling in production environments. It uses `Module#prepend` and metaprogramming to intercept method calls on classes and modules that include the `Timeasure` module, measuring execution time via `Process.clock_gettime(Process::CLOCK_MONOTONIC)`. The gem provides class macros (`tracked_instance_methods`, `tracked_class_methods`, etc.) to declare which methods to profile, and a direct `Timeasure.measure` interface for manual instrumentation. Measurements are aggregated by method path (class and method name) and optionally segmented by custom values, stored in an in-memory `ReportedMethodsHandler`, and exported via `Timeasure::Profiling::Manager.export`. The architecture is a simple library with configurable procs for post-measurement handling and error rescue, allowing users to integrate with external services like New Relic or Keen.io. The codebase is small, well-tested, and cleanly structured, but has not been updated since 2018, leading to outdated dependencies and a Ruby version target of 2.1+.
The LLM identified 2 files worth highlighting for reuse:
Implements a flexible configuration class using lambdas for customization of post-measurement behavior, error handling, toggling enablement, and storage of reported methods. This pattern is reusable across Ruby projects that need runtime-configurable logic without tight coupling.
A simple value object representing a single measurement, with attributes for class name, method name, segment, metadata, start/end times, and computed runtime in milliseconds. Uses memoization for derived values. Can be extracted as a general-purpose timing measurement class.