adb4283957e2ce94adede78f3c0a985debab5479
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / performance-logger-impl.cpp
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 <dali/internal/system/common/performance-logger-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/adaptor/common/adaptor-impl.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 namespace
34 {
35
36 PerformanceInterface* GetPerformanceInterface()
37 {
38   if( Adaptor::IsAvailable() )
39   {
40     return Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() ).GetPerformanceInterface();
41   }
42
43   return NULL;
44 }
45
46 } // Anonymous namespace
47
48 PerformanceLoggerPtr PerformanceLogger::New( const char* name )
49 {
50   PerformanceLoggerPtr logger = new PerformanceLogger( name );
51   return logger;
52 }
53
54 PerformanceLogger::PerformanceLogger( const char* name )
55 : mContext( 0 )
56 {
57   PerformanceInterface* performance = GetPerformanceInterface();
58   if( performance )
59   {
60     mContext = performance->AddContext( name );
61   }
62 }
63
64 PerformanceLogger::~PerformanceLogger()
65 {
66   PerformanceInterface* performance = GetPerformanceInterface();
67   if( performance )
68   {
69     performance->RemoveContext( mContext );
70   }
71 }
72
73 void PerformanceLogger::AddMarker( Dali::PerformanceLogger::Marker markerType )
74 {
75   PerformanceInterface* performance = GetPerformanceInterface();
76   if( performance )
77   {
78     PerformanceInterface::MarkerType newMarkerType = PerformanceInterface::START;
79     switch( markerType )
80     {
81       case Dali::PerformanceLogger::START_EVENT:
82       {
83         newMarkerType = PerformanceInterface::START;
84         break;
85       }
86       case Dali::PerformanceLogger::END_EVENT:
87       {
88         newMarkerType = PerformanceInterface::END;
89         break;
90       }
91     }
92
93     performance->AddMarker( newMarkerType, mContext );
94   }
95 }
96
97 void PerformanceLogger::SetLoggingFrequency( unsigned int logFrequency)
98 {
99   PerformanceInterface* performance = GetPerformanceInterface();
100   if( performance )
101   {
102     performance->SetLoggingFrequency( logFrequency, mContext );
103   }
104 }
105
106 void PerformanceLogger::EnableLogging( bool enable )
107 {
108   PerformanceInterface* performance = GetPerformanceInterface();
109   if( performance )
110   {
111     performance->EnableLogging( enable, mContext );
112   }
113 }
114
115 } // namespace Adaptor
116
117 } // namespace Internal
118
119 } // namespace Dali