Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / perf_provider_chromeos.h
blob6ba943e0880dbe202536cb720b75fab1126c630f
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_
6 #define CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "chrome/common/metrics/proto/perf_data.pb.h"
16 namespace metrics {
18 class WindowedIncognitoObserver;
20 // Provides access to ChromeOS perf data. perf aka "perf events" is a
21 // performance profiling infrastructure built into the linux kernel. For more
22 // information, see: https://perf.wiki.kernel.org/index.php/Main_Page.
23 class PerfProvider : public base::NonThreadSafe {
24 public:
25 PerfProvider();
26 ~PerfProvider();
28 // Gets the collected perf data protobuf and writes it to |perf_data_proto|.
29 // Returns true if it wrote to |perf_data_proto|.
30 bool GetPerfData(PerfDataProto* perf_data_proto);
32 private:
33 enum PerfDataState {
34 // Indicates that we are ready to collect perf data.
35 READY_TO_COLLECT,
37 // Indicates that we are ready to upload perf data.
38 READY_TO_UPLOAD,
41 // Starts an internal timer to start collecting perf data. The timer is set to
42 // trigger |interval| after this function call.
43 void ScheduleCollection(const base::TimeDelta& interval);
45 // Collects perf data if it has not been consumed by calling GetPerfData()
46 // (see above).
47 void CollectIfNecessary();
49 // Collects perf data by calling CollectIfNecessary() and reschedules it to be
50 // collected again.
51 void CollectIfNecessaryAndReschedule();
53 // Parses a protobuf from the |data| passed in only if the
54 // |incognito_observer| indicates that no incognito window had been opened
55 // during the profile collection period.
56 void ParseProtoIfValid(
57 scoped_ptr<WindowedIncognitoObserver> incognito_observer,
58 const std::vector<uint8>& data);
60 // The internal state can be one of the enum values above.
61 PerfDataState state_;
63 // Protobuf that has the perf data.
64 PerfDataProto perf_data_proto_;
66 // For scheduling collection of perf data.
67 base::OneShotTimer<PerfProvider> timer_;
69 // To pass around the "this" pointer across threads safely.
70 base::WeakPtrFactory<PerfProvider> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(PerfProvider);
75 } // namespace system
77 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_