-
Notifications
You must be signed in to change notification settings - Fork 12
Add Stopwatch.Reporter utility and refactor Rate_Group to use it #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| with Delta_Time.Arithmetic; | ||
| with Sys_Time.Arithmetic; | ||
|
|
||
| package body Stopwatch.Reporter is | ||
|
|
||
| procedure Start (Self : in out Instance) is | ||
| begin | ||
| Self.Start (Wall_Start_Time => Ada.Real_Time.Clock); | ||
| end Start; | ||
|
|
||
| procedure Start (Self : in out Instance; Wall_Start_Time : in Ada.Real_Time.Time) is | ||
| begin | ||
| Self.Wall_Timer.Start_Time := Wall_Start_Time; | ||
| Self.Cpu_Timer.Start; | ||
| end Start; | ||
|
|
||
| procedure Stop (Self : in out Instance) is | ||
| begin | ||
| -- Stop the CPU timer first so the wall clock read below is excluded | ||
| -- from the CPU measurement: | ||
| Self.Stop_Cpu_Timer; | ||
| Self.Stop_Wall_Timer (Wall_Stop_Time => Ada.Real_Time.Clock); | ||
| end Stop; | ||
|
|
||
| procedure Stop (Self : in out Instance; Wall_Stop_Time : in Ada.Real_Time.Time) is | ||
| begin | ||
| Self.Stop_Cpu_Timer; | ||
| Self.Stop_Wall_Timer (Wall_Stop_Time => Wall_Stop_Time); | ||
| end Stop; | ||
|
|
||
| procedure Stop_Cpu_Timer (Self : in out Instance) is | ||
| begin | ||
| Self.Cpu_Timer.Stop; | ||
| Self.Last_Execution_Time := Self.Cpu_Timer.Result; | ||
| end Stop_Cpu_Timer; | ||
|
|
||
| procedure Stop_Wall_Timer (Self : in out Instance; Wall_Stop_Time : in Ada.Real_Time.Time) is | ||
| begin | ||
| Self.Wall_Timer.Stop_Time := Wall_Stop_Time; | ||
| Self.Last_Wall_Time := Self.Wall_Timer.Result; | ||
| end Stop_Wall_Timer; | ||
|
|
||
| procedure Accumulate (Self : in out Instance) is | ||
| Ignore_Max_Wall, Ignore_Max_Execution : Boolean; | ||
| begin | ||
| Self.Accumulate (Max_Wall_Time_Updated => Ignore_Max_Wall, Max_Execution_Time_Updated => Ignore_Max_Execution); | ||
| end Accumulate; | ||
|
|
||
| procedure Accumulate (Self : in out Instance; Max_Wall_Time_Updated : out Boolean; Max_Execution_Time_Updated : out Boolean) is | ||
| use Ada.Real_Time; | ||
|
|
||
| -- Fold a measured value into a recent-maximum and maximum pair, | ||
| -- reporting whether the maximum was updated: | ||
| procedure Update_Maximums (Value : in Time_Span; Recent_Max : in out Time_Span; Max : in out Time_Span; Updated : out Boolean) is | ||
| begin | ||
| Updated := False; | ||
| if Value > Recent_Max then | ||
| Recent_Max := Value; | ||
| end if; | ||
| if Value > Max then | ||
| Max := Value; | ||
| Updated := True; | ||
| end if; | ||
| end Update_Maximums; | ||
| begin | ||
| Update_Maximums (Self.Last_Wall_Time, Self.Recent_Max_Wall_Time, Self.Max_Wall_Time, Max_Wall_Time_Updated); | ||
| Update_Maximums (Self.Last_Execution_Time, Self.Recent_Max_Execution_Time, Self.Max_Execution_Time, Max_Execution_Time_Updated); | ||
| end Accumulate; | ||
|
|
||
| -- Convert a set of wall and execution time measurements into a | ||
| -- Task_Timing_Report.T: | ||
| function To_Report (Max_Wall_Time : in Ada.Real_Time.Time_Span; Max_Execution_Time : in Ada.Real_Time.Time_Span; Recent_Wall_Time : in Ada.Real_Time.Time_Span; Recent_Execution_Time : in Ada.Real_Time.Time_Span) return Task_Timing_Report.T is | ||
| use Delta_Time.Arithmetic; | ||
| To_Return : Task_Timing_Report.T; | ||
| Ignore : Sys_Time.Arithmetic.Sys_Time_Status; | ||
| begin | ||
| Ignore := To_Delta_Time (Max_Wall_Time, To_Return.Max.Wall_Time); | ||
| Ignore := To_Delta_Time (Max_Execution_Time, To_Return.Max.Execution_Time); | ||
| Ignore := To_Delta_Time (Recent_Wall_Time, To_Return.Recent_Max.Wall_Time); | ||
| Ignore := To_Delta_Time (Recent_Execution_Time, To_Return.Recent_Max.Execution_Time); | ||
| return To_Return; | ||
| end To_Report; | ||
|
|
||
| function Report (Self : in Instance) return Task_Timing_Report.T is | ||
| (To_Report (Max_Wall_Time => Self.Max_Wall_Time, Max_Execution_Time => Self.Max_Execution_Time, Recent_Wall_Time => Self.Recent_Max_Wall_Time, Recent_Execution_Time => Self.Recent_Max_Execution_Time)); | ||
|
|
||
| function Report_Last (Self : in Instance) return Task_Timing_Report.T is | ||
| (To_Report (Max_Wall_Time => Self.Max_Wall_Time, Max_Execution_Time => Self.Max_Execution_Time, Recent_Wall_Time => Self.Last_Wall_Time, Recent_Execution_Time => Self.Last_Execution_Time)); | ||
|
|
||
| procedure Reset_Recent_Max (Self : in out Instance) is | ||
| use Ada.Real_Time; | ||
| begin | ||
| Self.Recent_Max_Wall_Time := Time_Span_Zero; | ||
| Self.Recent_Max_Execution_Time := Time_Span_Zero; | ||
| end Reset_Recent_Max; | ||
|
|
||
| procedure Reset (Self : in out Instance) is | ||
| begin | ||
| Self := (others => <>); | ||
| end Reset; | ||
|
|
||
| end Stopwatch.Reporter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| with Task_Timing_Report; | ||
|
|
||
| -- A paired wall-clock and CPU-execution stopwatch for timing a section of | ||
| -- code. The reporter accumulates recent-maximum and all-time-maximum (high | ||
| -- water mark) values for both timers, and produces reports of the | ||
| -- accumulated values as a Task_Timing_Report.T, suitable for publishing as | ||
| -- a data product. | ||
| package Stopwatch.Reporter is | ||
|
|
||
| type Instance is tagged record | ||
| -- The underlying stopwatch pair. These are exposed so that users may | ||
| -- manipulate the start and stop times directly for cases the Start and | ||
| -- Stop subprograms below do not cover. | ||
| Wall_Timer : Wall_Timer_Instance; | ||
| Cpu_Timer : Cpu_Timer_Instance; | ||
| -- The results of the most recent Stop: | ||
| Last_Wall_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| Last_Execution_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| -- The accumulated maximum values: | ||
| Recent_Max_Wall_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| Max_Wall_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| Recent_Max_Execution_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| Max_Execution_Time : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero; | ||
| end record; | ||
|
|
||
| -- Start both the wall and CPU timers now. The wall timer is started | ||
| -- first, so that the timing bookkeeping itself is excluded from the CPU | ||
| -- measurement: | ||
| procedure Start (Self : in out Instance); | ||
| -- Start both timers, with the wall timer's start time supplied by the | ||
| -- caller instead of read from the clock. This is useful to backdate the | ||
| -- wall measurement, for example to the timestamp of an incoming tick so | ||
| -- that queue latency is included in the measurement: | ||
| procedure Start (Self : in out Instance; Wall_Start_Time : in Ada.Real_Time.Time); | ||
| -- Stop both timers now and store the measurement results. The CPU timer | ||
| -- is stopped first, so that the timing bookkeeping itself is excluded | ||
| -- from the CPU measurement: | ||
| procedure Stop (Self : in out Instance); | ||
| -- Stop both timers, with the wall timer's stop time supplied by the | ||
| -- caller instead of read from the clock. Note that the provided wall stop | ||
| -- time is necessarily acquired before the CPU timer stops; if that | ||
| -- acquisition is expensive, use the split subprograms below instead: | ||
| procedure Stop (Self : in out Instance; Wall_Stop_Time : in Ada.Real_Time.Time); | ||
| -- The two halves of Stop, exposed so that the CPU timer can be stopped | ||
| -- before the wall clock stop time is acquired, when that acquisition is | ||
| -- itself expensive (e.g. a system time fetched through a connector). Call | ||
| -- Stop_Cpu_Timer first, acquire the wall stop time, and then call | ||
| -- Stop_Wall_Timer. Each stops its timer and stores that timer's | ||
| -- measurement result: | ||
| procedure Stop_Cpu_Timer (Self : in out Instance); | ||
| procedure Stop_Wall_Timer (Self : in out Instance; Wall_Stop_Time : in Ada.Real_Time.Time); | ||
| -- Fold the results of the most recent Stop into the recent-maximum and | ||
| -- maximum accumulators: | ||
| procedure Accumulate (Self : in out Instance); | ||
| -- Same as above, but additionally reports whether either all-time maximum | ||
| -- value was updated, which is useful for issuing time-exceeded events: | ||
| procedure Accumulate (Self : in out Instance; Max_Wall_Time_Updated : out Boolean; Max_Execution_Time_Updated : out Boolean); | ||
| -- Produce a report of the currently accumulated values: | ||
| function Report (Self : in Instance) return Task_Timing_Report.T; | ||
| -- Produce a report with the Recent_Max fields holding the results of the | ||
| -- most recent Stop instead of the recent maximums. This is useful for | ||
| -- per-operation reporting, where each report carries the timing of the | ||
| -- operation just performed alongside the all-time maximums: | ||
| function Report_Last (Self : in Instance) return Task_Timing_Report.T; | ||
| -- Reset only the recent-maximum values. This is intended to be called | ||
| -- after each report is published so that the recent maximums cover a | ||
| -- single reporting period: | ||
| procedure Reset_Recent_Max (Self : in out Instance); | ||
| -- Reset all stored values, including the all-time maximums. Any | ||
| -- in-progress measurement (a Start without a Stop) is also discarded: | ||
| procedure Reset (Self : in out Instance); | ||
|
|
||
| end Stopwatch.Reporter; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from environments import test # noqa: F401 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| description: This is a unit test suite for the Stopwatch.Reporter utility | ||
| tests: | ||
| - name: Test_Start_Stop | ||
| description: This unit test tests starting and stopping the timer pair, including supplying the wall clock start and stop times externally. | ||
| - name: Test_Accumulation | ||
| description: This unit test tests accumulating measurements into the recent-maximum and maximum values, including the maximum-updated indications. | ||
| - name: Test_Reports | ||
| description: This unit test tests the contents of the accumulated report and the last-measurement report. | ||
| - name: Test_Reset | ||
| description: This unit test tests resetting the recent-maximum values and resetting all values. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.