OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/external_metrics.h" | 5 #include "chrome/browser/chromeos/external_metrics.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
17 #include "base/metrics/statistics_recorder.h" | 17 #include "base/metrics/statistics_recorder.h" |
18 #include "base/metrics/user_metrics.h" | 18 #include "base/metrics/user_metrics.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/task_scheduler/post_task.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/metrics/chromeos_metrics_provider.h" | 21 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
22 #include "components/metrics/metrics_service.h" | 22 #include "components/metrics/metrics_service.h" |
23 #include "components/metrics/serialization/metric_sample.h" | 23 #include "components/metrics/serialization/metric_sample.h" |
24 #include "components/metrics/serialization/serialization_utils.h" | 24 #include "components/metrics/serialization/serialization_utils.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 | 26 |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
28 | 28 |
29 namespace chromeos { | 29 namespace chromeos { |
(...skipping 11 matching lines...) Expand all Loading... |
41 base::StatisticsRecorder::FindHistogram(name); | 41 base::StatisticsRecorder::FindHistogram(name); |
42 if (!histogram) | 42 if (!histogram) |
43 return true; | 43 return true; |
44 return histogram->HasConstructionArguments(minimum, maximum, bucket_count); | 44 return histogram->HasConstructionArguments(minimum, maximum, bucket_count); |
45 } | 45 } |
46 | 46 |
47 bool CheckLinearValues(const std::string& name, int maximum) { | 47 bool CheckLinearValues(const std::string& name, int maximum) { |
48 return CheckValues(name, 1, maximum, maximum + 1); | 48 return CheckValues(name, 1, maximum, maximum + 1); |
49 } | 49 } |
50 | 50 |
| 51 // The interval between external metrics collections. |
| 52 constexpr base::TimeDelta kExternalMetricsCollectionInterval = |
| 53 base::TimeDelta::FromSeconds(30); |
| 54 constexpr char kEventsFilePath[] = "/var/lib/metrics/uma-events"; |
| 55 |
51 } // namespace | 56 } // namespace |
52 | 57 |
53 // The interval between external metrics collections in seconds | |
54 static const int kExternalMetricsCollectionIntervalSeconds = 30; | |
55 const char kEventsFilePath[] = "/var/lib/metrics/uma-events"; | |
56 | |
57 ExternalMetrics::ExternalMetrics() : uma_events_file_(kEventsFilePath) { | 58 ExternalMetrics::ExternalMetrics() : uma_events_file_(kEventsFilePath) { |
58 } | 59 } |
59 | 60 |
60 ExternalMetrics::~ExternalMetrics() {} | 61 ExternalMetrics::~ExternalMetrics() {} |
61 | 62 |
62 void ExternalMetrics::Start() { | 63 void ExternalMetrics::Start() { |
63 ScheduleCollector(); | 64 ScheduleCollector(); |
64 } | 65 } |
65 | 66 |
66 // static | 67 // static |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 165 |
165 return samples.size(); | 166 return samples.size(); |
166 } | 167 } |
167 | 168 |
168 void ExternalMetrics::CollectEventsAndReschedule() { | 169 void ExternalMetrics::CollectEventsAndReschedule() { |
169 CollectEvents(); | 170 CollectEvents(); |
170 ScheduleCollector(); | 171 ScheduleCollector(); |
171 } | 172 } |
172 | 173 |
173 void ExternalMetrics::ScheduleCollector() { | 174 void ExternalMetrics::ScheduleCollector() { |
174 bool result = BrowserThread::GetBlockingPool()->PostDelayedWorkerTask( | 175 base::PostDelayedTaskWithTraits( |
175 FROM_HERE, | 176 FROM_HERE, |
176 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), | 177 base::TaskTraits().MayBlock().WithPriority( |
177 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); | 178 base::TaskPriority::BACKGROUND), |
178 DCHECK(result); | 179 base::BindOnce(&chromeos::ExternalMetrics::CollectEventsAndReschedule, |
| 180 this), |
| 181 kExternalMetricsCollectionInterval); |
179 } | 182 } |
180 | 183 |
181 } // namespace chromeos | 184 } // namespace chromeos |
OLD | NEW |