OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Tracer objects uresed to record an annotated timeline of events for use in | 5 // Tracer objects uresed to record an annotated timeline of events for use in |
6 // gathering performance data. It wraps a TraceBuffer which is the raw data | 6 // gathering performance data. It wraps a TraceBuffer which is the raw data |
7 // for a trace. Tracer is threadsafe. | 7 // for a trace. Tracer is threadsafe. |
8 // | 8 // |
9 // TraceContext is a singleton that is used to give information for the current | 9 // TraceContext is a singleton that is used to give information for the current |
10 // trace. Clients should query TraceContext to find the current tracer and then | 10 // trace. Clients should query TraceContext to find the current tracer and then |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // For each call of StartDecode(), the related calls to OnFrameOutput() and | 46 // For each call of StartDecode(), the related calls to OnFrameOutput() and |
47 // DecodeDone() will be annotated to the Tracer created by the ScopedTracer | 47 // DecodeDone() will be annotated to the Tracer created by the ScopedTracer |
48 // declaration allowing for creating of timing information over the related | 48 // declaration allowing for creating of timing information over the related |
49 // asynchronous Task invocations. | 49 // asynchronous Task invocations. |
50 | 50 |
51 #ifndef REMOTING_BASE_TRACER_H_ | 51 #ifndef REMOTING_BASE_TRACER_H_ |
52 #define REMOTING_BASE_TRACER_H_ | 52 #define REMOTING_BASE_TRACER_H_ |
53 | 53 |
54 #include <string> | 54 #include <string> |
55 | 55 |
56 #include "base/lock.h" | |
57 #include "base/ref_counted.h" | 56 #include "base/ref_counted.h" |
58 #include "base/singleton.h" | 57 #include "base/singleton.h" |
| 58 #include "base/synchronization/lock.h" |
59 #include "base/task.h" | 59 #include "base/task.h" |
60 #include "base/scoped_ptr.h" | 60 #include "base/scoped_ptr.h" |
61 #include "remoting/proto/trace.pb.h" | 61 #include "remoting/proto/trace.pb.h" |
62 | 62 |
63 namespace remoting { | 63 namespace remoting { |
64 | 64 |
65 class Tracer : public base::RefCountedThreadSafe<Tracer> { | 65 class Tracer : public base::RefCountedThreadSafe<Tracer> { |
66 public: | 66 public: |
67 // The |name| is just a label for the given tracer. It is recorder into the | 67 // The |name| is just a label for the given tracer. It is recorder into the |
68 // trace buffer and printed at the end. Use it specify one logical flow such | 68 // trace buffer and printed at the end. Use it specify one logical flow such |
69 // as "Host Update Request". The sample_percent is to allow for gathering a | 69 // as "Host Update Request". The sample_percent is to allow for gathering a |
70 // random sampling of the traces. This allows the tracer to be used in a | 70 // random sampling of the traces. This allows the tracer to be used in a |
71 // high-frequency code path without spamming the log, or putting undo load on | 71 // high-frequency code path without spamming the log, or putting undo load on |
72 // the system. Use 0.0 to disable the tracer completely, and 1.0 to log | 72 // the system. Use 0.0 to disable the tracer completely, and 1.0 to log |
73 // everything. | 73 // everything. |
74 Tracer(const std::string& name, double sample_percent); | 74 Tracer(const std::string& name, double sample_percent); |
75 | 75 |
76 // TODO(ajwong): Consider using an ostream interface similar to DLOG. | 76 // TODO(ajwong): Consider using an ostream interface similar to DLOG. |
77 void PrintString(const std::string& s); | 77 void PrintString(const std::string& s); |
78 | 78 |
79 void OutputTrace(); | 79 void OutputTrace(); |
80 | 80 |
81 private: | 81 private: |
82 friend class base::RefCountedThreadSafe<Tracer>; | 82 friend class base::RefCountedThreadSafe<Tracer>; |
83 virtual ~Tracer(); | 83 virtual ~Tracer(); |
84 | 84 |
85 Lock lock_; | 85 base::Lock lock_; |
86 scoped_ptr<TraceBuffer> buffer_; | 86 scoped_ptr<TraceBuffer> buffer_; |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(Tracer); | 88 DISALLOW_COPY_AND_ASSIGN(Tracer); |
89 }; | 89 }; |
90 | 90 |
91 class TraceContext { | 91 class TraceContext { |
92 public: | 92 public: |
93 // Get the current tracer. | 93 // Get the current tracer. |
94 static Tracer* tracer(); | 94 static Tracer* tracer(); |
95 | 95 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 e, f, g)); | 243 e, f, g)); |
244 } | 244 } |
245 | 245 |
246 #else | 246 #else |
247 # define NewTracedMethod NewRunnableMethod | 247 # define NewTracedMethod NewRunnableMethod |
248 #endif | 248 #endif |
249 | 249 |
250 } // namespace remoting | 250 } // namespace remoting |
251 | 251 |
252 #endif // REMOTING_BASE_TRACER_H_ | 252 #endif // REMOTING_BASE_TRACER_H_ |
OLD | NEW |