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

Side by Side Diff: components/startup_metric_utils/browser/startup_metric_utils.cc

Issue 2215513002: Reland #1: "base: Implement GetCurrentThreadPriority." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REbase error. Created 4 years, 4 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
« no previous file with comments | « base/threading/platform_thread_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/startup_metric_utils/browser/startup_metric_utils.h" 5 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // also the time taken to synchronously resolve base::Time::Now() and 309 // also the time taken to synchronously resolve base::Time::Now() and
310 // base::TimeTicks::Now() at play, but in practice it is pretty much instant 310 // base::TimeTicks::Now() at play, but in practice it is pretty much instant
311 // compared to multi-seconds startup timings. 311 // compared to multi-seconds startup timings.
312 base::TimeTicks StartupTimeToTimeTicks(const base::Time& time) { 312 base::TimeTicks StartupTimeToTimeTicks(const base::Time& time) {
313 // First get a base which represents the same point in time in both units. 313 // First get a base which represents the same point in time in both units.
314 // Bump the priority of this thread while doing this as the wall clock time it 314 // Bump the priority of this thread while doing this as the wall clock time it
315 // takes to resolve these two calls affects the precision of this method and 315 // takes to resolve these two calls affects the precision of this method and
316 // bumping the priority reduces the likelihood of a context switch interfering 316 // bumping the priority reduces the likelihood of a context switch interfering
317 // with this computation. 317 // with this computation.
318 318
319 // Enabling this logic on OS X causes a significant performance regression.
320 // https://crbug.com/601270
321 #if !defined(OS_MACOSX)
322 static bool statics_initialized = false; 319 static bool statics_initialized = false;
323 320
324 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; 321 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL;
325 if (!statics_initialized) { 322 if (!statics_initialized) {
326 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); 323 previous_priority = base::PlatformThread::GetCurrentThreadPriority();
327 base::PlatformThread::SetCurrentThreadPriority( 324 base::PlatformThread::SetCurrentThreadPriority(
328 base::ThreadPriority::DISPLAY); 325 base::ThreadPriority::DISPLAY);
329 } 326 }
330 #endif
331 327
332 static const base::Time time_base = base::Time::Now(); 328 static const base::Time time_base = base::Time::Now();
333 static const base::TimeTicks trace_ticks_base = base::TimeTicks::Now(); 329 static const base::TimeTicks trace_ticks_base = base::TimeTicks::Now();
334 330
335 #if !defined(OS_MACOSX)
336 if (!statics_initialized) { 331 if (!statics_initialized) {
337 base::PlatformThread::SetCurrentThreadPriority(previous_priority); 332 base::PlatformThread::SetCurrentThreadPriority(previous_priority);
338 } 333 }
339 statics_initialized = true; 334 statics_initialized = true;
340 #endif
341 335
342 // Then use the TimeDelta common ground between the two units to make the 336 // Then use the TimeDelta common ground between the two units to make the
343 // conversion. 337 // conversion.
344 const base::TimeDelta delta_since_base = time_base - time; 338 const base::TimeDelta delta_since_base = time_base - time;
345 return trace_ticks_base - delta_since_base; 339 return trace_ticks_base - delta_since_base;
346 } 340 }
347 341
348 // Record time of main entry so it can be read from Telemetry performance tests. 342 // Record time of main entry so it can be read from Telemetry performance tests.
349 // TODO(jeremy): Remove once crbug.com/317481 is fixed. 343 // TODO(jeremy): Remove once crbug.com/317481 is fixed.
350 void RecordMainEntryTimeHistogram() { 344 void RecordMainEntryTimeHistogram() {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 741
748 base::TimeTicks MainEntryPointTicks() { 742 base::TimeTicks MainEntryPointTicks() {
749 return g_browser_main_entry_point_ticks.Get(); 743 return g_browser_main_entry_point_ticks.Get();
750 } 744 }
751 745
752 StartupTemperature GetStartupTemperature() { 746 StartupTemperature GetStartupTemperature() {
753 return g_startup_temperature; 747 return g_startup_temperature;
754 } 748 }
755 749
756 } // namespace startup_metric_utils 750 } // namespace startup_metric_utils
OLDNEW
« no previous file with comments | « base/threading/platform_thread_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698