OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project 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 V8_V8_PROFILER_H_ | 5 #ifndef V8_V8_PROFILER_H_ |
6 #define V8_V8_PROFILER_H_ | 6 #define V8_V8_PROFILER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include "v8.h" // NOLINT(build/include) | 9 #include "v8.h" // NOLINT(build/include) |
10 | 10 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 virtual ~ActivityControl() {} | 412 virtual ~ActivityControl() {} |
413 /** | 413 /** |
414 * Notify about current progress. The activity can be stopped by | 414 * Notify about current progress. The activity can be stopped by |
415 * returning kAbort as the callback result. | 415 * returning kAbort as the callback result. |
416 */ | 416 */ |
417 virtual ControlOption ReportProgressValue(int done, int total) = 0; | 417 virtual ControlOption ReportProgressValue(int done, int total) = 0; |
418 }; | 418 }; |
419 | 419 |
420 | 420 |
421 /** | 421 /** |
| 422 * AllocationProfile is a sampled profile of allocations done by the program. |
| 423 * This is structured as a call-graph. |
| 424 */ |
| 425 class V8_EXPORT AllocationProfile { |
| 426 public: |
| 427 struct Allocation { |
| 428 /** |
| 429 * Size of the sampled allocation object. |
| 430 */ |
| 431 size_t size; |
| 432 |
| 433 /** |
| 434 * The number of objects of such size that were sampled. |
| 435 */ |
| 436 unsigned int count; |
| 437 }; |
| 438 |
| 439 /** |
| 440 * Represents a node in the call-graph. |
| 441 */ |
| 442 struct Node { |
| 443 /** |
| 444 * Name of the function. May be empty for anonymous functions or if the |
| 445 * script corresponding to this function has been unloaded. |
| 446 */ |
| 447 Local<String> name; |
| 448 |
| 449 /** |
| 450 * Name of the script containing the function. May be empty if the script |
| 451 * name is not available, or if the script has been unloaded. |
| 452 */ |
| 453 Local<String> script_name; |
| 454 |
| 455 /** |
| 456 * id of the script where the function is located. May be equal to |
| 457 * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist. |
| 458 */ |
| 459 int script_id; |
| 460 |
| 461 /** |
| 462 * Start position of the function in the script. |
| 463 */ |
| 464 int start_position; |
| 465 |
| 466 /** |
| 467 * 1-indexed line number where the function starts. May be |
| 468 * kNoLineNumberInfo if no line number information is available. |
| 469 */ |
| 470 int line_number; |
| 471 |
| 472 /** |
| 473 * 1-indexed column number where the function starts. May be |
| 474 * kNoColumnNumberInfo if no line number information is available. |
| 475 */ |
| 476 int column_number; |
| 477 |
| 478 /** |
| 479 * List of callees called from this node for which we have sampled |
| 480 * allocations. The lifetime of the children is scoped to the containing |
| 481 * AllocationProfile. |
| 482 */ |
| 483 std::vector<Node*> children; |
| 484 |
| 485 /** |
| 486 * List of self allocations done by this node in the call-graph. |
| 487 */ |
| 488 std::vector<Allocation> allocations; |
| 489 }; |
| 490 |
| 491 /** |
| 492 * Returns the root node of the call-graph. The root node corresponds to an |
| 493 * empty JS call-stack. The lifetime of the returned Node* is scoped to the |
| 494 * containing AllocationProfile. |
| 495 */ |
| 496 virtual Node* GetRootNode() = 0; |
| 497 |
| 498 virtual ~AllocationProfile() {} |
| 499 |
| 500 static const int kNoLineNumberInfo = Message::kNoLineNumberInfo; |
| 501 static const int kNoColumnNumberInfo = Message::kNoColumnInfo; |
| 502 }; |
| 503 |
| 504 |
| 505 /** |
422 * Interface for controlling heap profiling. Instance of the | 506 * Interface for controlling heap profiling. Instance of the |
423 * profiler can be retrieved using v8::Isolate::GetHeapProfiler. | 507 * profiler can be retrieved using v8::Isolate::GetHeapProfiler. |
424 */ | 508 */ |
425 class V8_EXPORT HeapProfiler { | 509 class V8_EXPORT HeapProfiler { |
426 public: | 510 public: |
427 /** | 511 /** |
428 * Callback function invoked for obtaining RetainedObjectInfo for | 512 * Callback function invoked for obtaining RetainedObjectInfo for |
429 * the given JavaScript wrapper object. It is prohibited to enter V8 | 513 * the given JavaScript wrapper object. It is prohibited to enter V8 |
430 * while the callback is running: only getters on the handle and | 514 * while the callback is running: only getters on the handle and |
431 * GetPointerFromInternalField on the objects are allowed. | 515 * GetPointerFromInternalField on the objects are allowed. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int64_t* timestamp_us = NULL); | 599 int64_t* timestamp_us = NULL); |
516 | 600 |
517 /** | 601 /** |
518 * Stops tracking of heap objects population statistics, cleans up all | 602 * Stops tracking of heap objects population statistics, cleans up all |
519 * collected data. StartHeapObjectsTracking must be called again prior to | 603 * collected data. StartHeapObjectsTracking must be called again prior to |
520 * calling GetHeapStats next time. | 604 * calling GetHeapStats next time. |
521 */ | 605 */ |
522 void StopTrackingHeapObjects(); | 606 void StopTrackingHeapObjects(); |
523 | 607 |
524 /** | 608 /** |
| 609 * Starts gathering a sampling heap profile. A sampling heap profile is |
| 610 * similar to tcmalloc's heap profiler and Go's mprof. It samples object |
| 611 * allocations and builds an online 'sampling' heap profile. At any point in |
| 612 * time, this profile is expected to be a representative sample of objects |
| 613 * currently live in the system. Each sampled allocation includes the stack |
| 614 * trace at the time of allocation, which makes this really useful for memory |
| 615 * leak detection. |
| 616 * |
| 617 * This mechanism is intended to be cheap enough that it can be used in |
| 618 * production with minimal performance overhead. |
| 619 * |
| 620 * Allocations are sampled using a randomized Poisson process. On average, one |
| 621 * allocation will be sampled every |sample_interval| bytes allocated. The |
| 622 * |stack_depth| parameter controls the maximum number of stack frames to be |
| 623 * captured on each allocation. |
| 624 * |
| 625 * NOTE: This is a proof-of-concept at this point. Right now we only sample |
| 626 * newspace allocations. Support for paged space allocation (e.g. pre-tenured |
| 627 * objects, large objects, code objects, etc.) and native allocations |
| 628 * doesn't exist yet, but is anticipated in the future. |
| 629 * |
| 630 * Objects allocated before the sampling is started will not be included in |
| 631 * the profile. |
| 632 * |
| 633 * Returns false if a sampling heap profiler is already running. |
| 634 */ |
| 635 bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024, |
| 636 int stack_depth = 16); |
| 637 |
| 638 /** |
| 639 * Stops the sampling heap profile and discards the current profile. |
| 640 */ |
| 641 void StopSamplingHeapProfiler(); |
| 642 |
| 643 /** |
| 644 * Returns the sampled profile of allocations allocated (and still live) since |
| 645 * StartSamplingHeapProfiler was called. The ownership of the pointer is |
| 646 * transfered to the caller. Returns nullptr if sampling heap profiler is not |
| 647 * active. |
| 648 */ |
| 649 AllocationProfile* GetAllocationProfile(); |
| 650 |
| 651 /** |
525 * Deletes all snapshots taken. All previously returned pointers to | 652 * Deletes all snapshots taken. All previously returned pointers to |
526 * snapshots and their contents become invalid after this call. | 653 * snapshots and their contents become invalid after this call. |
527 */ | 654 */ |
528 void DeleteAllHeapSnapshots(); | 655 void DeleteAllHeapSnapshots(); |
529 | 656 |
530 /** Binds a callback to embedder's class ID. */ | 657 /** Binds a callback to embedder's class ID. */ |
531 void SetWrapperClassInfoProvider( | 658 void SetWrapperClassInfoProvider( |
532 uint16_t class_id, | 659 uint16_t class_id, |
533 WrapperInfoCallback callback); | 660 WrapperInfoCallback callback); |
534 | 661 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 uint32_t index; // Index of the time interval that was changed. | 766 uint32_t index; // Index of the time interval that was changed. |
640 uint32_t count; // New value of count field for the interval with this index. | 767 uint32_t count; // New value of count field for the interval with this index. |
641 uint32_t size; // New value of size field for the interval with this index. | 768 uint32_t size; // New value of size field for the interval with this index. |
642 }; | 769 }; |
643 | 770 |
644 | 771 |
645 } // namespace v8 | 772 } // namespace v8 |
646 | 773 |
647 | 774 |
648 #endif // V8_V8_PROFILER_H_ | 775 #endif // V8_V8_PROFILER_H_ |
OLD | NEW |