Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / include / frameworkunified_msgprofiler.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 //////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NSFramework
19 /// \brief    File declares FrameworkunifiedMsgProfiler class which keeps profiler information for message dispatcher
20 ///
21 ///
22 ///
23 //////////////////////////////////////////////////////////////////////////////////////////////////
24
25 #ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_
26 #define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_
27
28 #include <native_service/frameworkunified_types.h>
29 #include <string>
30 #include <vector>
31
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 /// Profiler class which keeps and manage profiler information for message dispatcher
34 ///////////////////////////////////////////////////////////////////////////////////////////////////
35 class FrameworkunifiedMsgProfiler {
36  public:
37   ///////////////////////////////////////////////////////////////////////////////////////////
38   /// FrameworkunifiedMsgProfiler
39   /// Parameterized constructor
40   /// \param [in] f_cAppName
41   ///     const std::string& - Name of the application or dispatcher
42   ///
43   /// \return none
44   ///////////////////////////////////////////////////////////////////////////////////////////
45   explicit FrameworkunifiedMsgProfiler(const std::string &f_cAppName);
46
47   ///////////////////////////////////////////////////////////////////////////////////////////
48   /// ~FrameworkunifiedMsgProfiler
49   /// Class destructor
50   ///
51   /// \return none
52   ///////////////////////////////////////////////////////////////////////////////////////////
53   ~FrameworkunifiedMsgProfiler();
54
55   ///////////////////////////////////////////////////////////////////////////////////////////
56   /// GetAppName
57   /// Returns application name corresponding to profiler
58   ///
59   /// \param [in] none
60   ///
61   /// \return std::string
62   ///         std::string - Returns application name corresponding to profiler
63   ///
64   ///////////////////////////////////////////////////////////////////////////////////////////
65   std::string GetAppName();
66
67   ///////////////////////////////////////////////////////////////////////////////////////////
68   /// AddChildName
69   /// Returns application name corresponding to profiler
70   ///
71   /// \param [in] f_cChildName
72   ///      const std::string& - Add the name of child dispatcher profiler
73   ///
74   /// \return none
75   ///
76   ///////////////////////////////////////////////////////////////////////////////////////////
77   VOID AddChildName(const std::string &f_cChildName);
78
79   ///////////////////////////////////////////////////////////////////////////////////////////
80   /// MsgReceived
81   /// Updates the profiler information once the message is received.
82   /// e.g. increaments msg count, save the time of msg received
83   ///
84   /// \param [in] none
85   ///
86   /// \return none
87   ///
88   ///////////////////////////////////////////////////////////////////////////////////////////
89   VOID MsgReceived();
90
91   ///////////////////////////////////////////////////////////////////////////////////////////
92   /// MsgProcessed
93   /// Updates the profiler information once the message is processed.
94   /// e.g. Updates the frequency of execution of message
95   ///
96   /// \param [in] none
97   ///
98   /// \return none
99   ///
100   ///////////////////////////////////////////////////////////////////////////////////////////
101   VOID MsgProcessed();
102
103   ///////////////////////////////////////////////////////////////////////////////////////////
104   /// PrintProfileInfo
105   /// All the profiler information which FrameworkunifiedMsgProfiler class has prints it in message
106   /// queue FRAMEWORKUNIFIED_NS_MSGPROFILERUTIL
107   ///
108   /// \param [in] f_hApp
109   ///         HANDLE - Application framework handle
110   ///
111   /// \return status
112   ///         EFrameworkunifiedStatus - success or failure
113   ///
114   ///////////////////////////////////////////////////////////////////////////////////////////
115   EFrameworkunifiedStatus PrintProfileInfo(HANDLE f_hApp);
116
117   static BOOL m_bMsgProfilerEnabled;  /// Flag is enabled when command line argument -q is passed.
118   /// Otherwise no profiler information is maintained.
119
120  private:
121   ///////////////////////////////////////////////////////////////////////////////////////////
122   /// GetClock
123   /// GetClock of milliseconds
124   ///
125   /// \param [in] none
126   ///
127   /// \return UI_64
128   ///         UI_64 - returns time in Milliseconds
129   ///
130   ///////////////////////////////////////////////////////////////////////////////////////////
131   UI_64 GetClock();
132
133   std::vector<std::string> m_vChildNames;  /// vector to save list of all child threads dispatcher
134   std::string m_cAppName;  /// Dispacther application name
135   UI_32 m_ui32TotalNoOfMsgsReceived;  /// Total number of messages received by the dispatcher
136
137   // NOTE: Storing time in ClockCycle. So that it will not add overhead for converting it to miliseconds.
138   //      It will get converted only when information is required to print.
139   UI_64 m_ui64MinMsgProcessingTime;  // time is in clock cycles
140   UI_64 m_ui64MaxMsgProcessingTime;  // time is in clock cycles
141
142   UI_64 m_ui64TotalMsgExecutionTime;  /// total time spent in message execution
143   UI_64 m_ui64LastMsgReceivedTime;  /// save the time when last message was received
144   UI_64 m_ui64AppInitTime;  /// save the time when application got initialized
145   BOOL  m_bLastMsgWasPrintProfile;  /// TRUE if the last message received
146 };
147
148 #endif  // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_