2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/system/common/system-trace.h>
22 #include <dali/devel-api/common/hash.h>
26 #include <dali/integration-api/debug.h>
32 // Emulate trace calls if ttrace isn't available
35 const int TTRACE_TAG_GRAPHICS = 1;
37 void traceAsyncBegin(int tag, int cookie, const char* name, ...)
39 Debug::LogMessage(Debug::INFO, "AsyncBegin: %s : cookie %d\n", name, cookie);
41 void traceAsyncEnd(int tag, int cookie, const char* name, ...)
43 Debug::LogMessage(Debug::INFO, "AsyncEnd: %s : cookie %d\n", name, cookie);
45 void traceMark(int tag, const char* name, ...)
47 Debug::LogMessage(Debug::INFO, "Marker: %s \n", name);
54 int GetCookie(const std::string& description, std::string& markerName)
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)
60 pos = description.find("_END");
64 // if this asserts then check the postfix strings in StatContext.cpp for
65 // custom markers and performance-marker.cpp for built-in markers
68 markerName = description.substr(0, pos);
70 std::size_t hash = Dali::CalculateHash(markerName.c_str());
71 return static_cast<int>(hash);
81 SystemTrace::SystemTrace()
84 SystemTrace::~SystemTrace()
88 void SystemTrace::Trace(const PerformanceMarker& marker, const std::string& traceMessage)
90 PerformanceMarker::MarkerEventType eventType = marker.GetEventType();
92 if(eventType == PerformanceMarker::SINGLE_EVENT)
94 traceMark(TTRACE_TAG_GRAPHICS, traceMessage.c_str());
98 // DALi is multi-threaded so timed events will occur asynchronously
99 std::string markerName;
101 int cookie = GetCookie(traceMessage, markerName);
103 if(eventType == PerformanceMarker::START_TIMED_EVENT)
105 traceAsyncBegin(TTRACE_TAG_GRAPHICS, cookie, markerName.c_str());
109 traceAsyncEnd(TTRACE_TAG_GRAPHICS, cookie, markerName.c_str());
113 } // namespace Adaptor
115 } // namespace Internal