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