[dali_2.3.27] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / frame-time-stats.h
1 #ifndef DALI_INTERNAL_ADAPTOR_FRAME_TIME_STATS_H
2 #define DALI_INTERNAL_ADAPTOR_FRAME_TIME_STATS_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/system/common/frame-time-stamp.h>
23 #include <dali/public-api/common/dali-vector.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 /**
32  * Used to get statistics about time stamps over a period of time.
33  * E.g. the min, max, total and average time spent inside two markers,
34  * such as UPDATE_START and UPDATE_END
35  */
36 struct FrameTimeStats
37 {
38   /**
39    * Constructor
40    */
41   FrameTimeStats();
42
43   /**
44    * Destructor, not intended as a base class
45    */
46   ~FrameTimeStats();
47
48   /**
49    * Timer start time
50    * @param timeStamp time stamp
51    */
52   void StartTime(const FrameTimeStamp& timeStamp);
53
54   /**
55     * Timer end time
56     * @param timeStamp time stamp
57     */
58   void EndTime(const FrameTimeStamp& timeStamp);
59
60   /**
61     * Reset all internal counters / state except total time.
62     */
63   void Reset();
64
65   /**
66     * @return maximum time in seconds
67     */
68   float GetMaxTime() const;
69
70   /**
71     * @return minimum time in seconds
72     */
73   float GetMinTime() const;
74
75   /**
76     * @return total time in second
77     */
78   float GetTotalTime() const;
79
80   /**
81     * Get how many times the timer has been started /stopped
82     */
83   unsigned int GetRunCount() const;
84
85   /**
86     * Calculate the mean and standard deviation
87     *
88     * @param[out] mean The return mean value
89     * @param[out] standardDeviation The return standard deviation value
90     */
91   void CalculateMean(float& meanOut, float& standardDeviationOut) const;
92
93 private:
94   /**
95     * internal time state.
96     */
97   enum TimeState
98   {
99     WAITING_FOR_START_TIME, ///< waiting for start time marker
100     WAITING_FOR_END_TIME    ///< waiting for end time marker
101   };
102
103   typedef Dali::Vector<unsigned int> Samples;
104   Samples                            mSamples;
105
106   unsigned int   mMin;               ///< current minimum value in microseconds
107   unsigned int   mMax;               ///< current maximum value in microseconds
108   unsigned int   mTotal;             ///< current total in in microseconds
109   unsigned int   mRunCount;          ///< how many times the timer has been start / stopped
110   FrameTimeStamp mStart;             ///< start time stamp, to calculate the diff
111   TimeState      mTimeState : 1;     ///< time state
112   bool           mMinMaxTimeSet : 1; ///< whether the min-max values have been configured
113 };
114
115 } // namespace Adaptor
116
117 } // namespace Internal
118
119 } // namespace Dali
120
121 #endif // DALI_INTERNAL_ADAPTOR_FRAME_TIME_STATS_H