2 * Copyright (c) 2014 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 "kernel-trace.h"
27 #include <dali/integration-api/debug.h>
40 const char* TRACE_MARKER_FILE = "/sys/kernel/debug/tracing/trace_marker";
41 const char* SPI_PREFIX = "SPI_EV_DALI_"; ///< prefix to let the SPI tool know it should read the trace
42 }// un-named name space
44 KernelTrace::KernelTrace()
45 : mFileDescriptor( 0 ),
50 KernelTrace::~KernelTrace()
54 close( mFileDescriptor );
58 // If this function doesn't appear to work, you can test manually on the device.
59 // $ cd /sys/kernel/debug/tracing
61 // If the folder doesn't exist then the kernel needs to be re-built with ftrace enabled
62 // If it does exist, then you can continue to test ftrace is working:
64 // $ echo 1 > tracing_enabled
65 // $ echo "test" > trace_marker
67 // should print out test message
68 // If the message did not get added to the trace, then check you have write permissions to the trace_marker file.
71 void KernelTrace::Trace( const PerformanceMarker& marker, const std::string& traceMessage )
73 // Open the trace_marker file
74 if( mFileDescriptor == 0 )
76 mFileDescriptor = open( TRACE_MARKER_FILE , O_WRONLY);
77 if( mFileDescriptor == -1 )
79 // we want to keep trying to open it, so it will start working if someone fixes
80 // the permissions on the trace marker
83 // first time we fail to open the file, log an error
87 DALI_LOG_ERROR("Failed to open /sys/kernel/debug/tracing/trace_marker for writing please check file permissions.");
93 if( mFileDescriptor > 0 )
95 std::string msg( SPI_PREFIX );
98 int ret = write( mFileDescriptor, msg.c_str(), msg.length() );
99 // if it failed then close the file description and try again next time we trace
102 close( mFileDescriptor );
108 } // namespace Internal
110 } // namespace Adaptor