blob: 5fd5588326d3b75e2de1744558ad5c74eb48bb54 [file] [log] [blame]
[email protected]eb95d3b12013-07-26 06:18:201// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
6#define CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
7
8#include <map>
9#include <string>
10
11#include "base/basictypes.h"
12#include "base/callback.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/memory/weak_ptr.h"
[email protected]eb95d3b12013-07-26 06:18:2015
[email protected]6174a362013-12-03 19:48:1916namespace base {
17
18class RefCountedString;
19class FilePath;
20
21}
[email protected]eb95d3b12013-07-26 06:18:2022// Callback used for getting the output of a trace.
23typedef base::Callback<void(scoped_refptr<base::RefCountedString> trace_data)>
24 TraceDataCallback;
25
[email protected]6174a362013-12-03 19:48:1926// This class is used to manage performance metrics that can be attached to
[email protected]eb95d3b12013-07-26 06:18:2027// feedback reports. This class is a Singleton that is owned by the preference
28// system. It should only be created when it is enabled, and should only be
29// accessed elsewhere via Get().
30//
31// When a performance trace is desired, TracingManager::Get()->RequestTrace()
32// should be invoked. The TracingManager will then start preparing a zipped
33// version of the performance data. That data can then be requested via
34// GetTraceData(). When the data is no longer needed, it should be discarded
35// via DiscardTraceData().
[email protected]6174a362013-12-03 19:48:1936class TracingManager {
[email protected]eb95d3b12013-07-26 06:18:2037 public:
38 virtual ~TracingManager();
39
40 // Create a TracingManager. Can only be called when none exists.
41 static scoped_ptr<TracingManager> Create();
42
43 // Get the current TracingManager. Returns NULL if one doesn't exist.
44 static TracingManager* Get();
45
46 // Request a trace ending at the current time. If a trace is already being
47 // collected, the id for that trace is returned.
48 int RequestTrace();
49
50 // Get the trace data for |id|. On success, true is returned, and the data is
51 // returned via |callback|. Returns false on failure.
52 bool GetTraceData(int id, const TraceDataCallback& callback);
53
54 // Discard the data for trace |id|.
55 void DiscardTraceData(int id);
56
57 private:
[email protected]eb95d3b12013-07-26 06:18:2058 TracingManager();
59
[email protected]6174a362013-12-03 19:48:1960 void StartTracing();
61 void OnTraceDataCollected(const base::FilePath& path);
[email protected]eb95d3b12013-07-26 06:18:2062
63 // ID of the trace that is being collected.
64 int current_trace_id_;
65
66 // Mapping of trace ID to trace data.
67 std::map<int, scoped_refptr<base::RefCountedString> > trace_data_;
68
69 // Callback for the current trace request.
70 TraceDataCallback trace_callback_;
71
72 base::WeakPtrFactory<TracingManager> weak_ptr_factory_;
73
74 DISALLOW_COPY_AND_ASSIGN(TracingManager);
75};
76
77#endif // CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
78