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 "system-trace.h"
23 #include <dali/public-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::DebugInfo, "AsyncBegin: %s : cookie %d\n", name, cookie );
41 void traceAsyncEnd(int tag, int cookie, const char *name, ...)
43 Debug::LogMessage(Debug::DebugInfo, "AsyncEnd: %s : cookie %d\n", name, cookie );
45 void traceMark(int tag, const char *name, ...)
47 Debug::LogMessage(Debug::DebugInfo, "Marker: %s \n", name);
49 } // un-named namespace
55 int GetCookie( const std::string& description, std::string& markerName )
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 )
61 pos = description.find("_END");
65 // if this asserts then check the postfix strings in StatContext.cpp for
66 // custom markers and performance-marker.cpp for built-in markers
69 markerName = description.substr( 0, pos );
71 std::size_t hash = Dali::CalculateHash( markerName.c_str() );
72 return static_cast<int>( hash );
85 SystemTrace::SystemTrace()
88 SystemTrace::~SystemTrace()
92 void SystemTrace::Trace( const PerformanceMarker& marker, const std::string& traceMessage )
94 PerformanceMarker::MarkerEventType eventType = marker.GetEventType();
96 if( eventType == PerformanceMarker::SINGLE_EVENT )
98 traceMark( TTRACE_TAG_GRAPHICS, traceMessage.c_str() );
102 // DALi is multi-threaded so timed events will occur asynchronously
103 std::string markerName;
105 int cookie = GetCookie(traceMessage, markerName );
107 if( eventType == PerformanceMarker::START_TIMED_EVENT )
109 traceAsyncBegin( TTRACE_TAG_GRAPHICS, cookie, markerName.c_str() );
113 traceAsyncEnd( TTRACE_TAG_GRAPHICS, cookie, markerName.c_str() );
117 } // namespace Internal
119 } // namespace Adaptor