• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <gtest/gtest.h>  // for FRIEND_TEST
6 #include <linux/limits.h>
7 
8 #include "include/macros.h"
9 
10 #ifndef GESTURES_TRACE_MARKER_H__
11 #define GESTURES_TRACE_MARKER_H__
12 
13 #define TRACE_WRITE(x) TraceMarker::StaticTraceWrite(x)
14 
15 namespace gestures {
16 // This class is used for writing message into the debugfs tracing system
17 // based on Ftrace provided by linux.
18 // By default, the debugfs is mounted at /sys/kernel/debug/
19 // It will automatically help you handle the detail things. If you want to
20 // write a message into tracing system, you can simply use
21 // TRACE_WRITE("MESSAGE") and you can find the message appears in the file
22 // debugfs/tracing/trace
23 
24 class TraceMarker {
25   FRIEND_TEST(TraceMarkerTest, DeleteTraceMarkerTest);
26 
27  public:
28   static void CreateTraceMarker();
29   static void DeleteTraceMarker();
30   static void StaticTraceWrite(const char* str);
31   static TraceMarker* GetTraceMarker();
32   void TraceWrite(const char* str);
33 
34  private:
35   TraceMarker();
36   ~TraceMarker();
37   DISALLOW_COPY_AND_ASSIGN(TraceMarker);
38   static TraceMarker* trace_marker_;
39   static int trace_marker_count_;
40   int fd_;
41   bool FindDebugfs(const char** ret) const;
42   bool FindTraceMarker(char** ret) const;
43   bool OpenTraceMarker();
44 };
45 }  // namespace gestures
46 #endif  // GESTURES_TRACE_MARKER_H__
47