| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 10 #include <string> |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 std::map<const ThreadData*, int> birth_threads_; | 350 std::map<const ThreadData*, int> birth_threads_; |
| 351 DeathData death_data_; | 351 DeathData death_data_; |
| 352 std::map<const ThreadData*, int> death_threads_; | 352 std::map<const ThreadData*, int> death_threads_; |
| 353 | 353 |
| 354 DISALLOW_COPY_AND_ASSIGN(Aggregation); | 354 DISALLOW_COPY_AND_ASSIGN(Aggregation); |
| 355 }; | 355 }; |
| 356 | 356 |
| 357 //------------------------------------------------------------------------------ | 357 //------------------------------------------------------------------------------ |
| 358 // Comparator is a class that supports the comparison of Snapshot instances. | 358 // Comparator is a class that supports the comparison of Snapshot instances. |
| 359 // An instance is actually a list of chained Comparitors, that can provide for | 359 // An instance is actually a list of chained Comparitors, that can provide for |
| 360 // arbitrary ordering. The path portion of an about:objects URL is translated | 360 // arbitrary ordering. The path portion of an about:tasks URL is translated |
| 361 // into such a chain, which is then used to order Snapshot instances in a | 361 // into such a chain, which is then used to order Snapshot instances in a |
| 362 // vector. It orders them into groups (for aggregation), and can also order | 362 // vector. It orders them into groups (for aggregation), and can also order |
| 363 // instances within the groups (for detailed rendering of the instances in an | 363 // instances within the groups (for detailed rendering of the instances in an |
| 364 // aggregation). | 364 // aggregation). |
| 365 | 365 |
| 366 class Comparator { | 366 class Comparator { |
| 367 public: | 367 public: |
| 368 // Selector enum is the token identifier for each parsed keyword, most of | 368 // Selector enum is the token identifier for each parsed keyword, most of |
| 369 // which specify a sort order. | 369 // which specify a sort order. |
| 370 // Since it is not meaningful to sort more than once on a specific key, we | 370 // Since it is not meaningful to sort more than once on a specific key, we |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 bool IsGroupedBy(Selector selector) const; | 416 bool IsGroupedBy(Selector selector) const; |
| 417 | 417 |
| 418 // Using the tiebreakers as set above, we mostly get an ordering, which | 418 // Using the tiebreakers as set above, we mostly get an ordering, which |
| 419 // equivalent groups. If those groups are displayed (rather than just being | 419 // equivalent groups. If those groups are displayed (rather than just being |
| 420 // aggregated, then the following is used to order them (within the group). | 420 // aggregated, then the following is used to order them (within the group). |
| 421 void SetSubgroupTiebreaker(Selector selector); | 421 void SetSubgroupTiebreaker(Selector selector); |
| 422 | 422 |
| 423 // Translate a keyword and restriction in URL path to a selector for sorting. | 423 // Translate a keyword and restriction in URL path to a selector for sorting. |
| 424 void ParseKeyphrase(const std::string& key_phrase); | 424 void ParseKeyphrase(const std::string& key_phrase); |
| 425 | 425 |
| 426 // Parse a query in an about:objects URL to decide on sort ordering. | 426 // Parse a query in an about:tasks URL to decide on sort ordering. |
| 427 bool ParseQuery(const std::string& query); | 427 bool ParseQuery(const std::string& query); |
| 428 | 428 |
| 429 // Output a header line that can be used to indicated what items will be | 429 // Output a header line that can be used to indicated what items will be |
| 430 // collected in the group. It lists all (potentially) tested attributes and | 430 // collected in the group. It lists all (potentially) tested attributes and |
| 431 // their values (in the sample item). | 431 // their values (in the sample item). |
| 432 bool WriteSortGrouping(const Snapshot& sample, std::string* output) const; | 432 bool WriteSortGrouping(const Snapshot& sample, std::string* output) const; |
| 433 | 433 |
| 434 // Output a sample, with SortGroup details not displayed. | 434 // Output a sample, with SortGroup details not displayed. |
| 435 void WriteSnapshot(const Snapshot& sample, std::string* output) const; | 435 void WriteSnapshot(const Snapshot& sample, std::string* output) const; |
| 436 | 436 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 ThreadData(); | 472 ThreadData(); |
| 473 ~ThreadData(); | 473 ~ThreadData(); |
| 474 | 474 |
| 475 // Using Thread Local Store, find the current instance for collecting data. | 475 // Using Thread Local Store, find the current instance for collecting data. |
| 476 // If an instance does not exist, construct one (and remember it for use on | 476 // If an instance does not exist, construct one (and remember it for use on |
| 477 // this thread. | 477 // this thread. |
| 478 // If shutdown has already started, and we don't yet have an instance, then | 478 // If shutdown has already started, and we don't yet have an instance, then |
| 479 // return null. | 479 // return null. |
| 480 static ThreadData* current(); | 480 static ThreadData* current(); |
| 481 | 481 |
| 482 // For a given about:objects URL, develop resulting HTML, and append to | 482 // For a given about:tasks URL, develop resulting HTML, and append to output. |
| 483 // output. | |
| 484 static void WriteHTML(const std::string& query, std::string* output); | 483 static void WriteHTML(const std::string& query, std::string* output); |
| 485 | 484 |
| 486 // For a given accumulated array of results, use the comparator to sort and | 485 // For a given accumulated array of results, use the comparator to sort and |
| 487 // subtotal, writing the results to the output. | 486 // subtotal, writing the results to the output. |
| 488 static void WriteHTMLTotalAndSubtotals( | 487 static void WriteHTMLTotalAndSubtotals( |
| 489 const DataCollector::Collection& match_array, | 488 const DataCollector::Collection& match_array, |
| 490 const Comparator& comparator, std::string* output); | 489 const Comparator& comparator, std::string* output); |
| 491 | 490 |
| 492 // In this thread's data, record a new birth. | 491 // In this thread's data, record a new birth. |
| 493 Births* TallyABirth(const Location& location); | 492 Births* TallyABirth(const Location& location); |
| 494 | 493 |
| 495 // Find a place to record a death on this thread. | 494 // Find a place to record a death on this thread. |
| 496 void TallyADeath(const Births& lifetimes, const base::TimeDelta& duration); | 495 void TallyADeath(const Births& lifetimes, const base::TimeDelta& duration); |
| 497 | 496 |
| 498 // (Thread safe) Get start of list of instances. | 497 // (Thread safe) Get start of list of instances. |
| 499 static ThreadData* first(); | 498 static ThreadData* first(); |
| 500 // Iterate through the null terminated list of instances. | 499 // Iterate through the null terminated list of instances. |
| 501 ThreadData* next() const { return next_; } | 500 ThreadData* next() const { return next_; } |
| 502 | 501 |
| 503 MessageLoop* message_loop() const { return message_loop_; } | 502 MessageLoop* message_loop() const { return message_loop_; } |
| 504 const std::string ThreadName() const; | 503 const std::string ThreadName() const; |
| 505 | 504 |
| 506 // Using our lock, make a copy of the specified maps. These calls may arrive | 505 // Using our lock, make a copy of the specified maps. These calls may arrive |
| 507 // from non-local threads, and are used to quickly scan data from all threads | 506 // from non-local threads, and are used to quickly scan data from all threads |
| 508 // in order to build an HTML page for about:objects. | 507 // in order to build an HTML page for about:tasks. |
| 509 void SnapshotBirthMap(BirthMap *output) const; | 508 void SnapshotBirthMap(BirthMap *output) const; |
| 510 void SnapshotDeathMap(DeathMap *output) const; | 509 void SnapshotDeathMap(DeathMap *output) const; |
| 511 | 510 |
| 512 // Hack: asynchronously clear all birth counts and death tallies data values | 511 // Hack: asynchronously clear all birth counts and death tallies data values |
| 513 // in all ThreadData instances. The numerical (zeroing) part is done without | 512 // in all ThreadData instances. The numerical (zeroing) part is done without |
| 514 // use of a locks or atomics exchanges, and may (for int64 values) produce | 513 // use of a locks or atomics exchanges, and may (for int64 values) produce |
| 515 // bogus counts VERY rarely. | 514 // bogus counts VERY rarely. |
| 516 static void ResetAllThreadData(); | 515 static void ResetAllThreadData(); |
| 517 | 516 |
| 518 // Using our lock to protect the iteration, Clear all birth and death data. | 517 // Using our lock to protect the iteration, Clear all birth and death data. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 }; | 657 }; |
| 659 static State state_; | 658 static State state_; |
| 660 | 659 |
| 661 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 660 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
| 662 }; | 661 }; |
| 663 | 662 |
| 664 | 663 |
| 665 } // namespace tracked_objects | 664 } // namespace tracked_objects |
| 666 | 665 |
| 667 #endif // BASE_TRACKED_OBJECTS_H_ | 666 #endif // BASE_TRACKED_OBJECTS_H_ |
| OLD | NEW |