Dali 3D User Interface Engine
performance-server.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 // CLASS HEADER
19 #include "performance-server.h"
20 
21 // EXTERNAL INCLUDES
23 
24 // INTERNAL INCLUDES
26 #include <base/time-service.h>
27 
28 namespace Dali
29 {
30 
31 namespace Internal
32 {
33 
34 namespace Adaptor
35 {
36 
37 namespace
38 {
39 const unsigned int NANOSECONDS_PER_MICROSECOND = 1000u;
40 const float MICROSECONDS_TO_SECOND = 1e-6;
41 } // unnamed namespace
42 
44  const EnvironmentOptions& environmentOptions)
45 : mEnvironmentOptions( environmentOptions ),
46  mKernelTrace( adaptorServices.GetKernelTraceInterface() ),
47  mSystemTrace( adaptorServices.GetSystemTraceInterface() ),
48 #if defined(NETWORK_LOGGING_ENABLED)
49  mNetworkServer( adaptorServices, environmentOptions ),
50  mNetworkControlEnabled( mEnvironmentOptions.GetNetworkControlMode()),
51 #endif
52  mStatContextManager( *this ),
53  mStatisticsLogBitmask( 0 ),
54  mLoggingEnabled( false ),
55  mLogFunctionInstalled( false )
56 {
60 
61 #if defined(NETWORK_LOGGING_ENABLED)
62  if( mNetworkControlEnabled )
63  {
64  mLoggingEnabled = true;
65  mNetworkServer.Start();
66  }
67 #endif
68 }
69 
71 {
72 #if defined(NETWORK_LOGGING_ENABLED)
73  if( mNetworkControlEnabled )
74  {
75  mNetworkServer.Stop();
76  }
77 #endif
78 
80  {
82  }
83 }
84 
85 void PerformanceServer::SetLogging( unsigned int statisticsLogOptions,
86  unsigned int timeStampOutput,
87  unsigned int logFrequency )
88 {
89  mStatisticsLogBitmask = statisticsLogOptions;
90  mPerformanceOutputBitmask = timeStampOutput;
91 
93 
94  if( ( mStatisticsLogBitmask == 0) && ( mPerformanceOutputBitmask == 0 ))
95  {
96  mLoggingEnabled = false;
97  }
98  else
99  {
100  mLoggingEnabled = true;
101  }
102 }
103 
104 void PerformanceServer::SetLoggingFrequency( unsigned int logFrequency, ContextId contextId )
105 {
106  mStatContextManager.SetLoggingFrequency( logFrequency, contextId );
107 }
108 
109 void PerformanceServer::EnableLogging( bool enable, ContextId contextId )
110 {
111  mStatContextManager.EnableLogging( enable, contextId );
112 }
113 
115 {
116  // for adding custom contexts
118 }
119 
121 {
122  mStatContextManager.RemoveContext( contextId );
123 }
124 
125 void PerformanceServer::AddMarker( MarkerType markerType, ContextId contextId )
126 {
127  // called only for custom markers
128 
129  if( !mLoggingEnabled )
130  {
131  return;
132  }
133 
134  // Get the time stamp
135  uint64_t timeStamp = 0;
136  TimeService::GetNanoseconds( timeStamp );
137  timeStamp /= NANOSECONDS_PER_MICROSECOND; // Convert to microseconds
138 
139  // Create a marker
140  PerformanceMarker marker( markerType, FrameTimeStamp( 0, timeStamp ) );
141 
142  // get the marker description for this context, e.g SIZE_NEGOTIATION_START
143  const char* const description = mStatContextManager.GetMarkerDescription( markerType, contextId );
144 
145  // log it
146  LogMarker( marker, description );
147 
148  // Add custom marker to statistics context manager
149  mStatContextManager.AddCustomMarker( marker, contextId );
150 }
151 
153 {
154  // called only for internal markers
155 
156  if( !mLoggingEnabled )
157  {
158  return;
159  }
160 
161  if( markerType == VSYNC )
162  {
163  // make sure log function is installed, note this will be called only from v-sync thread
164  // if the v-sync thread has already installed one, it won't make any difference.
165  if( ! mLogFunctionInstalled )
166  {
168  mLogFunctionInstalled = true;
169  }
170  }
171 
172  // Get the time
173  uint64_t timeStamp = 0;
174  TimeService::GetNanoseconds( timeStamp );
175  timeStamp /= NANOSECONDS_PER_MICROSECOND; // Convert to microseconds
176 
177  // Create a marker
178  PerformanceMarker marker( markerType, FrameTimeStamp( 0, timeStamp ) );
179 
180  // log it
181  LogMarker(marker, marker.GetName() );
182 
183  // Add internal marker to statistics context manager
185 
186 }
187 
188 void PerformanceServer::LogContextStatistics( const char* const text )
189 {
191 }
192 
193 void PerformanceServer::LogMarker( const PerformanceMarker& marker, const char* const description )
194 {
195 #if defined(NETWORK_LOGGING_ENABLED)
196  // log to the network ( this is thread safe )
197  if( mNetworkControlEnabled )
198  {
199  mNetworkServer.TransmitMarker( marker, description );
200  }
201 #endif
202 
203  // log to kernel trace
205  {
206  // Kernel tracing implementation may not be thread safe
208  // description will be something like UPDATE_START or UPDATE_END
209  mKernelTrace.Trace( marker, description );
210  }
211 
212  // log to system trace
214  {
215  // System tracing implementation may not be thread safe
217 
218  mSystemTrace.Trace( marker, description );
219  }
220 
221  // log to Dali log ( this is thread safe )
223  {
225  "%.6f (seconds), %s\n",
226  (float)( marker.GetTimeStamp().microseconds * MICROSECONDS_TO_SECOND ),
227  description);
228 
229  }
230 }
231 
232 
233 } // namespace Internal
234 
235 } // namespace Adaptor
236 
237 } // namespace Dali
Dali Docs Home
Read more about Dali