|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| exampleConsolePrint () | |
| Placeholder example function illustrating a custom console print callback. | |
| module | setGetTimeFunction (fn) |
| Override the timing function used by the profiler to measure elapsed time. | |
| module | getInfo () |
| Return the internal profiler report cache and full report list for inspection. | |
| module | attachPrintFunction (fn, verbose) |
| Attach a custom print function to receive profiler output strings. | |
| module | start () |
| Start a new profiling session and begin instrumenting function calls. | |
| module | pause () |
| Pause an active profiling session without discarding collected data. | |
| module | resume () |
| Resume profiling after a pause and accumulate the paused interval duration. | |
| module | stop () |
| Stop the profiler and record the stop timestamp. | |
| module | report (filename) |
| Write the profiling report to a file, stopping profiling if not already stopped. | |
| module | configuration (overrides) |
| Modify the configuration of the profiler module programmatically. | |
| module attachPrintFunction | ( | fn | , |
| verbose | ) |
Attach a custom print function to receive profiler output strings.
Registers an external function that the profiler will call with string arguments during report generation. If verbose mode is enabled, the attached function is called for every output line written to the report file. Regardless of verbose setting, the total time summary line is always forwarded to the attached function. Pass nil as fn to detach a previously registered print function.
| fn | (function) The print callback to attach. Must accept a single string parameter |
| verbose | (boolean) If true, every report output line is forwarded to fn. Defaults to false |
| module configuration | ( | overrides | ) |
Modify the configuration of the profiler module programmatically.
Accepts a table of override values whose keys must match existing configuration parameter names. Invalid keys are reported via print(). Valid overrides are deep-copied before being applied to prevent external mutation. After applying overrides, column formatting patterns are rebuilt to reflect the new configuration.
| overrides | (table) Table of configuration overrides. Valid keys are:
|
| exampleConsolePrint | ( | ) |
Placeholder example function illustrating a custom console print callback.
This function serves as a documentation example showing the expected signature and purpose of a user-defined print callback for use with module.attachPrintFunction(). It is not implemented and should be replaced with a real logging or console output function in the caller's codebase. The function must accept a single string parameter representing the output line produced by the profiler.
| module getInfo | ( | ) |
Return the internal profiler report cache and full report list for inspection.
Provides direct access to the two primary internal data structures used by the profiler: reportCache (a table keyed by formatted title strings) and allReports (an ordered array of all report entries). This function is intended for debugging and programmatic inspection of raw profiling data without generating a report file.
| module pause | ( | ) |
Pause an active profiling session without discarding collected data.
Records the current timestamp as the pause start time and removes the debug hook, suspending function call instrumentation. The duration spent in the paused state is later subtracted from total elapsed time when module.resume() is called, ensuring paused intervals do not inflate profiling results.
Referenced by SetXNegativeStrokePause(), SetXPositiveStrokePause(), SetZNegativeStrokePause(), and SetZPositiveStrokePause().
| module report | ( | filename | ) |
Write the profiling report to a file, stopping profiling if not already stopped.
Sorts all collected function reports by descending execution time, then writes a formatted report to the specified file. The report includes total elapsed time, a formatted table of function call data, and a divider separating measurable from unmeasurable (near-zero time) entries. Functions belonging to the profiler itself and C functions are excluded from the output. If an attached print function exists, the total time and (if verbose) each output line are forwarded to it. The lessTime accumulated during any paused intervals is subtracted from the total time calculation.
| filename | (string) Path to the output report file. File is created or overwritten. If not provided, defaults to "profiler.log" |
| module resume | ( | ) |
Resume profiling after a pause and accumulate the paused interval duration.
Reinstates the debug hook to resume function call instrumentation. If a pause start time was recorded by module.pause(), the elapsed paused duration is added to the running lessTime accumulator so that paused intervals are excluded from the final total time calculation in the report. If resume() is called without a preceding pause(), the debug hook is still reinstated but no time adjustment is made.
| module setGetTimeFunction | ( | fn | ) |
Override the timing function used by the profiler to measure elapsed time.
Replaces the internal getTime function reference used to record call and return timestamps during profiling. By default the profiler uses wh.GetUsecTimestamp for microsecond precision. Supply a replacement function to use an alternative clock source, such as os.clock for millisecond precision or a custom high-resolution timer. The provided function must take no parameters and return a numeric timestamp.
| fn | (function) Replacement timing function. Must accept no parameters and return a comparable numeric value representing the current time |
| module start | ( | ) |
Start a new profiling session and begin instrumenting function calls.
Clears all previously collected report data, resets counters, records the start timestamp, and installs a debug hook that fires on every function call and return event. If column formatting patterns have not yet been built, they are initialized before profiling begins. The lessTime accumulator used for pause/resume intervals is also reset to zero.
| module stop | ( | ) |
Stop the profiler and record the stop timestamp.
Captures the current high-resolution timestamp as the stop time and removes the debug hook, halting all function call instrumentation. The recorded stop time is used by module.report() to compute total elapsed time. Calling stop() multiple times is safe but will overwrite the previous stop timestamp.