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/metrics/perf/perf_provider_chromeos.h" | 5 #include "chrome/browser/metrics/perf/perf_provider_chromeos.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 #include <map> | 10 #include <map> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/bind.h" | 13 #include "base/bind.h" |
12 #include "base/callback.h" | 14 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
14 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
16 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Returns a random TimeDelta between zero and |max|. | 74 // Returns a random TimeDelta between zero and |max|. |
73 base::TimeDelta RandomTimeDelta(base::TimeDelta max) { | 75 base::TimeDelta RandomTimeDelta(base::TimeDelta max) { |
74 return base::TimeDelta::FromMicroseconds( | 76 return base::TimeDelta::FromMicroseconds( |
75 base::RandGenerator(max.InMicroseconds())); | 77 base::RandGenerator(max.InMicroseconds())); |
76 } | 78 } |
77 | 79 |
78 // Gets parameter named by |key| from the map. If it is present and is an | 80 // Gets parameter named by |key| from the map. If it is present and is an |
79 // integer, stores the result in |out| and return true. Otherwise return false. | 81 // integer, stores the result in |out| and return true. Otherwise return false. |
80 bool GetInt64Param(const std::map<std::string, std::string>& params, | 82 bool GetInt64Param(const std::map<std::string, std::string>& params, |
81 const std::string& key, | 83 const std::string& key, |
82 int64* out) { | 84 int64_t* out) { |
83 auto it = params.find(key); | 85 auto it = params.find(key); |
84 if (it == params.end()) | 86 if (it == params.end()) |
85 return false; | 87 return false; |
86 int64 value; | 88 int64_t value; |
87 // NB: StringToInt64 will set value even if the conversion fails. | 89 // NB: StringToInt64 will set value even if the conversion fails. |
88 if (!base::StringToInt64(it->second, &value)) | 90 if (!base::StringToInt64(it->second, &value)) |
89 return false; | 91 return false; |
90 *out = value; | 92 *out = value; |
91 return true; | 93 return true; |
92 } | 94 } |
93 | 95 |
94 // Parses the key. e.g.: "PerfCommand::arm::0" returns "arm" | 96 // Parses the key. e.g.: "PerfCommand::arm::0" returns "arm" |
95 bool ExtractPerfCommandCpuSpecifier(const std::string& key, | 97 bool ExtractPerfCommandCpuSpecifier(const std::string& key, |
96 std::string* cpu_specifier) { | 98 std::string* cpu_specifier) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::TimeDelta periodic_interval, | 195 base::TimeDelta periodic_interval, |
194 TriggerParams resume_from_suspend, | 196 TriggerParams resume_from_suspend, |
195 TriggerParams restore_session) | 197 TriggerParams restore_session) |
196 : collection_duration_(collection_duration.ToInternalValue()), | 198 : collection_duration_(collection_duration.ToInternalValue()), |
197 periodic_interval_(periodic_interval.ToInternalValue()), | 199 periodic_interval_(periodic_interval.ToInternalValue()), |
198 resume_from_suspend_(resume_from_suspend), | 200 resume_from_suspend_(resume_from_suspend), |
199 restore_session_(restore_session) { | 201 restore_session_(restore_session) { |
200 } | 202 } |
201 | 203 |
202 PerfProvider::CollectionParams::TriggerParams::TriggerParams( | 204 PerfProvider::CollectionParams::TriggerParams::TriggerParams( |
203 int64 sampling_factor, | 205 int64_t sampling_factor, |
204 base::TimeDelta max_collection_delay) | 206 base::TimeDelta max_collection_delay) |
205 : sampling_factor_(sampling_factor), | 207 : sampling_factor_(sampling_factor), |
206 max_collection_delay_(max_collection_delay.ToInternalValue()) { | 208 max_collection_delay_(max_collection_delay.ToInternalValue()) {} |
207 } | |
208 | 209 |
209 const PerfProvider::CollectionParams PerfProvider::kDefaultParameters( | 210 const PerfProvider::CollectionParams PerfProvider::kDefaultParameters( |
210 /* collection_duration = */ base::TimeDelta::FromSeconds(2), | 211 /* collection_duration = */ base::TimeDelta::FromSeconds(2), |
211 /* periodic_interval = */ base::TimeDelta::FromHours(3), | 212 /* periodic_interval = */ base::TimeDelta::FromHours(3), |
212 /* resume_from_suspend = */ PerfProvider::CollectionParams::TriggerParams( | 213 /* resume_from_suspend = */ PerfProvider::CollectionParams::TriggerParams( |
213 /* sampling_factor = */ 10, | 214 /* sampling_factor = */ 10, |
214 /* max_collection_delay = */ base::TimeDelta::FromSeconds(5)), | 215 /* max_collection_delay = */ base::TimeDelta::FromSeconds(5)), |
215 /* restore_session = */ PerfProvider::CollectionParams::TriggerParams( | 216 /* restore_session = */ PerfProvider::CollectionParams::TriggerParams( |
216 /* sampling_factor = */ 10, | 217 /* sampling_factor = */ 10, |
217 /* max_collection_delay = */ base::TimeDelta::FromSeconds(10))); | 218 /* max_collection_delay = */ base::TimeDelta::FromSeconds(10))); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 ret = cpu_specifier; | 301 ret = cpu_specifier; |
301 } | 302 } |
302 } | 303 } |
303 return ret; | 304 return ret; |
304 } | 305 } |
305 | 306 |
306 } // namespace internal | 307 } // namespace internal |
307 | 308 |
308 void PerfProvider::SetCollectionParamsFromVariationParams( | 309 void PerfProvider::SetCollectionParamsFromVariationParams( |
309 const std::map<std::string, std::string>& params) { | 310 const std::map<std::string, std::string>& params) { |
310 int64 value; | 311 int64_t value; |
311 if (GetInt64Param(params, "ProfileCollectionDurationSec", &value)) { | 312 if (GetInt64Param(params, "ProfileCollectionDurationSec", &value)) { |
312 collection_params_.set_collection_duration( | 313 collection_params_.set_collection_duration( |
313 base::TimeDelta::FromSeconds(value)); | 314 base::TimeDelta::FromSeconds(value)); |
314 } | 315 } |
315 if (GetInt64Param(params, "PeriodicProfilingIntervalMs", &value)) { | 316 if (GetInt64Param(params, "PeriodicProfilingIntervalMs", &value)) { |
316 collection_params_.set_periodic_interval( | 317 collection_params_.set_periodic_interval( |
317 base::TimeDelta::FromMilliseconds(value)); | 318 base::TimeDelta::FromMilliseconds(value)); |
318 } | 319 } |
319 if (GetInt64Param(params, "ResumeFromSuspend::SamplingFactor", &value)) { | 320 if (GetInt64Param(params, "ResumeFromSuspend::SamplingFactor", &value)) { |
320 collection_params_.mutable_resume_from_suspend() | 321 collection_params_.mutable_resume_from_suspend() |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 cached_perf_data_.clear(); | 376 cached_perf_data_.clear(); |
376 | 377 |
377 AddToPerfHistogram(SUCCESS); | 378 AddToPerfHistogram(SUCCESS); |
378 return true; | 379 return true; |
379 } | 380 } |
380 | 381 |
381 void PerfProvider::ParseOutputProtoIfValid( | 382 void PerfProvider::ParseOutputProtoIfValid( |
382 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 383 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
383 scoped_ptr<SampledProfile> sampled_profile, | 384 scoped_ptr<SampledProfile> sampled_profile, |
384 int result, | 385 int result, |
385 const std::vector<uint8>& perf_data, | 386 const std::vector<uint8_t>& perf_data, |
386 const std::vector<uint8>& perf_stat) { | 387 const std::vector<uint8_t>& perf_stat) { |
387 DCHECK(CalledOnValidThread()); | 388 DCHECK(CalledOnValidThread()); |
388 | 389 |
389 if (incognito_observer->incognito_launched()) { | 390 if (incognito_observer->incognito_launched()) { |
390 AddToPerfHistogram(INCOGNITO_LAUNCHED); | 391 AddToPerfHistogram(INCOGNITO_LAUNCHED); |
391 return; | 392 return; |
392 } | 393 } |
393 | 394 |
394 if (result != 0 || (perf_data.empty() && perf_stat.empty())) { | 395 if (result != 0 || (perf_data.empty() && perf_stat.empty())) { |
395 AddToPerfHistogram(PROTOBUF_NOT_PARSED); | 396 AddToPerfHistogram(PROTOBUF_NOT_PARSED); |
396 return; | 397 return; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 614 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
614 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 615 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
615 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); | 616 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); |
616 sampled_profile->set_num_tabs_restored(num_tabs_restored); | 617 sampled_profile->set_num_tabs_restored(num_tabs_restored); |
617 | 618 |
618 CollectIfNecessary(sampled_profile.Pass()); | 619 CollectIfNecessary(sampled_profile.Pass()); |
619 last_session_restore_collection_time_ = base::TimeTicks::Now(); | 620 last_session_restore_collection_time_ = base::TimeTicks::Now(); |
620 } | 621 } |
621 | 622 |
622 } // namespace metrics | 623 } // namespace metrics |
OLD | NEW |