| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "heap-profiler.h" | 30 #include "heap-profiler.h" |
| 31 #include "frames-inl.h" | 31 #include "frames-inl.h" |
| 32 #include "global-handles.h" | 32 #include "global-handles.h" |
| 33 #include "profile-generator.h" |
| 33 #include "string-stream.h" | 34 #include "string-stream.h" |
| 34 #include "zone-inl.h" | |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 | 39 |
| 40 #ifdef ENABLE_LOGGING_AND_PROFILING | 40 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // Clusterizer is a set of helper functions for converting | 43 // Clusterizer is a set of helper functions for converting |
| 44 // object references into clusters. | 44 // object references into clusters. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if (output_tree_.Insert(eq, &loc)) { | 307 if (output_tree_.Insert(eq, &loc)) { |
| 308 loc.set_value(new JSObjectsClusterTree()); | 308 loc.set_value(new JSObjectsClusterTree()); |
| 309 } | 309 } |
| 310 RetainersAggregator retainers_aggregator(coarser_, loc.value()); | 310 RetainersAggregator retainers_aggregator(coarser_, loc.value()); |
| 311 tree->ForEach(&retainers_aggregator); | 311 tree->ForEach(&retainers_aggregator); |
| 312 } | 312 } |
| 313 | 313 |
| 314 } // namespace | 314 } // namespace |
| 315 | 315 |
| 316 | 316 |
| 317 HeapProfiler* HeapProfiler::singleton_ = NULL; |
| 318 |
| 319 HeapProfiler::HeapProfiler() |
| 320 : snapshots_(new HeapSnapshotsCollection()), |
| 321 next_snapshot_uid_(1) { |
| 322 } |
| 323 |
| 324 |
| 325 HeapProfiler::~HeapProfiler() { |
| 326 delete snapshots_; |
| 327 } |
| 328 |
| 329 |
| 330 void HeapProfiler::Setup() { |
| 331 if (singleton_ == NULL) { |
| 332 singleton_ = new HeapProfiler(); |
| 333 } |
| 334 } |
| 335 |
| 336 |
| 337 void HeapProfiler::TearDown() { |
| 338 delete singleton_; |
| 339 singleton_ = NULL; |
| 340 } |
| 341 |
| 342 |
| 343 HeapSnapshot* HeapProfiler::TakeSnapshot(const char* name) { |
| 344 ASSERT(singleton_ != NULL); |
| 345 return singleton_->TakeSnapshotImpl(name); |
| 346 } |
| 347 |
| 348 |
| 349 HeapSnapshot* HeapProfiler::TakeSnapshot(String* name) { |
| 350 ASSERT(singleton_ != NULL); |
| 351 return singleton_->TakeSnapshotImpl(name); |
| 352 } |
| 353 |
| 354 |
| 355 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(const char* name) { |
| 356 HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++); |
| 357 HeapSnapshotGenerator generator(result); |
| 358 generator.GenerateSnapshot(); |
| 359 return result; |
| 360 } |
| 361 |
| 362 |
| 363 HeapSnapshot* HeapProfiler::TakeSnapshotImpl(String* name) { |
| 364 return TakeSnapshotImpl(snapshots_->GetName(name)); |
| 365 } |
| 366 |
| 367 |
| 368 int HeapProfiler::GetSnapshotsCount() { |
| 369 ASSERT(singleton_ != NULL); |
| 370 return singleton_->snapshots_->snapshots()->length(); |
| 371 } |
| 372 |
| 373 |
| 374 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
| 375 ASSERT(singleton_ != NULL); |
| 376 return singleton_->snapshots_->snapshots()->at(index); |
| 377 } |
| 378 |
| 379 |
| 380 HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
| 381 ASSERT(singleton_ != NULL); |
| 382 return singleton_->snapshots_->GetSnapshot(uid); |
| 383 } |
| 384 |
| 385 |
| 317 const JSObjectsClusterTreeConfig::Key JSObjectsClusterTreeConfig::kNoKey; | 386 const JSObjectsClusterTreeConfig::Key JSObjectsClusterTreeConfig::kNoKey; |
| 318 const JSObjectsClusterTreeConfig::Value JSObjectsClusterTreeConfig::kNoValue; | 387 const JSObjectsClusterTreeConfig::Value JSObjectsClusterTreeConfig::kNoValue; |
| 319 | 388 |
| 320 | 389 |
| 321 ConstructorHeapProfile::ConstructorHeapProfile() | 390 ConstructorHeapProfile::ConstructorHeapProfile() |
| 322 : zscope_(DELETE_ON_EXIT) { | 391 : zscope_(DELETE_ON_EXIT) { |
| 323 } | 392 } |
| 324 | 393 |
| 325 | 394 |
| 326 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, | 395 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 GlobalHandles::MakeWeak(handle.location(), | 755 GlobalHandles::MakeWeak(handle.location(), |
| 687 static_cast<void*>(stack.start()), | 756 static_cast<void*>(stack.start()), |
| 688 StackWeakReferenceCallback); | 757 StackWeakReferenceCallback); |
| 689 } | 758 } |
| 690 | 759 |
| 691 | 760 |
| 692 #endif // ENABLE_LOGGING_AND_PROFILING | 761 #endif // ENABLE_LOGGING_AND_PROFILING |
| 693 | 762 |
| 694 | 763 |
| 695 } } // namespace v8::internal | 764 } } // namespace v8::internal |
| OLD | NEW |