[Tizen] Change DebugPriority name and Debug priority
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / 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 <dali/internal/system/common/system-trace.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/devel-api/common/hash.h>
23 #include <string>
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::INFO, "AsyncBegin: %s : cookie %d\n", name, cookie);
40 }
41 void traceAsyncEnd(int tag, int cookie, const char* name, ...)
42 {
43   Debug::LogMessage(Debug::INFO, "AsyncEnd: %s : cookie %d\n", name, cookie);
44 }
45 void traceMark(int tag, const char* name, ...)
46 {
47   Debug::LogMessage(Debug::INFO, "Marker: %s \n", name);
48 }
49 } // namespace
50 #endif
51
52 namespace
53 {
54 int GetCookie(const std::string& description, std::string& markerName)
55 {
56   // description holds the marker name and postfix of _START or _END
57   std::size_t pos = description.find("_START");
58   if(pos == std::string::npos)
59   {
60     pos = description.find("_END");
61   }
62   if(!pos)
63   {
64     // if this asserts then check the postfix strings in StatContext.cpp for
65     // custom markers and performance-marker.cpp for built-in markers
66     DALI_ASSERT_DEBUG(0);
67   }
68   markerName = description.substr(0, pos);
69
70   std::size_t hash = Dali::CalculateHash(markerName.c_str());
71   return static_cast<int>(hash);
72 }
73 } // namespace
74
75 namespace Dali
76 {
77 namespace Internal
78 {
79 namespace Adaptor
80 {
81 SystemTrace::SystemTrace()
82 {
83 }
84 SystemTrace::~SystemTrace()
85 {
86 }
87
88 void SystemTrace::Trace(const PerformanceMarker& marker, const std::string& traceMessage)
89 {
90   PerformanceMarker::MarkerEventType eventType = marker.GetEventType();
91
92   if(eventType == PerformanceMarker::SINGLE_EVENT)
93   {
94     traceMark(TTRACE_TAG_GRAPHICS, traceMessage.c_str());
95     return;
96   }
97
98   // DALi is multi-threaded so timed events will occur asynchronously
99   std::string markerName;
100
101   int cookie = GetCookie(traceMessage, markerName);
102
103   if(eventType == PerformanceMarker::START_TIMED_EVENT)
104   {
105     traceAsyncBegin(TTRACE_TAG_GRAPHICS, cookie, markerName.c_str());
106   }
107   else
108   {
109     traceAsyncEnd(TTRACE_TAG_GRAPHICS, cookie, markerName.c_str());
110   }
111 }
112
113 } // namespace Adaptor
114
115 } // namespace Internal
116
117 } // namespace Dali