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

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

Issue 6626043: Add an interface for an embedder to provide information about native (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix GetCopy Created 9 years, 9 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
« no previous file with comments | « include/v8.h ('k') | src/api.cc » ('j') | src/heap-profiler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 const HeapGraphNode* GetToNode() const; 238 const HeapGraphNode* GetToNode() const;
239 }; 239 };
240 240
241 241
242 /** 242 /**
243 * HeapGraphNode represents a node in a heap graph. 243 * HeapGraphNode represents a node in a heap graph.
244 */ 244 */
245 class V8EXPORT HeapGraphNode { 245 class V8EXPORT HeapGraphNode {
246 public: 246 public:
247 enum Type { 247 enum Type {
248 kHidden = 0, // Hidden node, may be filtered when shown to user. 248 kHidden = 0, // Hidden node, may be filtered when shown to user.
249 kArray = 1, // An array of elements. 249 kArray = 1, // An array of elements.
250 kString = 2, // A string. 250 kString = 2, // A string.
251 kObject = 3, // A JS object (except for arrays and strings). 251 kObject = 3, // A JS object (except for arrays and strings).
252 kCode = 4, // Compiled code. 252 kCode = 4, // Compiled code.
253 kClosure = 5, // Function closure. 253 kClosure = 5, // Function closure.
254 kRegExp = 6, // RegExp. 254 kRegExp = 6, // RegExp.
255 kHeapNumber = 7 // Number stored in the heap. 255 kHeapNumber = 7, // Number stored in the heap.
256 kNative = 8 // Native object (not from V8 heap).
256 }; 257 };
257 258
258 /** Returns node type (see HeapGraphNode::Type). */ 259 /** Returns node type (see HeapGraphNode::Type). */
259 Type GetType() const; 260 Type GetType() const;
260 261
261 /** 262 /**
262 * Returns node name. Depending on node's type this can be the name 263 * Returns node name. Depending on node's type this can be the name
263 * of the constructor (for objects), the name of the function (for 264 * of the constructor (for objects), the name of the function (for
264 * closures), string value, or an empty string (for compiled code). 265 * closures), string value, or an empty string (for compiled code).
265 */ 266 */
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 * strings: [strings] 386 * strings: [strings]
386 * } 387 * }
387 * 388 *
388 * Outgoing node links are stored after each node. Nodes reference strings 389 * Outgoing node links are stored after each node. Nodes reference strings
389 * and other nodes by their indexes in corresponding arrays. 390 * and other nodes by their indexes in corresponding arrays.
390 */ 391 */
391 void Serialize(OutputStream* stream, SerializationFormat format) const; 392 void Serialize(OutputStream* stream, SerializationFormat format) const;
392 }; 393 };
393 394
394 395
396 class RetainedObjectInfo;
397
395 /** 398 /**
396 * Interface for controlling heap profiling. 399 * Interface for controlling heap profiling.
397 */ 400 */
398 class V8EXPORT HeapProfiler { 401 class V8EXPORT HeapProfiler {
399 public: 402 public:
403 /**
404 * Callback function invoked for obtaining RetainedObjectInfo for
405 * the given JavaScript wrapper object. It is prohibited to enter V8
406 * while the callback is running: only getters on the handle and
407 * GetPointerFromInternalField on the objects are allowed.
408 */
409 typedef RetainedObjectInfo* (*WrapperInfoCallback)
410 (uint16_t class_id, Handle<Value> wrapper);
411
400 /** Returns the number of snapshots taken. */ 412 /** Returns the number of snapshots taken. */
401 static int GetSnapshotsCount(); 413 static int GetSnapshotsCount();
402 414
403 /** Returns a snapshot by index. */ 415 /** Returns a snapshot by index. */
404 static const HeapSnapshot* GetSnapshot(int index); 416 static const HeapSnapshot* GetSnapshot(int index);
405 417
406 /** Returns a profile by uid. */ 418 /** Returns a profile by uid. */
407 static const HeapSnapshot* FindSnapshot(unsigned uid); 419 static const HeapSnapshot* FindSnapshot(unsigned uid);
408 420
409 /** 421 /**
410 * Takes a heap snapshot and returns it. Title may be an empty string. 422 * Takes a heap snapshot and returns it. Title may be an empty string.
411 * See HeapSnapshot::Type for types description. 423 * See HeapSnapshot::Type for types description.
412 */ 424 */
413 static const HeapSnapshot* TakeSnapshot( 425 static const HeapSnapshot* TakeSnapshot(
414 Handle<String> title, 426 Handle<String> title,
415 HeapSnapshot::Type type = HeapSnapshot::kFull, 427 HeapSnapshot::Type type = HeapSnapshot::kFull,
416 ActivityControl* control = NULL); 428 ActivityControl* control = NULL);
429
430 /** Binds a callback to embedder's class ID. */
431 static void DefineWrapperClass(
432 uint16_t class_id,
433 WrapperInfoCallback callback);
434
435 /**
436 * Default value of persistent handle class ID. Must not be used to
437 * define a class. Can be used to reset a class of a persistent
438 * handle.
439 */
440 static const uint16_t kPersistentHandleNoClassId = 0;
417 }; 441 };
418 442
419 443
444 /**
445 * Interface for providing information about embedder's objects
446 * held by global handles. This information is reported in two ways:
447 *
448 * 1. When calling AddObjectGroup, an embedder may pass
449 * RetainedObjectInfo instance describing the group. To collect
450 * this information while taking a heap snapshot, V8 calls GC
451 * prologue and epilogue callbacks.
452 *
453 * 2. When a heap snapshot is collected, V8 additionally
454 * requests RetainedObjectInfos for persistent handles that
455 * were not previously reported via AddObjectGroup.
456 *
457 * Thus, if an embedder wants to provide information about native
458 * objects for heap snapshots, he can do it in a GC prologue
459 * handler, and / or by assigning wrapper class ids in the following way:
460 *
461 * 1. Bind a callback to class id by calling DefineWrapperClass.
462 * 2. Call SetWrapperClassId on certain persistent handles.
463 *
464 * V8 takes ownership of RetainedObjectInfo instances passed to it and
465 * keeps them alive only during snapshot collection. Afterwards, they
466 * are freed by calling the Dispose class function.
467 */
468 class V8EXPORT RetainedObjectInfo { // NOLINT
469 public:
470 /** Called by V8 when it no longer needs an instance. */
471 virtual void Dispose() = 0;
472
473 /** Returns whether two instances are equivalent. */
474 virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
475
476 /**
477 * Returns hash value for the instance. Equivalent instances
478 * must have the same hash value.
479 */
480 virtual intptr_t GetHash() = 0;
481
482 /**
483 * Returns human-readable label. It must be a NUL-terminated UTF-8
484 * encoded string. V8 copies its contents during a call to GetLabel.
485 */
486 virtual const char* GetLabel() = 0;
487
488 /**
489 * Returns element count in case if a global handle retains
490 * a subgraph by holding one of its nodes.
491 */
492 virtual intptr_t GetElementCount() { return -1; }
493
494 /** Returns embedder's object size in bytes. */
495 virtual intptr_t GetSizeInBytes() { return -1; }
496
497 protected:
498 RetainedObjectInfo() {}
499 virtual ~RetainedObjectInfo() {}
500
501 private:
502 RetainedObjectInfo(const RetainedObjectInfo&);
503 RetainedObjectInfo& operator=(const RetainedObjectInfo&);
504 };
505
506
420 } // namespace v8 507 } // namespace v8
421 508
422 509
423 #undef V8EXPORT 510 #undef V8EXPORT
424 511
425 512
426 #endif // V8_V8_PROFILER_H_ 513 #endif // V8_V8_PROFILER_H_
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/api.cc » ('j') | src/heap-profiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698