Merge "Added FileReader and FileWriter classes to wrap FileCloser" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / common / system-trace.cpp
1 /*
2  * Copyright (c) 2015 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 "system-trace.h"
20
21 // EXTERNAL HEADERS
22 #include <string>
23 #include <dali/devel-api/common/hash.h>
24
25 // INTERNAL HEADERS
26 #include <dali/integration-api/debug.h>
27
28 #ifdef ENABLE_TTRACE
29 #include <ttrace.h>
30 #else
31
32 // Emulate trace calls if ttrace isn't available
33 namespace
34 {
35 const int TTRACE_TAG_GRAPHICS = 1;
36
37 void traceAsyncBegin(int tag, int cookie, const char *name, ...)
38 {
39   Debug::LogMessage(Debug::DebugInfo, "AsyncBegin: %s : cookie %d\n", name, cookie );
40 }
41 void traceAsyncEnd(int tag, int cookie, const char *name, ...)
42 {
43   Debug::LogMessage(Debug::DebugInfo, "AsyncEnd: %s : cookie %d\n", name, cookie );
44 }
45 void traceMark(int tag, const char *name, ...)
46 {
47   Debug::LogMessage(Debug::DebugInfo, "Marker: %s \n", name);
48 }
49 } // un-named namespace
50 #endif
51
52 namespace
53 {
54
55 int GetCookie( const std::string& description, std::string& markerName )
56 {
57   // description holds the marker name and postfix of _START or _END
58   std::size_t pos = description.find("_START");
59   if( pos == std::string::npos )
60   {
61     pos = description.find("_END");
62   }
63   if( !pos )
64   {
65     // if this asserts then check the postfix strings in StatContext.cpp for
66     // custom markers and performance-marker.cpp for built-in markers
67     DALI_ASSERT_DEBUG(0);
68   }
69   markerName = description.substr( 0, pos );
70
71   std::size_t hash =  Dali::CalculateHash( markerName.c_str() );
72   return static_cast<int>( hash );
73 }
74 }
75
76 namespace Dali
77 {
78
79 namespace Internal
80 {
81
82 namespace Adaptor
83 {
84
85 SystemTrace::SystemTrace()
86 {
87 }
88 SystemTrace::~SystemTrace()
89 {
90 }
91
92 void SystemTrace::Trace( const PerformanceMarker& marker, const std::string& traceMessage )
93 {
94   PerformanceMarker::MarkerEventType eventType = marker.GetEventType();
95
96   if( eventType == PerformanceMarker::SINGLE_EVENT )
97   {
98     traceMark( TTRACE_TAG_GRAPHICS, traceMessage.c_str() );
99     return;
100   }
101
102   // DALi is multi-threaded so timed events will occur asynchronously
103   std::string markerName;
104
105   int cookie = GetCookie(traceMessage, markerName );
106
107   if( eventType == PerformanceMarker::START_TIMED_EVENT )
108   {
109     traceAsyncBegin( TTRACE_TAG_GRAPHICS, cookie,  markerName.c_str() );
110   }
111   else
112   {
113     traceAsyncEnd( TTRACE_TAG_GRAPHICS, cookie,  markerName.c_str() );
114   }
115 }
116
117 } // namespace Internal
118
119 } // namespace Adaptor
120
121 } // namespace Dali
122