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: base/tracked_objects.h

Issue 9212025: Support use of third party time function to profiler (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « base/profiler/tracked_time.h ('k') | base/tracked_objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BASE_TRACKED_OBJECTS_H_ 5 #ifndef BASE_TRACKED_OBJECTS_H_
6 #define BASE_TRACKED_OBJECTS_H_ 6 #define BASE_TRACKED_OBJECTS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <stack> 11 #include <stack>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/base_export.h" 16 #include "base/base_export.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/profiler/alternate_timer.h"
20 #include "base/profiler/tracked_time.h" 21 #include "base/profiler/tracked_time.h"
21 #include "base/time.h" 22 #include "base/time.h"
22 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
23 #include "base/threading/thread_local_storage.h" 24 #include "base/threading/thread_local_storage.h"
24 #include "base/tracking_info.h" 25 #include "base/tracking_info.h"
25 #include "base/values.h" 26 #include "base/values.h"
26 27
27 // TrackedObjects provides a database of stats about objects (generally Tasks) 28 // TrackedObjects provides a database of stats about objects (generally Tasks)
28 // that are tracked. Tracking means their birth, death, duration, birth thread, 29 // that are tracked. Tracking means their birth, death, duration, birth thread,
29 // death thread, and birth place are recorded. This data is carefully spread 30 // death thread, and birth place are recorded. This data is carefully spread
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // relationships can be (optionally) calculated. 461 // relationships can be (optionally) calculated.
461 static TrackedTime NowForStartOfRun(const Births* parent); 462 static TrackedTime NowForStartOfRun(const Births* parent);
462 static TrackedTime NowForEndOfRun(); 463 static TrackedTime NowForEndOfRun();
463 464
464 // Provide a time function that does nothing (runs fast) when we don't have 465 // Provide a time function that does nothing (runs fast) when we don't have
465 // the profiler enabled. It will generally be optimized away when it is 466 // the profiler enabled. It will generally be optimized away when it is
466 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of 467 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of
467 // the code). 468 // the code).
468 static TrackedTime Now(); 469 static TrackedTime Now();
469 470
471 // Use the function |now| to provide current times, instead of calling the
472 // TrackedTime::Now() function. Since this alternate function is being used,
473 // the other time arguments (used for calculating queueing delay) will be
474 // ignored.
475 static void SetAlternateTimeSource(NowFunction* now);
476
470 // This function can be called at process termination to validate that thread 477 // This function can be called at process termination to validate that thread
471 // cleanup routines have been called for at least some number of named 478 // cleanup routines have been called for at least some number of named
472 // threads. 479 // threads.
473 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); 480 static void EnsureCleanupWasCalled(int major_threads_shutdown_count);
474 481
475 private: 482 private:
476 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it 483 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it
477 // in production code. 484 // in production code.
478 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a 485 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a
479 // better change of optimizing (inlining? etc.) private methods (knowing that 486 // better change of optimizing (inlining? etc.) private methods (knowing that
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // uninitialized) state. If there is any chance that other threads are still 543 // uninitialized) state. If there is any chance that other threads are still
537 // using the data structures, then the |leak| argument should be passed in as 544 // using the data structures, then the |leak| argument should be passed in as
538 // true, and the data structures (birth maps, death maps, ThreadData 545 // true, and the data structures (birth maps, death maps, ThreadData
539 // insntances, etc.) will be leaked and not deleted. If you have joined all 546 // insntances, etc.) will be leaked and not deleted. If you have joined all
540 // threads since the time that InitializeAndSetTrackingStatus() was called, 547 // threads since the time that InitializeAndSetTrackingStatus() was called,
541 // then you can pass in a |leak| value of false, and this function will 548 // then you can pass in a |leak| value of false, and this function will
542 // delete recursively all data structures, starting with the list of 549 // delete recursively all data structures, starting with the list of
543 // ThreadData instances. 550 // ThreadData instances.
544 static void ShutdownSingleThreadedCleanup(bool leak); 551 static void ShutdownSingleThreadedCleanup(bool leak);
545 552
553 // When non-null, this specifies an external function that supplies monotone
554 // increasing time functcion.
555 static NowFunction* now_function_;
556
546 // We use thread local store to identify which ThreadData to interact with. 557 // We use thread local store to identify which ThreadData to interact with.
547 static base::ThreadLocalStorage::StaticSlot tls_index_; 558 static base::ThreadLocalStorage::StaticSlot tls_index_;
548 559
549 // List of ThreadData instances for use with worker threads. When a worker 560 // List of ThreadData instances for use with worker threads. When a worker
550 // thread is done (terminated), we push it onto this llist. When a new worker 561 // thread is done (terminated), we push it onto this llist. When a new worker
551 // thread is created, we first try to re-use a ThreadData instance from the 562 // thread is created, we first try to re-use a ThreadData instance from the
552 // list, and if none are available, construct a new one. 563 // list, and if none are available, construct a new one.
553 // This is only accessed while list_lock_ is held. 564 // This is only accessed while list_lock_ is held.
554 static ThreadData* first_retired_worker_; 565 static ThreadData* first_retired_worker_;
555 566
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 710
700 // The complete list of parent-child relationships among tasks. 711 // The complete list of parent-child relationships among tasks.
701 ThreadData::ParentChildSet parent_child_set_; 712 ThreadData::ParentChildSet parent_child_set_;
702 713
703 DISALLOW_COPY_AND_ASSIGN(DataCollector); 714 DISALLOW_COPY_AND_ASSIGN(DataCollector);
704 }; 715 };
705 716
706 } // namespace tracked_objects 717 } // namespace tracked_objects
707 718
708 #endif // BASE_TRACKED_OBJECTS_H_ 719 #endif // BASE_TRACKED_OBJECTS_H_
OLDNEW
« no previous file with comments | « base/profiler/tracked_time.h ('k') | base/tracked_objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698