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 // This file provides support for basic in-memory tracing of short events. We | 5 // This file provides support for basic in-memory tracing of short events. We |
6 // keep a static circular buffer where we store the last traced events, so we | 6 // keep a static circular buffer where we store the last traced events, so we |
7 // can review the cache recent behavior should we need it. | 7 // can review the cache recent behavior should we need it. |
8 | 8 |
9 #ifndef NET_DISK_CACHE_TRACE_H__ | 9 #ifndef NET_DISK_CACHE_TRACE_H__ |
10 #define NET_DISK_CACHE_TRACE_H__ | 10 #define NET_DISK_CACHE_TRACE_H__ |
11 #pragma once | 11 #pragma once |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
15 | 15 |
16 namespace disk_cache { | 16 namespace disk_cache { |
17 | 17 |
18 // Create and destroy the tracing buffer. | 18 // Create and destroy the tracing buffer. |
19 void InitTrace(void); | 19 void InitTrace(void); |
20 void DestroyTrace(void); | 20 void DestroyTrace(void); |
21 | 21 |
22 // Simple class to handle the trace buffer lifetime. Any object interested in | 22 // Simple class to handle the trace buffer lifetime. Any object interested in |
23 // tracing should keep a reference to the object returned by GetTraceObject(). | 23 // tracing should keep a reference to the object returned by GetTraceObject(). |
24 class TraceObject : public base::RefCounted<TraceObject> { | 24 class TraceObject : public base::RefCounted<TraceObject> { |
25 friend class base::RefCounted<TraceObject>; | 25 friend class base::RefCounted<TraceObject>; |
26 public: | 26 public: |
27 static TraceObject* GetTraceObject(); | 27 static TraceObject* GetTraceObject(); |
28 | 28 |
29 private: | 29 private: |
30 TraceObject() { | 30 TraceObject(); |
31 InitTrace(); | 31 ~TraceObject(); |
32 } | |
33 | |
34 ~TraceObject() { | |
35 DestroyTrace(); | |
36 } | |
37 DISALLOW_COPY_AND_ASSIGN(TraceObject); | 32 DISALLOW_COPY_AND_ASSIGN(TraceObject); |
38 }; | 33 }; |
39 | 34 |
40 // Traces to the internal buffer. | 35 // Traces to the internal buffer. |
41 void Trace(const char* format, ...); | 36 void Trace(const char* format, ...); |
42 | 37 |
43 } // namespace disk_cache | 38 } // namespace disk_cache |
44 | 39 |
45 #endif // NET_DISK_CACHE_TRACE_H__ | 40 #endif // NET_DISK_CACHE_TRACE_H__ |
OLD | NEW |