Natools

Check-in [cf0534dce3]
Login
Overview
Comment:time_statistics-fine_timers: new instance of Generic_Timers using annex D monotonic time
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cf0534dce338a5e56cf9c71b18194e1a419357b5
User & Date: nat on 2014-09-06 21:08:04
Other Links: manifest | tags
Context
2014-09-07
20:13
s_expressions-replayable: new interface for S-expression descriptors that can duplicated check-in: 39fe9aca16 user: nat tags: trunk
2014-09-06
21:08
time_statistics-fine_timers: new instance of Generic_Timers using annex D monotonic time check-in: cf0534dce3 user: nat tags: trunk
2014-09-05
21:12
time_statistics-tests: add tests for a simple instance of Generic_Timers check-in: 93c9714216 user: nat tags: trunk
Changes

Added src/natools-time_statistics-fine_timer_difference.adb version [b174cfbb20].






























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.Time_Statistics.Fine_Timer_Difference provides a difference      --
-- function between real-time moments as a Duration value.                  --
------------------------------------------------------------------------------

with Ada.Real_Time;

function Natools.Time_Statistics.Fine_Timer_Difference
  (Left, Right : Ada.Real_Time.Time)
  return Duration is
begin
   return Ada.Real_Time.To_Duration (Ada.Real_Time."-" (Left, Right));
end Natools.Time_Statistics.Fine_Timer_Difference;

Added src/natools-time_statistics-fine_timer_difference.ads version [3f493847ab].



























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.Time_Statistics.Fine_Timer_Difference provides a difference      --
-- function between real-time moments as a Duration value.                  --
------------------------------------------------------------------------------

with Ada.Real_Time;

function Natools.Time_Statistics.Fine_Timer_Difference
  (Left, Right : Ada.Real_Time.Time)
  return Duration;

Added src/natools-time_statistics-fine_timers.ads version [d409ace7dd].


























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Ada.Real_Time;
with Natools.Time_Statistics.Fine_Timer_Difference;
with Natools.Time_Statistics.Generic_Timers;

package Natools.Time_Statistics.Fine_Timers
  is new Natools.Time_Statistics.Generic_Timers
  (Ada.Real_Time.Time,
   Ada.Real_Time.Clock,
   Natools.Time_Statistics.Fine_Timer_Difference);

Modified tests/natools-time_statistics-tests.adb from [2b967f59a6] to [05e270656b].

11
12
13
14
15
16
17


18
19
20










21
22
23
24
25




































26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57
58


59
60
61
62
63
64
65
66
67

68
69

70
71
72
73


74
75
76
77
78

79
80
81
82
83
84
85
86
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95








96
97



98
99

100

101





102


103




104
105


106
107

108
109
110
111
112
113
114
115
116







+
+



+
+
+
+
+
+
+
+
+
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










+










-

-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-

-

-
-
-
-
-
+
-
-
+
-
-
-
-
+
+
-
-


-
+








-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Natools.Time_Statistics.Coarse_Timers;
with Natools.Time_Statistics.Fine_Timers;
with Natools.Time_Statistics.Generic_Timers;

package body Natools.Time_Statistics.Tests is

   generic
      with package Timers is new Generic_Timers (<>);
      Total_Length : in Duration;
   procedure Test_Timer (Test : in out NT.Test);


   ------------------------------
   -- Local Helper Subprograms --
   ------------------------------

   procedure Check is new NT.Generic_Check
     (Natural, "=", Natural'Image, False);

   procedure Check is new NT.Generic_Check
     (Duration, "=", Duration'Image, False);


   procedure Test_Timer (Test : in out NT.Test) is
      Stats : aliased Summary;
   begin
      declare
         Actual_Auto : Timers.Auto_Timer (Stats'Access);
         Aborted_Auto : Timers.Auto_Timer (Stats'Access);
         Manual : Timers.Manual_Timer (Stats'Access);

         pragma Unreferenced (Actual_Auto);
      begin
         Manual.Start;
         Check (Test, 0, Stats.Sample_Count);

         delay Total_Length / 2;

         Aborted_Auto.Cancel;
         Manual.Stop;
         Check (Test, 1, Stats.Sample_Count, "Sample count");
         Manual.Start;

         delay Total_Length / 2;

         Manual.Cancel;
         Check (Test, 1, Stats.Sample_Count, "Sample count");
      end;

      Check (Test, 2, Stats.Sample_Count, "Sample count");
   end Test_Timer;


   procedure Coarse_Timer is new Test_Timer (Coarse_Timers, 0.2);

   procedure Fine_Timer is new Test_Timer (Fine_Timers, 0.2);



   -------------------------
   -- Complete Test Suite --
   -------------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Summary_Accumulator (Report);
      Coarse_Timer (Report);
      Fine_Timer (Report);
   end All_Tests;



   -----------------------
   -- Inidividual Tests --
   -----------------------

   procedure Coarse_Timer (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Coarse timer standard use");
      Total_Length : constant Duration := 0.2;
   begin
      declare
         Stats : aliased Summary;
      begin
         declare
            Actual_Auto : Coarse_Timers.Auto_Timer (Stats'Access);
            Aborted_Auto : Coarse_Timers.Auto_Timer (Stats'Access);
            Manual : Coarse_Timers.Manual_Timer (Stats'Access);

      Coarse_Timer (Test);
   exception
            pragma Unreferenced (Actual_Auto);
         begin
            Manual.Start;
      when Error : others => Test.Report_Exception (Error);
   end Coarse_Timer;
            Check (Test, 0, Stats.Sample_Count);

            delay Total_Length / 2;

            Aborted_Auto.Cancel;
            Manual.Stop;
            Check (Test, 1, Stats.Sample_Count, "Sample count");
            Manual.Start;

   procedure Fine_Timer (Report : in out NT.Reporter'Class) is
            delay Total_Length / 2;

      Test : NT.Test := Report.Item ("Fine timer standard use");
            Manual.Cancel;
            Check (Test, 1, Stats.Sample_Count, "Sample count");
         end;

   begin
      Fine_Timer (Test);
         Check (Test, 2, Stats.Sample_Count, "Sample count");
      end;
   exception
      when Error : others => Test.Report_Exception (Error);
   end Coarse_Timer;
   end Fine_Timer;


   procedure Summary_Accumulator (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Summary accumulator");
   begin
      declare
         Stats : Summary;
      begin

Modified tests/natools-time_statistics-tests.ads from [1c9ced85f6] to [a53f57c487].

25
26
27
28
29
30
31

32
33
25
26
27
28
29
30
31
32
33
34







+



   package NT renames Natools.Tests;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Summary_Accumulator (Report : in out NT.Reporter'Class);
   procedure Coarse_Timer (Report : in out NT.Reporter'Class);
   procedure Fine_Timer (Report : in out NT.Reporter'Class);

end Natools.Time_Statistics.Tests;