| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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" | 56 #include "base/lock.h" |
| 57 #include "base/ref_counted.h" | 57 #include "base/ref_counted.h" |
| 58 #include "base/singleton.h" | 58 #include "base/singleton.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 "base/thread_local.h" | |
| 62 #include "remoting/base/protocol/trace.pb.h" | 61 #include "remoting/base/protocol/trace.pb.h" |
| 63 | 62 |
| 64 namespace remoting { | 63 namespace remoting { |
| 65 | 64 |
| 66 class Tracer : public base::RefCountedThreadSafe<Tracer> { | 65 class Tracer : public base::RefCountedThreadSafe<Tracer> { |
| 67 public: | 66 public: |
| 68 // 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 |
| 69 // 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 |
| 70 // 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 |
| 71 // 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 | 84 |
| 86 Lock lock_; | 85 Lock lock_; |
| 87 scoped_ptr<TraceBuffer> buffer_; | 86 scoped_ptr<TraceBuffer> buffer_; |
| 88 | 87 |
| 89 DISALLOW_COPY_AND_ASSIGN(Tracer); | 88 DISALLOW_COPY_AND_ASSIGN(Tracer); |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 class TraceContext { | 91 class TraceContext { |
| 93 public: | 92 public: |
| 94 // Get the current tracer. | 93 // Get the current tracer. |
| 95 static Tracer* tracer() { | 94 static Tracer* tracer(); |
| 96 return Get()->GetTracerInternal(); | |
| 97 } | |
| 98 | 95 |
| 99 static void PushTracer(Tracer* tracer) { | 96 static void PushTracer(Tracer* tracer); |
| 100 Get()->PushTracerInternal(tracer); | |
| 101 } | |
| 102 | 97 |
| 103 static void PopTracer() { | 98 static void PopTracer(); |
| 104 Get()->PopTracerInternal(); | |
| 105 } | |
| 106 | 99 |
| 107 static TraceContext* Get() { | 100 static TraceContext* Get(); |
| 108 TraceContext* context = | |
| 109 Singleton<base::ThreadLocalPointer<TraceContext> >::get()->Get(); | |
| 110 if (context == NULL) { | |
| 111 context = new TraceContext(); | |
| 112 context->PushTracerInternal(new Tracer("default", 0.0)); | |
| 113 Singleton<base::ThreadLocalPointer<TraceContext> >::get()->Set(context); | |
| 114 } | |
| 115 return context; | |
| 116 } | |
| 117 | 101 |
| 118 private: | 102 private: |
| 119 TraceContext() { | 103 TraceContext(); |
| 120 } | |
| 121 | 104 |
| 122 ~TraceContext() {} | 105 ~TraceContext(); |
| 123 | 106 |
| 124 void PushTracerInternal(Tracer* tracer) { tracers_.push_back(tracer); } | 107 void PushTracerInternal(Tracer* tracer); |
| 125 | 108 |
| 126 void PopTracerInternal() { tracers_.pop_back(); } | 109 void PopTracerInternal(); |
| 127 | 110 |
| 128 Tracer* GetTracerInternal() { return tracers_.back(); } | 111 Tracer* GetTracerInternal(); |
| 129 | 112 |
| 130 std::vector<scoped_refptr<Tracer> > tracers_; | 113 std::vector<scoped_refptr<Tracer> > tracers_; |
| 131 | 114 |
| 132 DISALLOW_COPY_AND_ASSIGN(TraceContext); | 115 DISALLOW_COPY_AND_ASSIGN(TraceContext); |
| 133 }; | 116 }; |
| 134 | 117 |
| 135 // Used to create a new tracer that NewRunnableMethod can propogate from. | 118 // Used to create a new tracer that NewRunnableMethod can propogate from. |
| 136 // | 119 // |
| 137 // Declare this at the logical start of a "trace." Calls to NewTracedMethod | 120 // Declare this at the logical start of a "trace." Calls to NewTracedMethod |
| 138 // that are done with the ScopedTracer object is alive will take a reference | 121 // that are done with the ScopedTracer object is alive will take a reference |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 e, f, g)); | 243 e, f, g)); |
| 261 } | 244 } |
| 262 | 245 |
| 263 #else | 246 #else |
| 264 # define NewTracedMethod NewRunnableMethod | 247 # define NewTracedMethod NewRunnableMethod |
| 265 #endif | 248 #endif |
| 266 | 249 |
| 267 } // namespace remoting | 250 } // namespace remoting |
| 268 | 251 |
| 269 #endif // REMOTING_BASE_TRACER_H_ | 252 #endif // REMOTING_BASE_TRACER_H_ |
| OLD | NEW |