OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ | 5 #ifndef COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ |
6 #define COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ | 6 #define COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequence_checker.h" |
14 #include "base/threading/thread_checker.h" | |
15 #include "components/metrics/metrics_provider.h" | 14 #include "components/metrics/metrics_provider.h" |
16 #include "components/metrics/proto/system_profile.pb.h" | 15 #include "components/metrics/proto/system_profile.pb.h" |
17 | 16 |
18 namespace base { | 17 namespace base { |
19 class FilePath; | 18 class FilePath; |
20 } | 19 } |
21 | 20 |
22 namespace metrics { | 21 namespace metrics { |
23 | 22 |
24 // Provides metrics about the local drives on a user's computer. Currently only | 23 // Provides metrics about the local drives on a user's computer. Currently only |
25 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs). | 24 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs). |
26 // | |
27 // Defers gathering metrics until after "rush hour" (startup) so as to not bog | |
28 // down the file thread. | |
29 class DriveMetricsProvider : public metrics::MetricsProvider { | 25 class DriveMetricsProvider : public metrics::MetricsProvider { |
30 public: | 26 public: |
31 DriveMetricsProvider(scoped_refptr<base::SequencedTaskRunner> file_thread, | 27 DriveMetricsProvider(int local_state_path_key); |
Alexei Svitkine (slow)
2017/06/29 20:54:15
explicit
Ilya Sherman
2017/06/30 03:06:41
Ah, right, good call. Done.
| |
32 int local_state_path_key); | |
33 ~DriveMetricsProvider() override; | 28 ~DriveMetricsProvider() override; |
34 | 29 |
35 // metrics::MetricsDataProvider: | 30 // metrics::MetricsDataProvider: |
36 void ProvideSystemProfileMetrics( | 31 void ProvideSystemProfileMetrics( |
37 metrics::SystemProfileProto* system_profile_proto) override; | 32 metrics::SystemProfileProto* system_profile_proto) override; |
38 | 33 |
39 // Called to start gathering metrics. | 34 // Called to start gathering metrics. |
40 void GetDriveMetrics(const base::Closure& done_callback); | 35 void GetDriveMetrics(const base::Closure& done_callback); |
41 | 36 |
42 private: | 37 private: |
(...skipping 10 matching lines...) Expand all Loading... | |
53 struct DriveMetrics { | 48 struct DriveMetrics { |
54 SeekPenaltyResponse app_drive; | 49 SeekPenaltyResponse app_drive; |
55 SeekPenaltyResponse user_data_drive; | 50 SeekPenaltyResponse user_data_drive; |
56 }; | 51 }; |
57 | 52 |
58 // Determine whether the device that services |path| has a seek penalty. | 53 // Determine whether the device that services |path| has a seek penalty. |
59 // Returns false if it couldn't be determined (e.g., |path| doesn't exist). | 54 // Returns false if it couldn't be determined (e.g., |path| doesn't exist). |
60 static bool HasSeekPenalty(const base::FilePath& path, | 55 static bool HasSeekPenalty(const base::FilePath& path, |
61 bool* has_seek_penalty); | 56 bool* has_seek_penalty); |
62 | 57 |
63 // Gather metrics about various drives on |file_thread_|. | 58 // Gather metrics about various drives. Should be run on a background thread. |
64 static DriveMetrics GetDriveMetricsOnFileThread(int local_state_path_key); | 59 static DriveMetrics GetDriveMetricsOnBackgroundThread( |
60 int local_state_path_key); | |
65 | 61 |
66 // Tries to determine whether there is a penalty for seeking on the drive that | 62 // Tries to determine whether there is a penalty for seeking on the drive that |
67 // hosts |path_service_key| (for example: the drive that holds "Local State"). | 63 // hosts |path_service_key| (for example: the drive that holds "Local State"). |
68 static void QuerySeekPenalty(int path_service_key, | 64 static void QuerySeekPenalty(int path_service_key, |
69 SeekPenaltyResponse* response); | 65 SeekPenaltyResponse* response); |
70 | 66 |
71 // Called when metrics are done being gathered from the FILE thread. | 67 // Called when metrics are done being gathered asynchronously. |
72 // |done_callback| is the callback that should be called once all metrics are | 68 // |done_callback| is the callback that should be called once all metrics are |
73 // gathered. | 69 // gathered. |
74 void GotDriveMetrics(const base::Closure& done_callback, | 70 void GotDriveMetrics(const base::Closure& done_callback, |
75 const DriveMetrics& metrics); | 71 const DriveMetrics& metrics); |
76 | 72 |
77 // Fills |drive| with information from successful |response|s. | 73 // Fills |drive| with information from successful |response|s. |
78 void FillDriveMetrics(const SeekPenaltyResponse& response, | 74 void FillDriveMetrics(const SeekPenaltyResponse& response, |
79 metrics::SystemProfileProto::Hardware::Drive* drive); | 75 metrics::SystemProfileProto::Hardware::Drive* drive); |
80 | 76 |
81 // The thread on which file operations are performed (supplied by the | |
82 // embedder). | |
83 scoped_refptr<base::SequencedTaskRunner> file_thread_; | |
84 | |
85 // The key to give to base::PathService to obtain the path to local state | 77 // The key to give to base::PathService to obtain the path to local state |
86 // (supplied by the embedder). | 78 // (supplied by the embedder). |
87 int local_state_path_key_; | 79 int local_state_path_key_; |
88 | 80 |
89 // Information gathered about various important drives. | 81 // Information gathered about various important drives. |
90 DriveMetrics metrics_; | 82 DriveMetrics metrics_; |
91 | 83 |
92 base::ThreadChecker thread_checker_; | 84 SEQUENCE_CHECKER(sequence_checker_); |
93 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; | 85 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; |
94 | 86 |
95 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); | 87 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); |
96 }; | 88 }; |
97 | 89 |
98 } // namespace metrics | 90 } // namespace metrics |
99 | 91 |
100 #endif // COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ | 92 #endif // COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ |
OLD | NEW |