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

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
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // relationships can be (optionally) calculated. 463 // relationships can be (optionally) calculated.
463 static TrackedTime NowForStartOfRun(const Births* parent); 464 static TrackedTime NowForStartOfRun(const Births* parent);
464 static TrackedTime NowForEndOfRun(); 465 static TrackedTime NowForEndOfRun();
465 466
466 // Provide a time function that does nothing (runs fast) when we don't have 467 // Provide a time function that does nothing (runs fast) when we don't have
467 // the profiler enabled. It will generally be optimized away when it is 468 // the profiler enabled. It will generally be optimized away when it is
468 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of 469 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of
469 // the code). 470 // the code).
470 static TrackedTime Now(); 471 static TrackedTime Now();
471 472
473 // Use the function |now| to provide current times, instead of calling the
474 // TrackedTime::Now() function. Since this alternate function is being used,
475 // the other time arguments (used for calculating queueing delay) will be
476 // ignored.
477 static void SetAlternateTimeSource(NowFunction* now);
478
472 // This function can be called at process termination to validate that thread 479 // This function can be called at process termination to validate that thread
473 // cleanup routines have been called for at least some number of named 480 // cleanup routines have been called for at least some number of named
474 // threads. 481 // threads.
475 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); 482 static void EnsureCleanupWasCalled(int major_threads_shutdown_count);
476 483
477 private: 484 private:
478 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it 485 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it
479 // in production code. 486 // in production code.
480 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a 487 // TODO(jar): Make this a friend in DEBUG only, so that the optimizer has a
481 // better change of optimizing (inlining? etc.) private methods (knowing that 488 // better change of optimizing (inlining? etc.) private methods (knowing that
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // uninitialized) state. If there is any chance that other threads are still 545 // uninitialized) state. If there is any chance that other threads are still
539 // using the data structures, then the |leak| argument should be passed in as 546 // using the data structures, then the |leak| argument should be passed in as
540 // true, and the data structures (birth maps, death maps, ThreadData 547 // true, and the data structures (birth maps, death maps, ThreadData
541 // insntances, etc.) will be leaked and not deleted. If you have joined all 548 // insntances, etc.) will be leaked and not deleted. If you have joined all
542 // threads since the time that InitializeAndSetTrackingStatus() was called, 549 // threads since the time that InitializeAndSetTrackingStatus() was called,
543 // then you can pass in a |leak| value of false, and this function will 550 // then you can pass in a |leak| value of false, and this function will
544 // delete recursively all data structures, starting with the list of 551 // delete recursively all data structures, starting with the list of
545 // ThreadData instances. 552 // ThreadData instances.
546 static void ShutdownSingleThreadedCleanup(bool leak); 553 static void ShutdownSingleThreadedCleanup(bool leak);
547 554
555 // When non-null, this specifies an external function that supplies monotone
556 // increasing time functcion.
557 static NowFunction* now_function_;
558
548 // We use thread local store to identify which ThreadData to interact with. 559 // We use thread local store to identify which ThreadData to interact with.
549 static base::ThreadLocalStorage::StaticSlot tls_index_; 560 static base::ThreadLocalStorage::StaticSlot tls_index_;
550 561
551 // List of ThreadData instances for use with worker threads. When a worker 562 // List of ThreadData instances for use with worker threads. When a worker
552 // thread is done (terminated), we push it onto this llist. When a new worker 563 // thread is done (terminated), we push it onto this llist. When a new worker
553 // thread is created, we first try to re-use a ThreadData instance from the 564 // thread is created, we first try to re-use a ThreadData instance from the
554 // list, and if none are available, construct a new one. 565 // list, and if none are available, construct a new one.
555 // This is only accessed while list_lock_ is held. 566 // This is only accessed while list_lock_ is held.
556 static ThreadData* first_retired_worker_; 567 static ThreadData* first_retired_worker_;
557 568
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 712
702 // The complete list of parent-child relationships among tasks. 713 // The complete list of parent-child relationships among tasks.
703 ThreadData::ParentChildSet parent_child_set_; 714 ThreadData::ParentChildSet parent_child_set_;
704 715
705 DISALLOW_COPY_AND_ASSIGN(DataCollector); 716 DISALLOW_COPY_AND_ASSIGN(DataCollector);
706 }; 717 };
707 718
708 } // namespace tracked_objects 719 } // namespace tracked_objects
709 720
710 #endif // BASE_TRACKED_OBJECTS_H_ 721 #endif // BASE_TRACKED_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698