1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
tenderlove 2016-09-16 17:44:45 +00:00
parent 54fa33ea49
commit 45e8ccde00
3 changed files with 18 additions and 24 deletions

View file

@ -1,3 +1,10 @@
Sat Sep 17 02:40:52 2016 Aaron Patterson <tenderlove@ruby-lang.org>
* ext/objspace/objspace_dump.c: Fix stream processing support for heap
dumps. Full heap dumps should use JSON lines (http://jsonlines.org)
so that we can process very large heaps without loading the entire
heap dump in to memory at once.
Fri Sep 16 22:10:31 2016 Naohisa Goto <ngotogenome@gmail.com>
* ext/openssl/ossl_ssl.c (ssl_npn_select_cb_common): Fix compile error

View file

@ -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);
}

View file

@ -316,7 +316,7 @@ class TestObjSpace < Test::Unit::TestCase
assert_ruby_status(args, "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
IO.popen(ARGV) do |f|
JSON.load(f)
f.each_line.map { |x| JSON.load(x) }
end
end;
end