| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 ConstructorHeapProfile::ConstructorHeapProfile() | 443 ConstructorHeapProfile::ConstructorHeapProfile() |
| 443 : zscope_(DELETE_ON_EXIT) { | 444 : zscope_(DELETE_ON_EXIT) { |
| 444 } | 445 } |
| 445 | 446 |
| 446 | 447 |
| 447 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, | 448 void ConstructorHeapProfile::Call(const JSObjectsCluster& cluster, |
| 448 const NumberAndSizeInfo& number_and_size) { | 449 const NumberAndSizeInfo& number_and_size) { |
| 449 HeapStringAllocator allocator; | 450 HeapStringAllocator allocator; |
| 450 StringStream stream(&allocator); | 451 StringStream stream(&allocator); |
| 451 cluster.Print(&stream); | 452 cluster.Print(&stream); |
| 452 LOG(HeapSampleJSConstructorEvent(*(stream.ToCString()), | 453 LOG(ISOLATE, |
| 454 HeapSampleJSConstructorEvent(*(stream.ToCString()), |
| 453 number_and_size.number(), | 455 number_and_size.number(), |
| 454 number_and_size.bytes())); | 456 number_and_size.bytes())); |
| 455 } | 457 } |
| 456 | 458 |
| 457 | 459 |
| 458 void ConstructorHeapProfile::CollectStats(HeapObject* obj) { | 460 void ConstructorHeapProfile::CollectStats(HeapObject* obj) { |
| 459 Clusterizer::InsertIntoTree(&js_objects_info_tree_, obj, false); | 461 Clusterizer::InsertIntoTree(&js_objects_info_tree_, obj, false); |
| 460 } | 462 } |
| 461 | 463 |
| 462 | 464 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 DeleteArray(static_cast<Address*>(trace)); | 733 DeleteArray(static_cast<Address*>(trace)); |
| 732 object.Dispose(); | 734 object.Dispose(); |
| 733 } | 735 } |
| 734 | 736 |
| 735 | 737 |
| 736 static void PrintProducerStackTrace(Object* obj, void* trace) { | 738 static void PrintProducerStackTrace(Object* obj, void* trace) { |
| 737 if (!obj->IsJSObject()) return; | 739 if (!obj->IsJSObject()) return; |
| 738 String* constructor = GetConstructorNameForHeapProfile(JSObject::cast(obj)); | 740 String* constructor = GetConstructorNameForHeapProfile(JSObject::cast(obj)); |
| 739 SmartPointer<char> s_name( | 741 SmartPointer<char> s_name( |
| 740 constructor->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); | 742 constructor->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)); |
| 741 LOG(HeapSampleJSProducerEvent(GetConstructorName(*s_name), | 743 LOG(ISOLATE, |
| 744 HeapSampleJSProducerEvent(GetConstructorName(*s_name), |
| 742 reinterpret_cast<Address*>(trace))); | 745 reinterpret_cast<Address*>(trace))); |
| 743 } | 746 } |
| 744 | 747 |
| 745 | 748 |
| 746 void HeapProfiler::WriteSample() { | 749 void HeapProfiler::WriteSample() { |
| 747 Isolate* isolate = Isolate::Current(); | 750 Isolate* isolate = Isolate::Current(); |
| 748 LOG(HeapSampleBeginEvent("Heap", "allocated")); | 751 LOG(isolate, HeapSampleBeginEvent("Heap", "allocated")); |
| 749 LOG(HeapSampleStats( | 752 LOG(isolate, |
| 750 "Heap", "allocated", HEAP->CommittedMemory(), HEAP->SizeOfObjects())); | 753 HeapSampleStats( |
| 754 "Heap", "allocated", HEAP->CommittedMemory(), HEAP->SizeOfObjects())); |
| 751 | 755 |
| 752 AggregatedHeapSnapshot snapshot; | 756 AggregatedHeapSnapshot snapshot; |
| 753 AggregatedHeapSnapshotGenerator generator(&snapshot); | 757 AggregatedHeapSnapshotGenerator generator(&snapshot); |
| 754 generator.GenerateSnapshot(); | 758 generator.GenerateSnapshot(); |
| 755 | 759 |
| 756 HistogramInfo* info = snapshot.info(); | 760 HistogramInfo* info = snapshot.info(); |
| 757 for (int i = FIRST_NONSTRING_TYPE; | 761 for (int i = FIRST_NONSTRING_TYPE; |
| 758 i <= AggregatedHeapSnapshotGenerator::kAllStringsType; | 762 i <= AggregatedHeapSnapshotGenerator::kAllStringsType; |
| 759 ++i) { | 763 ++i) { |
| 760 if (info[i].bytes() > 0) { | 764 if (info[i].bytes() > 0) { |
| 761 LOG(HeapSampleItemEvent(info[i].name(), info[i].number(), | 765 LOG(isolate, |
| 766 HeapSampleItemEvent(info[i].name(), info[i].number(), |
| 762 info[i].bytes())); | 767 info[i].bytes())); |
| 763 } | 768 } |
| 764 } | 769 } |
| 765 | 770 |
| 766 snapshot.js_cons_profile()->PrintStats(); | 771 snapshot.js_cons_profile()->PrintStats(); |
| 767 snapshot.js_retainer_profile()->PrintStats(); | 772 snapshot.js_retainer_profile()->PrintStats(); |
| 768 | 773 |
| 769 isolate->global_handles()->IterateWeakRoots(PrintProducerStackTrace, | 774 isolate->global_handles()->IterateWeakRoots(PrintProducerStackTrace, |
| 770 StackWeakReferenceCallback); | 775 StackWeakReferenceCallback); |
| 771 | 776 |
| 772 LOG(HeapSampleEndEvent("Heap", "allocated")); | 777 LOG(isolate, HeapSampleEndEvent("Heap", "allocated")); |
| 773 } | 778 } |
| 774 | 779 |
| 775 | 780 |
| 776 AggregatedHeapSnapshot::AggregatedHeapSnapshot() | 781 AggregatedHeapSnapshot::AggregatedHeapSnapshot() |
| 777 : info_(NewArray<HistogramInfo>( | 782 : info_(NewArray<HistogramInfo>( |
| 778 AggregatedHeapSnapshotGenerator::kAllStringsType + 1)) { | 783 AggregatedHeapSnapshotGenerator::kAllStringsType + 1)) { |
| 779 #define DEF_TYPE_NAME(name) info_[name].set_name(#name); | 784 #define DEF_TYPE_NAME(name) info_[name].set_name(#name); |
| 780 INSTANCE_TYPE_LIST(DEF_TYPE_NAME); | 785 INSTANCE_TYPE_LIST(DEF_TYPE_NAME); |
| 781 #undef DEF_TYPE_NAME | 786 #undef DEF_TYPE_NAME |
| 782 info_[AggregatedHeapSnapshotGenerator::kAllStringsType].set_name( | 787 info_[AggregatedHeapSnapshotGenerator::kAllStringsType].set_name( |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 isolate_->global_handles()->MakeWeak(handle.location(), | 1129 isolate_->global_handles()->MakeWeak(handle.location(), |
| 1125 static_cast<void*>(stack.start()), | 1130 static_cast<void*>(stack.start()), |
| 1126 StackWeakReferenceCallback); | 1131 StackWeakReferenceCallback); |
| 1127 } | 1132 } |
| 1128 | 1133 |
| 1129 | 1134 |
| 1130 #endif // ENABLE_LOGGING_AND_PROFILING | 1135 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1131 | 1136 |
| 1132 | 1137 |
| 1133 } } // namespace v8::internal | 1138 } } // namespace v8::internal |
| OLD | NEW |