summaryrefslogtreecommitdiff
path: root/ext/objspace
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-16 17:44:45 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-16 17:44:45 +0000
commit45e8ccde005dd8191c4c745b6868d0de4ee66a40 (patch)
treedddb3d866b32a45ddb720650fd45cac7a24fdc53 /ext/objspace
parent54fa33ea491bb1c47400d4534f649efbd47767e3 (diff)
Use JSON lines format for full heap dumps.
This commit changes full heap dumps back to using JSON lines format (http://jsonlines.org) so that we can process very large heaps without loading the entire heap in to memory at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/objspace')
-rw-r--r--ext/objspace/objspace_dump.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 0dd3a9e..38476aa 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -191,7 +191,7 @@ dump_append_string_content(struct dump_config *dc, VALUE obj)
}
static void
-dump_object(VALUE obj, struct dump_config *dc, int part)
+dump_object(VALUE obj, struct dump_config *dc)
{
size_t memsize;
struct allocation_info *ainfo;
@@ -211,11 +211,7 @@ dump_object(VALUE obj, struct dump_config *dc, int part)
if (dc->cur_obj == dc->string)
return;
- if (part)
- dump_append(dc, "\"%p\":{", (void *)obj);
- else
- dump_append(dc, "{\"address\":\"%p\", ", (void *)obj);
- dump_append(dc, "\"type\":\"%s\"", obj_type(obj));
+ dump_append(dc, "{\"address\":\"%p\", \"type\":\"%s\"", (void *)obj, obj_type(obj));
if (dc->cur_obj_klass)
dump_append(dc, ", \"class\":\"%p\"", (void *)dc->cur_obj_klass);
@@ -287,8 +283,7 @@ dump_object(VALUE obj, struct dump_config *dc, int part)
break;
case T_ZOMBIE:
- dump_append(dc, "}");
- dc->roots++;
+ dump_append(dc, "}\n");
return;
}
@@ -317,8 +312,7 @@ dump_object(VALUE obj, struct dump_config *dc, int part)
dump_append(dc, "}");
}
- dump_append(dc, "}");
- dc->roots++;
+ dump_append(dc, "}\n");
}
static int
@@ -327,10 +321,8 @@ heap_i(void *vstart, void *vend, size_t stride, void *data)
struct dump_config *dc = (struct dump_config *)data;
VALUE v = (VALUE)vstart;
for (; v != (VALUE)vend; v += stride) {
- if (RBASIC(v)->flags && v != dc->string) {
- if (dc->roots++) dump_append(dc, ",\n");
- dump_object(v, dc, 1);
- }
+ if (RBASIC(v)->flags)
+ dump_object(v, data);
}
return 0;
}
@@ -341,11 +333,9 @@ root_obj_i(const char *category, VALUE obj, void *data)
struct dump_config *dc = (struct dump_config *)data;
if (dc->root_category != NULL && category != dc->root_category)
- dump_append(dc, "]},\n");
- if (dc->root_category == NULL || category != dc->root_category) {
- dump_append(dc, "\"%p\":", (void *)obj);
+ dump_append(dc, "]}\n");
+ if (dc->root_category == NULL || category != dc->root_category)
dump_append(dc, "{\"type\":\"ROOT\", \"root\":\"%s\", \"references\":[\"%p\"", category, (void *)obj);
- }
else
dump_append(dc, ", \"%p\"", (void *)obj);
@@ -429,8 +419,7 @@ objspace_dump(int argc, VALUE *argv, VALUE os)
output = dump_output(&dc, opts, sym_string, filename);
- dump_object(obj, &dc, 0);
- if (dc.roots) dump_append(&dc, "\n");
+ dump_object(obj, &dc);
return dump_result(&dc, output);
}
@@ -462,14 +451,12 @@ objspace_dump_all(int argc, VALUE *argv, VALUE os)
output = dump_output(&dc, opts, sym_file, filename);
- dump_append(&dc, "{\n");
/* dump roots */
rb_objspace_reachable_objects_from_root(root_obj_i, &dc);
- if (dc.roots) dump_append(&dc, "]}");
+ if (dc.roots) dump_append(&dc, "]}\n");
/* dump all objects */
rb_objspace_each_objects(heap_i, &dc);
- dump_append(&dc, "\n}");
return dump_result(&dc, output);
}