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_
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"
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
{
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
);
34 // Indicates that we are ready to collect perf data.
37 // Indicates that we are ready to upload perf data.
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()
47 void CollectIfNecessary();
49 // Collects perf data by calling CollectIfNecessary() and reschedules it to be
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.
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
);
77 #endif // CHROME_BROWSER_METRICS_PERF_PROVIDER_CHROMEOS_H_