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

Side by Side Diff: include/v8-profiler.h

Issue 1555553002: [profiler] Implement POC Sampling Heap Profiler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove commented code Created 4 years, 11 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
OLDNEW
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 <deque>
9 #include <string>
8 #include <vector> 10 #include <vector>
9 #include "v8.h" // NOLINT(build/include) 11 #include "v8.h" // NOLINT(build/include)
10 12
11 /** 13 /**
12 * Profiler support for the V8 JavaScript engine. 14 * Profiler support for the V8 JavaScript engine.
13 */ 15 */
14 namespace v8 { 16 namespace v8 {
15 17
16 class HeapGraphNode; 18 class HeapGraphNode;
17 struct HeapStatsUpdate; 19 struct HeapStatsUpdate;
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 virtual ~ActivityControl() {} 414 virtual ~ActivityControl() {}
413 /** 415 /**
414 * Notify about current progress. The activity can be stopped by 416 * Notify about current progress. The activity can be stopped by
415 * returning kAbort as the callback result. 417 * returning kAbort as the callback result.
416 */ 418 */
417 virtual ControlOption ReportProgressValue(int done, int total) = 0; 419 virtual ControlOption ReportProgressValue(int done, int total) = 0;
418 }; 420 };
419 421
420 422
421 /** 423 /**
424 * AllocationProfile is a sampled profile of allocations done by the program.
425 * This is structured as a call-graph.
426 */
427 class V8_EXPORT AllocationProfile {
428 public:
429 struct Allocation {
430 /**
431 * Size of the sampled allocation object.
432 */
433 size_t size;
434
435 /**
436 * The number of objects of such size that were sampled.
437 */
438 unsigned int count;
439 };
440
441 /**
442 * Represents a node in the call-graph.
443 */
444 struct Node {
445 /**
446 * Name of the function. May be empty for anonymous functions or if the
447 * script corresponding to this function has been unloaded.
448 */
449 Local<String> name;
450
451 /**
452 * Name of the script containing the function. May be empty if the script
453 * name is not available, or if the script has been unloaded.
454 */
455 Local<String> script_name;
456
457 /**
458 * id of the script where the function is located. May be equal to
459 * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist.
460 */
461 int script_id;
462
463 /**
464 * Start position of the function in the script.
465 */
466 int start_position;
467
468 /**
469 * 1-indexed line number where the function starts. May be
470 * kNoLineNumberInfo if no line number information is available.
471 */
472 int line_number;
473
474 /**
475 * 1-indexed column number where the function starts. May be
476 * kNoColumnNumberInfo if no line number information is available.
477 */
478 int column_number;
479
480 /**
481 * List of callees called from this node for which we have sampled
482 * allocations. The lifetime of the children is scoped to the containing
483 * AllocationProfile.
484 */
485 std::vector<Node*> children;
486
487 /**
488 * List of self allocations done by this node in the call-graph.
489 */
490 std::vector<Allocation> allocations;
491 };
492
493 /**
494 * Returns the root node of the call-graph. The root node corresponds to an
495 * empty JS call-stack. The lifetime of the returned Node* is scoped to the
496 * containing AllocationProfile.
497 */
498 Node* GetRootNode();
499
500 static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
501 static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
502
503 // This data structure can be large. It can be moved but we want to avoid
504 // accidental copies.
505 AllocationProfile() {}
506 AllocationProfile(AllocationProfile&& other) = default;
507 AllocationProfile& operator=(AllocationProfile&& other) = default;
508 AllocationProfile(AllocationProfile& other) = delete;
509 AllocationProfile& operator=(AllocationProfile& other) = delete;
510
511 /**
512 * Holds onto the storage for all the nodes in the profile. Use GetRootNode
513 * instead of directly iterating the following list.
514 */
515 std::deque<Node> nodes;
alph 2016/01/19 23:43:57 Can you move it to the implementation side so it's
ofrobots 2016/01/20 02:14:49 Done.
516 };
517
518
519 /**
422 * Interface for controlling heap profiling. Instance of the 520 * Interface for controlling heap profiling. Instance of the
423 * profiler can be retrieved using v8::Isolate::GetHeapProfiler. 521 * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
424 */ 522 */
425 class V8_EXPORT HeapProfiler { 523 class V8_EXPORT HeapProfiler {
426 public: 524 public:
427 /** 525 /**
428 * Callback function invoked for obtaining RetainedObjectInfo for 526 * Callback function invoked for obtaining RetainedObjectInfo for
429 * the given JavaScript wrapper object. It is prohibited to enter V8 527 * the given JavaScript wrapper object. It is prohibited to enter V8
430 * while the callback is running: only getters on the handle and 528 * while the callback is running: only getters on the handle and
431 * GetPointerFromInternalField on the objects are allowed. 529 * GetPointerFromInternalField on the objects are allowed.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 int64_t* timestamp_us = NULL); 613 int64_t* timestamp_us = NULL);
516 614
517 /** 615 /**
518 * Stops tracking of heap objects population statistics, cleans up all 616 * Stops tracking of heap objects population statistics, cleans up all
519 * collected data. StartHeapObjectsTracking must be called again prior to 617 * collected data. StartHeapObjectsTracking must be called again prior to
520 * calling GetHeapStats next time. 618 * calling GetHeapStats next time.
521 */ 619 */
522 void StopTrackingHeapObjects(); 620 void StopTrackingHeapObjects();
523 621
524 /** 622 /**
623 * Starts gathering a sampling heap profile. A sampling heap profile is
624 * similar to tcmalloc's heap profiler and Go's mprof. It samples object
625 * allocations and builds an online 'sampling' heap profile. At any point in
626 * time, this profile is expected to be a representative sample of objects
627 * currently live in the system. Each sampled allocation includes the stack
628 * trace at the time of allocation, which makes this really useful for memory
629 * leak detection.
630 *
631 * This mechanism is intended to be cheap enough that it can be used in
632 * production with minimal performance overhead.
633 *
634 * Allocations are sampled using a randomized Poisson process. On average, one
635 * allocation will be sampled every |sample_interval| bytes allocated. The
636 * |stack_depth| parameter controls the maximum number of stack frames to be
637 * captured on each allocation.
638 *
639 * NOTE: This is a proof-of-concept at this point. Right now we only sample
640 * newspace allocations. Support for paged space allocation (e.g. pre-tenured
641 * objects, large objects, code objects, etc.) and native allocations
642 * doesn't exist yet, but is anticipated in the future.
643 *
644 * Objects allocated before the sampling is started will not be included in
645 * the profile.
646 *
647 * Returns false if a sampling heap profiler is already running.
648 */
649 bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
650 int stack_depth = 16);
651
652 /**
653 * Stops the sampling heap profile and discards the current profile.
654 */
655 void StopSamplingHeapProfiler();
656
657 /**
658 * Returns the sampled profile of allocations allocated (and still live) since
659 * StartSamplingHeapProfiler was called.
alph 2016/01/19 23:43:57 It is worth to describe the profile lifetime here.
ofrobots 2016/01/20 02:14:49 Done.
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
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_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/api.cc » ('j') | src/profiler/sampling-heap-profiler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698