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