Skip to content

Commit 391aa99

Browse files
committed
account for multiple thread entries in sql format
it used to assume there's only the mappings data in slot 0 and "all" thread data in slot 1, but now slots 1 and following are individual threads. also handles thread id and responsible flag in profile overview and gc list respectively
1 parent f7449fa commit 391aa99

File tree

1 file changed

+58
-48
lines changed

1 file changed

+58
-48
lines changed

src/vm/moar/HLL/Backend.nqp

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -288,68 +288,76 @@ class HLL::Backend::MoarVM {
288288
}
289289

290290
sub to_sql($obj) {
291-
my @profile;
292-
for $obj[0] -> $k {
293-
my $v := $obj[0]{$k};
291+
my int $node_id := 0;
292+
#my %profile := nqp::hash();
293+
my $mapping := nqp::shift($obj);
294+
for $mapping -> $k {
295+
my $v := $mapping{$k};
294296
if nqp::ishash($v) {
295297
$profile_fh.say("INSERT INTO routines VALUES ('" ~ nqp::join("','", nqp::list(nqp::iterkey_s($k), literal_subst(~$v<name>, "'", "''"), ~$v<line>, ~$v<file>)) ~ "');");
296298
}
297299
else {
298300
$profile_fh.say("INSERT INTO types VALUES ('" ~ nqp::join("','", nqp::list(nqp::iterkey_s($k), literal_subst(~$v, "'", "''"))) ~ "');");
299301
}
300302
}
301-
for $obj[1] -> $k {
302-
my $v := $obj[1]{$k};
303-
if $k eq 'total_time' {
304-
@profile[0] := ~$v;
305-
}
306-
elsif $k eq 'spesh_time' {
307-
@profile[1] := ~$v;
308-
}
309-
elsif $k eq 'gcs' {
310-
for $v -> $gc {
311-
my @g := nqp::list_s();
312-
for <time retained_bytes promoted_bytes gen2_roots full cleared_bytes start_time> -> $f {
313-
nqp::push_s(@g, ~($gc{$f} // '0'));
314-
}
315-
$profile_fh.say('INSERT INTO gcs VALUES (' ~ nqp::join(',', @g) ~ ');');
303+
for $obj -> $thread {
304+
my $thisprof := nqp::list;
305+
note($thread<thread>);
306+
for $thread -> $k {
307+
my $v := $thread{$k};
308+
if $k eq 'total_time' {
309+
$thisprof[0] := ~$v;
316310
}
317-
}
318-
elsif $k eq 'call_graph' {
319-
my %call_rec_depth;
320-
my int $node_id := 0;
321-
sub collect_calls(str $parent_id, %call_graph) {
322-
my str $call_id := ~$node_id;
323-
$node_id++;
324-
my @call := nqp::list_s($call_id, $parent_id);
325-
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all> -> $f {
326-
nqp::push_s(@call, ~(%call_graph{$f} // '0'));
311+
elsif $k eq 'spesh_time' {
312+
$thisprof[1] := ~$v;
313+
}
314+
elsif $k eq 'thread' {
315+
$thisprof[2] := ~$v;
316+
}
317+
elsif $k eq 'gcs' {
318+
for $v -> $gc {
319+
my @g := nqp::list_s();
320+
for <time retained_bytes promoted_bytes gen2_roots full responsible cleared_bytes start_time> -> $f {
321+
nqp::push_s(@g, ~($gc{$f} // '0'));
322+
}
323+
$profile_fh.say('INSERT INTO gcs VALUES (' ~ nqp::join(',', @g) ~ ');');
327324
}
328-
my str $routine_id := ~%call_graph<id>;
329-
%call_rec_depth{$routine_id} := 0 unless %call_rec_depth{$routine_id};
330-
nqp::push_s(@call, ~%call_rec_depth{$routine_id});
331-
$profile_fh.say('INSERT INTO calls VALUES (' ~ nqp::join(',', @call) ~ ');');
332-
if %call_graph<allocations> {
333-
for %call_graph<allocations> -> $a {
334-
my @a := nqp::list_s($call_id);
335-
for <id spesh jit count> -> $f {
336-
nqp::push_s(@a, ~($a{$f} // '0'));
325+
}
326+
elsif $k eq 'call_graph' {
327+
my %call_rec_depth;
328+
sub collect_calls(str $parent_id, %call_graph) {
329+
my str $call_id := ~$node_id;
330+
$node_id++;
331+
my @call := nqp::list_s($call_id, $parent_id);
332+
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all> -> $f {
333+
nqp::push_s(@call, ~(%call_graph{$f} // '0'));
334+
}
335+
my str $routine_id := ~%call_graph<id>;
336+
%call_rec_depth{$routine_id} := 0 unless %call_rec_depth{$routine_id};
337+
nqp::push_s(@call, ~%call_rec_depth{$routine_id});
338+
$profile_fh.say('INSERT INTO calls VALUES (' ~ nqp::join(',', @call) ~ ');');
339+
if %call_graph<allocations> {
340+
for %call_graph<allocations> -> $a {
341+
my @a := nqp::list_s($call_id);
342+
for <id spesh jit count> -> $f {
343+
nqp::push_s(@a, ~($a{$f} // '0'));
344+
}
345+
$profile_fh.say('INSERT INTO allocations VALUES (' ~ nqp::join(',', @a) ~ ');');
337346
}
338-
$profile_fh.say('INSERT INTO allocations VALUES (' ~ nqp::join(',', @a) ~ ');');
339347
}
340-
}
341-
if %call_graph<callees> {
342-
%call_rec_depth{$routine_id}++;
343-
for %call_graph<callees> -> $c {
344-
collect_calls(~$call_id, $c);
348+
if %call_graph<callees> {
349+
%call_rec_depth{$routine_id}++;
350+
for %call_graph<callees> -> $c {
351+
collect_calls(~$call_id, $c);
352+
}
353+
%call_rec_depth{$routine_id}--;
345354
}
346-
%call_rec_depth{$routine_id}--;
347355
}
356+
collect_calls(~$node_id, $v);
348357
}
349-
collect_calls(~$node_id, $v);
350358
}
359+
$profile_fh.say('INSERT INTO profile VALUES (' ~ nqp::join(',', $thisprof) ~ ');');
351360
}
352-
$profile_fh.say('INSERT INTO profile VALUES (' ~ nqp::join(',', @profile) ~ ');');
353361
}
354362

355363
# Post-process the call data, turning objects into flat data.
@@ -359,6 +367,8 @@ class HLL::Backend::MoarVM {
359367
}
360368
}
361369

370+
# The data array is normally a list of threads, but the first entry is
371+
# actually our mapping for filenames and type names and such.
362372
nqp::unshift($data, $id_to_thing);
363373

364374
# First make sure the template file exists if we want html
@@ -392,8 +402,8 @@ class HLL::Backend::MoarVM {
392402
$profile_fh.say('BEGIN;');
393403
$profile_fh.say('CREATE TABLE types(id INTEGER PRIMARY KEY ASC, name TEXT);');
394404
$profile_fh.say('CREATE TABLE routines(id INTEGER PRIMARY KEY ASC, name TEXT, line INT, file TEXT);');
395-
$profile_fh.say('CREATE TABLE profile(total_time INT, spesh_time INT);');
396-
$profile_fh.say('CREATE TABLE gcs(time INT, retained_bytes INT, promoted_bytes INT, gen2_roots INT, full INT, cleared_bytes INT, start_time INT);');
405+
$profile_fh.say('CREATE TABLE profile(total_time INT, spesh_time INT, thread_id INT);');
406+
$profile_fh.say('CREATE TABLE gcs(time INT, retained_bytes INT, promoted_bytes INT, gen2_roots INT, full INT, responsible INT, cleared_bytes INT, start_time INT);');
397407
$profile_fh.say('CREATE TABLE calls(id INTEGER PRIMARY KEY ASC, parent_id INT, routine_id INT, osr INT, spesh_entries INT, jit_entries INT, inlined_entries INT, inclusive_time INT, exclusive_time INT, entries INT, deopt_one INT, deopt_all INT, rec_depth INT, FOREIGN KEY(routine_id) REFERENCES routines(id));');
398408
$profile_fh.say('CREATE TABLE allocations(call_id INT, type_id INT, spesh INT, jit INT, count INT, PRIMARY KEY(call_id, type_id), FOREIGN KEY(call_id) REFERENCES calls(id), FOREIGN KEY(type_id) REFERENCES types(id));');
399409
to_sql($data);

0 commit comments

Comments
 (0)