Index: src/heap/object-stats.cc |
diff --git a/src/heap/object-stats.cc b/src/heap/object-stats.cc |
index 6e4b50ec249aca90dbab76cc43307892067b6cf2..ef5f65734e8c53e3288f5c551a848a16b46ce410 100644 |
--- a/src/heap/object-stats.cc |
+++ b/src/heap/object-stats.cc |
@@ -52,55 +52,59 @@ V8_NOINLINE static void DumpJSONArray(std::stringstream& stream, size_t* array, |
stream << "]"; |
} |
+void ObjectStats::PrintKeyAndId(const char* key, int gc_count) { |
+ PrintF("\"isolate\": \"%p\", \"id\": %d, \"key\": \"%s\", ", |
+ reinterpret_cast<void*>(isolate()), gc_count, key); |
+} |
+ |
+void ObjectStats::PrintInstanceTypeJSON(const char* key, int gc_count, |
+ const char* name, int index) { |
+ PrintF("{ "); |
+ PrintKeyAndId(key, gc_count); |
+ PrintF("\"type\": \"instance_type_data\", "); |
+ PrintF("\"instance_type\": %d, ", index); |
+ PrintF("\"instance_type_name\": \"%s\", ", name); |
+ PrintF("\"overall\": %zu, ", object_sizes_[index]); |
+ PrintF("\"count\": %zu, ", object_counts_[index]); |
+ PrintF("\"over_allocated\": %zu, ", over_allocated_[index]); |
+ PrintF("\"histogram\": "); |
+ PrintJSONArray(size_histogram_[index], kNumberOfBuckets); |
+ PrintF(","); |
+ PrintF("\"over_allocated_histogram\": "); |
+ PrintJSONArray(over_allocated_histogram_[index], kNumberOfBuckets); |
+ PrintF(" }\n"); |
+} |
+ |
void ObjectStats::PrintJSON(const char* key) { |
double time = isolate()->time_millis_since_init(); |
int gc_count = heap()->gc_count(); |
-#define PRINT_KEY_AND_ID() \ |
- PrintF("\"isolate\": \"%p\", \"id\": %d, \"key\": \"%s\", ", \ |
- reinterpret_cast<void*>(isolate()), gc_count, key); |
- |
// gc_descriptor |
PrintF("{ "); |
- PRINT_KEY_AND_ID(); |
+ PrintKeyAndId(key, gc_count); |
PrintF("\"type\": \"gc_descriptor\", \"time\": %f }\n", time); |
// bucket_sizes |
PrintF("{ "); |
- PRINT_KEY_AND_ID(); |
+ PrintKeyAndId(key, gc_count); |
PrintF("\"type\": \"bucket_sizes\", \"sizes\": [ "); |
for (int i = 0; i < kNumberOfBuckets; i++) { |
PrintF("%d", 1 << (kFirstBucketShift + i)); |
if (i != (kNumberOfBuckets - 1)) PrintF(", "); |
} |
PrintF(" ] }\n"); |
-// instance_type_data |
-#define PRINT_INSTANCE_TYPE_DATA(name, index) \ |
- PrintF("{ "); \ |
- PRINT_KEY_AND_ID(); \ |
- PrintF("\"type\": \"instance_type_data\", "); \ |
- PrintF("\"instance_type\": %d, ", index); \ |
- PrintF("\"instance_type_name\": \"%s\", ", name); \ |
- PrintF("\"overall\": %zu, ", object_sizes_[index]); \ |
- PrintF("\"count\": %zu, ", object_counts_[index]); \ |
- PrintF("\"over_allocated\": %zu, ", over_allocated_[index]); \ |
- PrintF("\"histogram\": "); \ |
- PrintJSONArray(size_histogram_[index], kNumberOfBuckets); \ |
- PrintF(","); \ |
- PrintF("\"over_allocated_histogram\": "); \ |
- PrintJSONArray(over_allocated_histogram_[index], kNumberOfBuckets); \ |
- PrintF(" }\n"); |
-#define INSTANCE_TYPE_WRAPPER(name) PRINT_INSTANCE_TYPE_DATA(#name, name) |
-#define CODE_KIND_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA("*CODE_" #name, \ |
- FIRST_CODE_KIND_SUB_TYPE + Code::name) |
-#define FIXED_ARRAY_SUB_INSTANCE_TYPE_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA("*FIXED_ARRAY_" #name, \ |
- FIRST_FIXED_ARRAY_SUB_TYPE + name) |
-#define CODE_AGE_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA( \ |
- "*CODE_AGE_" #name, \ |
- FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge) |
+#define INSTANCE_TYPE_WRAPPER(name) \ |
+ PrintInstanceTypeJSON(key, gc_count, #name, name); |
+#define CODE_KIND_WRAPPER(name) \ |
+ PrintInstanceTypeJSON(key, gc_count, "*CODE_" #name, \ |
+ FIRST_CODE_KIND_SUB_TYPE + Code::name); |
+#define FIXED_ARRAY_SUB_INSTANCE_TYPE_WRAPPER(name) \ |
+ PrintInstanceTypeJSON(key, gc_count, "*FIXED_ARRAY_" #name, \ |
+ FIRST_FIXED_ARRAY_SUB_TYPE + name); |
+#define CODE_AGE_WRAPPER(name) \ |
+ PrintInstanceTypeJSON( \ |
+ key, gc_count, "*CODE_AGE_" #name, \ |
+ FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge); |
INSTANCE_TYPE_LIST(INSTANCE_TYPE_WRAPPER) |
CODE_KIND_LIST(CODE_KIND_WRAPPER) |
@@ -115,6 +119,20 @@ void ObjectStats::PrintJSON(const char* key) { |
#undef PRINT_KEY_AND_ID |
} |
+void ObjectStats::DumpInstanceTypeData(std::stringstream& stream, |
+ const char* name, int index) { |
+ stream << "\"" << name << "\":{"; |
+ stream << "\"type\":" << static_cast<int>(index) << ","; |
+ stream << "\"overall\":" << object_sizes_[index] << ","; |
+ stream << "\"count\":" << object_counts_[index] << ","; |
+ stream << "\"over_allocated\":" << over_allocated_[index] << ","; |
+ stream << "\"histogram\":"; |
+ DumpJSONArray(stream, size_histogram_[index], kNumberOfBuckets); |
+ stream << ",\"over_allocated_histogram\":"; |
+ DumpJSONArray(stream, over_allocated_histogram_[index], kNumberOfBuckets); |
+ stream << "},"; |
+} |
+ |
void ObjectStats::Dump(std::stringstream& stream) { |
double time = isolate()->time_millis_since_init(); |
int gc_count = heap()->gc_count(); |
@@ -131,29 +149,19 @@ void ObjectStats::Dump(std::stringstream& stream) { |
stream << "],"; |
stream << "\"type_data\":{"; |
-#define PRINT_INSTANCE_TYPE_DATA(name, index) \ |
- stream << "\"" << name << "\":{"; \ |
- stream << "\"type\":" << static_cast<int>(index) << ","; \ |
- stream << "\"overall\":" << object_sizes_[index] << ","; \ |
- stream << "\"count\":" << object_counts_[index] << ","; \ |
- stream << "\"over_allocated\":" << over_allocated_[index] << ","; \ |
- stream << "\"histogram\":"; \ |
- DumpJSONArray(stream, size_histogram_[index], kNumberOfBuckets); \ |
- stream << ",\"over_allocated_histogram\":"; \ |
- DumpJSONArray(stream, over_allocated_histogram_[index], kNumberOfBuckets); \ |
- stream << "},"; |
+#define INSTANCE_TYPE_WRAPPER(name) DumpInstanceTypeData(stream, #name, name); |
+#define CODE_KIND_WRAPPER(name) \ |
+ DumpInstanceTypeData(stream, "*CODE_" #name, \ |
+ FIRST_CODE_KIND_SUB_TYPE + Code::name); |
+ |
+#define FIXED_ARRAY_SUB_INSTANCE_TYPE_WRAPPER(name) \ |
+ DumpInstanceTypeData(stream, "*FIXED_ARRAY_" #name, \ |
+ FIRST_FIXED_ARRAY_SUB_TYPE + name); |
-#define INSTANCE_TYPE_WRAPPER(name) PRINT_INSTANCE_TYPE_DATA(#name, name) |
-#define CODE_KIND_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA("*CODE_" #name, \ |
- FIRST_CODE_KIND_SUB_TYPE + Code::name) |
-#define FIXED_ARRAY_SUB_INSTANCE_TYPE_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA("*FIXED_ARRAY_" #name, \ |
- FIRST_FIXED_ARRAY_SUB_TYPE + name) |
-#define CODE_AGE_WRAPPER(name) \ |
- PRINT_INSTANCE_TYPE_DATA( \ |
- "*CODE_AGE_" #name, \ |
- FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge) |
+#define CODE_AGE_WRAPPER(name) \ |
+ DumpInstanceTypeData( \ |
+ stream, "*CODE_AGE_" #name, \ |
+ FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge); |
INSTANCE_TYPE_LIST(INSTANCE_TYPE_WRAPPER); |
CODE_KIND_LIST(CODE_KIND_WRAPPER); |