| OLD | NEW |
| 1 // Copyright 2009-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2009-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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 | 168 |
| 169 // A printer interface implementation for the Retainers profile. | 169 // A printer interface implementation for the Retainers profile. |
| 170 class RetainersPrinter : public RetainerHeapProfile::Printer { | 170 class RetainersPrinter : public RetainerHeapProfile::Printer { |
| 171 public: | 171 public: |
| 172 void PrintRetainers(const JSObjectsCluster& cluster, | 172 void PrintRetainers(const JSObjectsCluster& cluster, |
| 173 const StringStream& retainers) { | 173 const StringStream& retainers) { |
| 174 HeapStringAllocator allocator; | 174 HeapStringAllocator allocator; |
| 175 StringStream stream(&allocator); | 175 StringStream stream(&allocator); |
| 176 cluster.Print(&stream); | 176 cluster.Print(&stream); |
| 177 LOG(HeapSampleJSRetainersEvent( | 177 LOG(ISOLATE, |
| 178 HeapSampleJSRetainersEvent( |
| 178 *(stream.ToCString()), *(retainers.ToCString()))); | 179 *(stream.ToCString()), *(retainers.ToCString()))); |
| 179 } | 180 } |
| 180 }; | 181 }; |
| 181 | 182 |
| 182 | 183 |
| 183 // Visitor for printing a cluster tree. | 184 // Visitor for printing a cluster tree. |
| 184 class ClusterTreePrinter BASE_EMBEDDED { | 185 class ClusterTreePrinter BASE_EMBEDDED { |
| 185 public: | 186 public: |
| 186 explicit ClusterTreePrinter(StringStream* stream) : stream_(stream) {} | 187 explicit ClusterTreePrinter(StringStream* stream) : stream_(stream) {} |
| 187 void Call(const JSObjectsCluster& cluster, | 188 void Call(const JSObjectsCluster& cluster, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 ConstructorHeapProfile::ConstructorHeapProfile() | 462 ConstructorHeapProfile::ConstructorHeapProfile() |
| 462 : zscope_(DELETE_ON_EXIT) { | 463 : zscope_(DELETE_ON_EXIT) { |
| 463 } | 464 } |
| 464 | 465 |
| 465 | 466 |
| 466 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, | 467 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, |
| 467 const NumberAndSizeInfo& number_and_size) { | 468 const NumberAndSizeInfo& number_and_size) { |
| 468 HeapStringAllocator allocator; | 469 HeapStringAllocator allocator; |
| 469 StringStream stream(&allocator); | 470 StringStream stream(&allocator); |
| 470 cluster.Print(&stream); | 471 cluster.Print(&stream); |
| 471 LOG(HeapSampleJSConstructorEvent(*(stream.ToCString()), | 472 LOG(ISOLATE, |
| 473 HeapSampleJSConstructorEvent(*(stream.ToCString()), |
| 472 number_and_size.number(), | 474 number_and_size.number(), |
| 473 number_and_size.bytes())); | 475 number_and_size.bytes())); |
| 474 } | 476 } |
| 475 | 477 |
| 476 | 478 |
| 477 void ConstructorHeapProfile::CollectStats(HeapObject* obj) { | 479 void ConstructorHeapProfile::CollectStats(HeapObject* obj) { |
| 478 Clusterizer::InsertIntoTree(&js_objects_info_tree_, obj, false); | 480 Clusterizer::InsertIntoTree(&js_objects_info_tree_, obj, false); |
| 479 } | 481 } |
| 480 | 482 |
| 481 | 483 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 DeleteArray(static_cast<Address*>(trace)); | 752 DeleteArray(static_cast<Address*>(trace)); |
| 751 object.Dispose(); | 753 object.Dispose(); |
| 752 } | 754 } |
| 753 | 755 |
| 754 | 756 |
| 755 static void PrintProducerStackTrace(Object* obj, void* trace) { | 757 static void PrintProducerStackTrace(Object* obj, void* trace) { |
| 756 if (!obj->IsJSObject()) return; | 758 if (!obj->IsJSObject()) return; |
| 757 String* constructor = GetConstructorNameForHeapProfile(JSObject::cast(obj)); | 759 String* constructor = GetConstructorNameForHeapProfile(JSObject::cast(obj)); |
| 758 SmartPointer<char> s_name( | 760 SmartPointer<char> s_name( |
| 759 constructor->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); | 761 constructor->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); |
| 760 LOG(HeapSampleJSProducerEvent(GetConstructorName(*s_name), | 762 LOG(ISOLATE, |
| 763 HeapSampleJSProducerEvent(GetConstructorName(*s_name), |
| 761 reinterpret_cast<Address*>(trace))); | 764 reinterpret_cast<Address*>(trace))); |
| 762 } | 765 } |
| 763 | 766 |
| 764 | 767 |
| 765 void HeapProfiler::WriteSample() { | 768 void HeapProfiler::WriteSample() { |
| 766 Isolate* isolate = Isolate::Current(); | 769 Isolate* isolate = Isolate::Current(); |
| 767 LOG(HeapSampleBeginEvent("Heap", "allocated")); | 770 LOG(isolate, HeapSampleBeginEvent("Heap", "allocated")); |
| 768 LOG(HeapSampleStats( | 771 LOG(isolate, |
| 769 "Heap", "allocated", HEAP->CommittedMemory(), HEAP->SizeOfObjects())); | 772 HeapSampleStats( |
| 773 "Heap", "allocated", HEAP->CommittedMemory(), HEAP->SizeOfObjects())); |
| 770 | 774 |
| 771 AggregatedHeapSnapshot snapshot; | 775 AggregatedHeapSnapshot snapshot; |
| 772 AggregatedHeapSnapshotGenerator generator(&snapshot); | 776 AggregatedHeapSnapshotGenerator generator(&snapshot); |
| 773 generator.GenerateSnapshot(); | 777 generator.GenerateSnapshot(); |
| 774 | 778 |
| 775 HistogramInfo* info = snapshot.info(); | 779 HistogramInfo* info = snapshot.info(); |
| 776 for (int i = FIRST_NONSTRING_TYPE; | 780 for (int i = FIRST_NONSTRING_TYPE; |
| 777 i <= AggregatedHeapSnapshotGenerator::kAllStringsType; | 781 i <= AggregatedHeapSnapshotGenerator::kAllStringsType; |
| 778 ++i) { | 782 ++i) { |
| 779 if (info[i].bytes() > 0) { | 783 if (info[i].bytes() > 0) { |
| 780 LOG(HeapSampleItemEvent(info[i].name(), info[i].number(), | 784 LOG(isolate, |
| 785 HeapSampleItemEvent(info[i].name(), info[i].number(), |
| 781 info[i].bytes())); | 786 info[i].bytes())); |
| 782 } | 787 } |
| 783 } | 788 } |
| 784 | 789 |
| 785 snapshot.js_cons_profile()->PrintStats(); | 790 snapshot.js_cons_profile()->PrintStats(); |
| 786 snapshot.js_retainer_profile()->PrintStats(); | 791 snapshot.js_retainer_profile()->PrintStats(); |
| 787 | 792 |
| 788 isolate->global_handles()->IterateWeakRoots(PrintProducerStackTrace, | 793 isolate->global_handles()->IterateWeakRoots(PrintProducerStackTrace, |
| 789 StackWeakReferenceCallback); | 794 StackWeakReferenceCallback); |
| 790 | 795 |
| 791 LOG(HeapSampleEndEvent("Heap", "allocated")); | 796 LOG(isolate, HeapSampleEndEvent("Heap", "allocated")); |
| 792 } | 797 } |
| 793 | 798 |
| 794 | 799 |
| 795 AggregatedHeapSnapshot::AggregatedHeapSnapshot() | 800 AggregatedHeapSnapshot::AggregatedHeapSnapshot() |
| 796 : info_(NewArray<HistogramInfo>( | 801 : info_(NewArray<HistogramInfo>( |
| 797 AggregatedHeapSnapshotGenerator::kAllStringsType + 1)) { | 802 AggregatedHeapSnapshotGenerator::kAllStringsType + 1)) { |
| 798 #define DEF_TYPE_NAME(name) info_[name].set_name(#name); | 803 #define DEF_TYPE_NAME(name) info_[name].set_name(#name); |
| 799 INSTANCE_TYPE_LIST(DEF_TYPE_NAME); | 804 INSTANCE_TYPE_LIST(DEF_TYPE_NAME); |
| 800 #undef DEF_TYPE_NAME | 805 #undef DEF_TYPE_NAME |
| 801 info_[AggregatedHeapSnapshotGenerator::kAllStringsType].set_name( | 806 info_[AggregatedHeapSnapshotGenerator::kAllStringsType].set_name( |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 isolate_->global_handles()->MakeWeak(handle.location(), | 1150 isolate_->global_handles()->MakeWeak(handle.location(), |
| 1146 static_cast<void*>(stack.start()), | 1151 static_cast<void*>(stack.start()), |
| 1147 StackWeakReferenceCallback); | 1152 StackWeakReferenceCallback); |
| 1148 } | 1153 } |
| 1149 | 1154 |
| 1150 | 1155 |
| 1151 #endif // ENABLE_LOGGING_AND_PROFILING | 1156 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1152 | 1157 |
| 1153 | 1158 |
| 1154 } } // namespace v8::internal | 1159 } } // namespace v8::internal |
| OLD | NEW |