Skip to content

Commit

Permalink
repair markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cskorpion committed Apr 29, 2024
1 parent 4bf7431 commit 5d47722
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
19 changes: 14 additions & 5 deletions vmprofconvert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def walk_pypylog(self, pypylog):# Problem: tracing[ backend[ backend] backend[ b
ppl_stack.append(log)
if last_log[PPL_ACTION] == log[PPL_ACTION]: # Only top level actions wanted e.g. A[ B[ B]A] => Sample: A->B not A->B, A
self.add_pypylog_sample_from_stack(plthread, ppl_stack)
plthread.create_single_pypylog_marker(ppl_stack[-2], ppl_stack[-1])
assert log[PPL_ACTION] == ppl_stack[-1][PPL_ACTION]
ppl_stack.pop()
ppl_stack.pop()
Expand All @@ -130,9 +131,10 @@ def add_pypylog_sample_from_stack(self, thread, stack_list):
start_time = stack_list[-2][PPL_TIME]
end_time = stack_list[-1][PPL_TIME]
thread.add_sample(stackindex, start_time)
thread.add_sample(stackindex, end_time)
if end_time - start_time > 3:
pass ### TODO: interpreter sample
thread.add_sample(stackindex, end_time)
#if len(thread.samples) > 2:
#if start_time - thread.samples[-3][1] >= 3:
#self.add_pypylog_interp_sample(thread, thread.samples[-3][1] + 1, start_time - 1)


def add_pypylog_sample(self, thread, logname, logtime_start, logtime_end):
Expand All @@ -145,11 +147,11 @@ def add_pypylog_sample(self, thread, logname, logtime_start, logtime_end):
thread.add_sample(stackindex, logtime_start)
thread.add_sample(stackindex, logtime_end)

def add_pypylog_interp_sample(self, thread, logtime_end, next_logtime_start):
def add_pypylog_interp_sample(self, thread, logtime_start, logtime_end):
frameindex = thread.add_frame("interp", -1, "", CATEGORY_INTERPRETER, -1, -1)
stackindex = thread.add_stack([frameindex], [CATEGORY_INTERPRETER])
thread.add_sample(stackindex, logtime_start)
thread.add_sample(stackindex, logtime_end)
thread.add_sample(stackindex, next_logtime_start)


def walk_samples(self, stats):
Expand Down Expand Up @@ -485,6 +487,13 @@ def create_pypylog_marker(self, pypylog):
next_logtime_start = next_log[0]
if abs(endtime - next_logtime_start) > 2:
self.add_marker(endtime + 1, next_logtime_start - 1, interperter_string_id)

def create_single_pypylog_marker(self, start_log, stop_log):
starttime = start_log[PPL_TIME]
endtime = stop_log[PPL_TIME]
name = start_log[PPL_ACTION]
st_id = self.add_string(name)
self.add_marker(starttime, endtime, st_id)

def add_marker(self, starttime, endtime, stringtable_index):
self.markers.append([starttime, endtime, stringtable_index])
Expand Down
17 changes: 9 additions & 8 deletions vmprofconvert/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_add_pypylog_interp_sample():
assert samples[1] == [0, 117]
assert stacktable[0] == [0, None, CATEGORY_INTERPRETER]

def _test_walk_pypylog(): ### TODO: re-enable as soon as interpreter frames can be created again
def test_walk_pypylog(): ### TODO: re-enable assert as soon as interpreter frames can be created again
c = Converter()
test_pypylog = [
[7, "gc_example_action_a", True, 0],
Expand All @@ -481,8 +481,8 @@ def _test_walk_pypylog(): ### TODO: re-enable as soon as interpreter frames can
c.walk_pypylog(test_pypylog)
t = c.threads[7]
stringarray = t.stringarray
assert stringarray[0] == "interpreter"
assert stringarray[1] == "gc_example_action_a"
#assert stringarray[0] == "interpreter"
assert stringarray[0] == "gc_example_action_a"

def test_walk_full_pypylog():
c = Converter()
Expand Down Expand Up @@ -521,8 +521,9 @@ def test_walk_full_pypylog():

assert funcname_0 == "gc_example_action_c" # action c is a top level action
assert funcname_2 == "gc_example_action_a" # action a is a top level action, but c should be at index 0
assert len(samples) == 4# there shall be only four samples

#assert samples[4][1] == 4
#assert samples[5][1] == 5
assert len(samples) == 4# there should be only four samples 2x action c, 2x action a

def test_dumps_vmprof_without_pypylog():
vmprof_path = os.path.join(os.path.dirname(__file__), "profiles/vmprof_cpuburn.prof")
Expand All @@ -535,7 +536,7 @@ def test_dumps_vmprof_without_pypylog():
assert len(samples["stack"]) == 5551
assert markers["data"] == []

def _test_dumps_vmprof_with_pypylog(): ### TODO: re-enable as soon as interpreter frames can be created again
def test_dumps_vmprof_with_pypylog(): ### TODO: re-enable assert as soon as interpreter frames can be created again
vmprof_path = os.path.join(os.path.dirname(__file__), "profiles/vmprof_cpuburn.prof")
pypylog_path = os.path.join(os.path.dirname(__file__), "profiles/pystone.pypylog")
times = (0, 42.368387)
Expand All @@ -544,8 +545,8 @@ def _test_dumps_vmprof_with_pypylog(): ### TODO: re-enable as soon as interpret
samples = profile["threads"][0]["samples"]
stringarray = profile["threads"][1]["stringArray"]
assert len(samples["stack"]) == 5551
assert stringarray[0] == "interpreter"
assert stringarray[1] == "gc-set-nursery-size"
#assert stringarray[0] == "interpreter"
assert stringarray[0] == "gc-set-nursery-size"

def test_write_file_dict():
file_dict = {
Expand Down

0 comments on commit 5d47722

Please sign in to comment.