Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/metrics/perf_provider_chromeos.cc

Issue 1218583002: metrics: Add dbus interface for GetRandomPerfOutput (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check that the dbus method returns some data Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 // Returns true if a normal user is logged in. Returns false otherwise (e.g. if 88 // Returns true if a normal user is logged in. Returns false otherwise (e.g. if
89 // logged in as a guest or as a kiosk app). 89 // logged in as a guest or as a kiosk app).
90 bool IsNormalUserLoggedIn() { 90 bool IsNormalUserLoggedIn() {
91 return chromeos::LoginState::Get()->IsUserAuthenticated(); 91 return chromeos::LoginState::Get()->IsUserAuthenticated();
92 } 92 }
93 93
94 } // namespace 94 } // namespace
95 95
96
97 namespace metrics { 96 namespace metrics {
98 97
99 // This class must be created and used on the UI thread. It watches for any 98 // This class must be created and used on the UI thread. It watches for any
100 // incognito window being opened from the time it is instantiated to the time it 99 // incognito window being opened from the time it is instantiated to the time it
101 // is destroyed. 100 // is destroyed.
102 class WindowedIncognitoObserver : public chrome::BrowserListObserver { 101 class WindowedIncognitoObserver : public chrome::BrowserListObserver {
103 public: 102 public:
104 WindowedIncognitoObserver() : incognito_launched_(false) { 103 WindowedIncognitoObserver() : incognito_launched_(false) {
105 BrowserList::AddObserver(this); 104 BrowserList::AddObserver(this);
106 } 105 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 313
315 scoped_ptr<WindowedIncognitoObserver> incognito_observer( 314 scoped_ptr<WindowedIncognitoObserver> incognito_observer(
316 new WindowedIncognitoObserver); 315 new WindowedIncognitoObserver);
317 316
318 chromeos::DebugDaemonClient* client = 317 chromeos::DebugDaemonClient* client =
319 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); 318 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
320 319
321 base::TimeDelta collection_duration = base::TimeDelta::FromSeconds( 320 base::TimeDelta collection_duration = base::TimeDelta::FromSeconds(
322 kPerfCommandDurationDefaultSeconds); 321 kPerfCommandDurationDefaultSeconds);
323 322
324 client->GetPerfData(collection_duration.InSeconds(), 323 client->GetPerfOutput(
325 base::Bind(&PerfProvider::ParseProtoIfValid, 324 collection_duration.InSeconds(),
326 weak_factory_.GetWeakPtr(), 325 base::Bind(&PerfProvider::ParseOutputProtoIfValid,
327 base::Passed(&incognito_observer), 326 weak_factory_.GetWeakPtr(), base::Passed(&incognito_observer),
328 base::Passed(&sampled_profile))); 327 base::Passed(&sampled_profile)));
329 } 328 }
330 329
331 void PerfProvider::DoPeriodicCollection() { 330 void PerfProvider::DoPeriodicCollection() {
332 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); 331 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile);
333 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); 332 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION);
334 333
335 CollectIfNecessary(sampled_profile.Pass()); 334 CollectIfNecessary(sampled_profile.Pass());
336 } 335 }
337 336
338 void PerfProvider::CollectPerfDataAfterResume( 337 void PerfProvider::CollectPerfDataAfterResume(
(...skipping 14 matching lines...) Expand all
353 // Fill out a SampledProfile protobuf that will contain the collected data. 352 // Fill out a SampledProfile protobuf that will contain the collected data.
354 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); 353 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile);
355 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); 354 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION);
356 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); 355 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds());
357 sampled_profile->set_num_tabs_restored(num_tabs_restored); 356 sampled_profile->set_num_tabs_restored(num_tabs_restored);
358 357
359 CollectIfNecessary(sampled_profile.Pass()); 358 CollectIfNecessary(sampled_profile.Pass());
360 last_session_restore_collection_time_ = base::TimeTicks::Now(); 359 last_session_restore_collection_time_ = base::TimeTicks::Now();
361 } 360 }
362 361
363 void PerfProvider::ParseProtoIfValid( 362 void PerfProvider::ParseOutputProtoIfValid(
364 scoped_ptr<WindowedIncognitoObserver> incognito_observer, 363 scoped_ptr<WindowedIncognitoObserver> incognito_observer,
365 scoped_ptr<SampledProfile> sampled_profile, 364 scoped_ptr<SampledProfile> sampled_profile_ptr,
366 const std::vector<uint8>& data) { 365 int result,
366 const std::vector<uint8>& perf_data,
367 const std::vector<uint8>& perf_stat) {
367 DCHECK(CalledOnValidThread()); 368 DCHECK(CalledOnValidThread());
368 369
369 if (incognito_observer->incognito_launched()) { 370 if (incognito_observer->incognito_launched()) {
370 AddToPerfHistogram(INCOGNITO_LAUNCHED); 371 AddToPerfHistogram(INCOGNITO_LAUNCHED);
371 return; 372 return;
372 } 373 }
373 374
374 PerfDataProto perf_data_proto; 375 if (result != 0 || (perf_data.empty() || perf_stat.empty())) {
Ilya Sherman 2015/06/27 05:44:24 nit: Should the second || be an &&? If so, please
Simon Que 2015/06/30 05:28:09 Done.
375 if (!perf_data_proto.ParseFromArray(data.data(), data.size())) {
376 AddToPerfHistogram(PROTOBUF_NOT_PARSED); 376 AddToPerfHistogram(PROTOBUF_NOT_PARSED);
377 return; 377 return;
378 } 378 }
379 379
380 // Populate a profile collection protobuf with the collected perf data and 380 // If output data in either PerfDataProto or PerfStatProto format was
381 // extra metadata. 381 // returned, store it in the corresponding field in SampledProfile.
382 cached_perf_data_.resize(cached_perf_data_.size() + 1); 382 SampledProfile& sampled_profile = *sampled_profile_ptr.get();
Ilya Sherman 2015/06/27 05:44:24 Erm, why don't you just use the arrow operator? W
Simon Que 2015/06/30 05:50:48 Done.
383 SampledProfile& collection_data = cached_perf_data_.back();
384 collection_data.Swap(sampled_profile.get());
385 383
386 // Fill out remaining fields of the SampledProfile protobuf. 384 if (!perf_data.empty()) {
387 collection_data.set_ms_after_boot( 385 PerfDataProto perf_data_proto;
388 perf_data_proto.timestamp_sec() * base::Time::kMillisecondsPerSecond); 386 if (!perf_data_proto.ParseFromArray(perf_data.data(), perf_data.size())) {
387 AddToPerfHistogram(PROTOBUF_NOT_PARSED);
388 return;
Ilya Sherman 2015/06/27 05:44:24 Is it appropriate to discard the perf_stat array i
Simon Que 2015/06/30 05:50:48 Good question. That's easy enough to deal with, bu
389 }
390 sampled_profile.set_ms_after_boot(perf_data_proto.timestamp_sec() *
391 base::Time::kMillisecondsPerSecond);
392 sampled_profile.mutable_perf_data()->Swap(&perf_data_proto);
393 }
394
395 if (!perf_stat.empty()) {
396 PerfStatProto perf_stat_proto;
397 if (!perf_stat_proto.ParseFromArray(perf_stat.data(), perf_stat.size())) {
398 AddToPerfHistogram(PROTOBUF_NOT_PARSED);
399 return;
400 }
401 // TODO(sque): Do we want to store |sampled_profile.ms_after_boot| for perf
402 // stat?
Ilya Sherman 2015/06/27 05:44:24 Are you planning to address this TODO as part of t
Simon Que 2015/06/30 05:50:48 This is actually wrong. The timestamp is time sinc
Ilya Sherman 2015/07/01 03:09:01 Sorry, what is actually wrong? Is the ms_after_bo
403 sampled_profile.mutable_perf_stat()->Swap(&perf_stat_proto);
404 }
389 405
390 DCHECK(!login_time_.is_null()); 406 DCHECK(!login_time_.is_null());
391 collection_data. 407 sampled_profile.set_ms_after_login(
392 set_ms_after_login((base::TimeTicks::Now() - login_time_) 408 (base::TimeTicks::Now() - login_time_).InMilliseconds());
393 .InMilliseconds());
394 409
395 // Finally, store the perf data itself. 410 // Add the collected data to the container of collected SampledProfiles.
396 collection_data.mutable_perf_data()->Swap(&perf_data_proto); 411 cached_perf_data_.resize(cached_perf_data_.size() + 1);
412 cached_perf_data_.back().Swap(&sampled_profile);
397 } 413 }
398 414
399 } // namespace metrics 415 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698