PrivateconstructorPrivate constructor to enforce singleton pattern. Initializes the store for profiler entries.
Optionalactive: boolean = falseOptional parameter to enable the profiler
PrivateactiveOptional parameter to enable the profiler
PrivatememPrivatenowPre-computed functions for time and memory retrieval
Returns the services provided by the Profiler class. This allows for easy access to the profiler's methods.
PrivatestoreStore for profiler entries
PrivatetotalPrivatetotalTotal time and memory consumption
Private StaticENVEnvironment detection
Private StaticinstanceSingleton instance
Resets the profiler by clearing the store, total time and memory consumption. This method is useful for starting a new profiling session.
Disables the profiler. Sets the active state to false, preventing further profiling.
Enables the profiler. Sets the active state to true, allowing profiling to occur.
Retrieves all profiler entries stored in the profiler.
Retrieves the last profiler entry stored in the profiler.
Retrieves the total time and memory consumption recorded by the profiler.
PrivatememGets the current memory usage based on the environment.
Uses process.memoryUsage().heapUsed for Node.js, performance.memory.usedJSHeapSize for browsers, and returns 0 as a fallback.
PrivatenowGets the current time based on the environment.
Uses process.hrtime.bigint() for Node.js, performance.now() for browsers, and Date.now() as a fallback.
PrivateprofileRuns a synchronous function and profiles its execution time and memory usage. If the profiler is not active, it simply executes the function without profiling.
Function to be executed and profiled
Metadata to be associated with the profiling entry
Runs an asynchronous function and profiles its execution time and memory usage. If the profiler is not active, it simply executes the function without profiling.
Asynchronous function to be executed and profiled
Metadata to be associated with the profiling entry
Protected StaticdetectSets the environment based on the available global objects. Detects if running in Node.js or browser and sets the ENV property accordingly.
StaticgetReturns the singleton instance of the Profiler class. If the instance does not exist, it creates a new one.
Optionalenable: booleanOptional parameter to enable the profiler upon instantiation
Profiler class for measuring execution time and memory usage of functions.