@@ -9,20 +9,14 @@ Copyright 2019 VMware Inc, Yordan Karadzhov <ykaradzhov@vmware.com>
import os
import sys
import subprocess as sp
-import json
-
import pprint as pr
-import matplotlib.pyplot as plt
-import scipy.stats as st
-import numpy as np
from collections import Counter
from tabulate import tabulate
-from ksharksetup import setup
-# Always call setup() before importing ksharkpy!!!
-setup()
-
-import ksharkpy as ks
+from tracecruncher import datawrapper as dw
+from tracecruncher import ksharkpy as ks
+from tracecruncher import ftracepy as ft
+import tracecruncher.utils as tc
def gdb_decode_address(obj_file, obj_address):
""" Use gdb to examine the contents of the memory at this
@@ -33,7 +27,7 @@ def gdb_decode_address(obj_file, obj_address):
'-ex',
'x/i ' + str(obj_address),
obj_file],
- stdout=sp.PIPE)
+ stdout=sp.PIPE)
symbol = result.stdout.decode("utf-8").splitlines()
@@ -49,35 +43,35 @@ def gdb_decode_address(obj_file, obj_address):
# Get the name of the tracing data file.
fname = str(sys.argv[1])
-ks.open_file(fname)
+ks.open(fname)
ks.register_plugin('reg_pid')
-data = ks.load_data()
+data = dw.load()
tasks = ks.get_tasks()
#pr.pprint(tasks)
# Get the Event Ids of the page_fault_user or page_fault_kernel events.
-pf_eid = ks.event_id('exceptions', 'page_fault_user')
+pf_eid = ft.event_id('exceptions', 'page_fault_user')
# Gey the size of the data.
-d_size = ks.data_size(data)
+d_size = tc.size(data)
# Get the name of the user program.
prog_name = str(sys.argv[2])
table_headers = ['N p.f.', 'function', 'value', 'obj. file']
-table_list = []
# Loop over all tasks associated with the user program.
for j in range(len(tasks[prog_name])):
+ table_list = []
count = Counter()
task_pid = tasks[prog_name][j]
for i in range(0, d_size):
if data['event'][i] == pf_eid and data['pid'][i] == task_pid:
- address = ks.read_event_field(offset=data['offset'][i],
+ address = ft.read_event_field(offset=data['offset'][i],
event_id=pf_eid,
field='address')
- ip = ks.read_event_field(offset=data['offset'][i],
+ ip = ft.read_event_field(offset=data['offset'][i],
event_id=pf_eid,
field='ip')
count[ip] += 1
@@ -92,29 +86,27 @@ for j in range(len(tasks[prog_name])):
if i_max > len(pf_list):
i_max = len(pf_list)
+ #print(pf_list[:25])
for i in range(0, i_max):
- func = ks.get_function(pf_list[i][0])
- func_info = [func]
- if func.startswith('0x'):
- # The name of the function cannot be determined. We have an
- # instruction pointer instead. Most probably this is a user-space
- # function.
- address = int(func, 0)
- instruction = ks.map_instruction_address(task_pid, address)
-
- if instruction['obj_file'] != 'UNKNOWN':
+ func_info = []
+ address = int(pf_list[i][0])
+ func = ft.get_function(address)
+ if not func :
+ # The name of the function cannot be determined. Most probably
+ # this is a user-space function.
+ instruction = ft.map_instruction_address(pid=task_pid,
+ proc_addr=address)
+ if instruction:
func_info = gdb_decode_address(instruction['obj_file'],
instruction['address'])
else:
- func_info += ['', instruction['obj_file']]
-
- else:
- func_info = [func]
+ func_info = ['addr: ' + hex(address), 'UNKNOWN']
table_list.append([pf_list[i][1]] + func_info)
-ks.close()
+ print('\n{}-{}\n'.format(prog_name, task_pid),
+ tabulate(table_list,
+ headers=table_headers,
+ tablefmt='simple'))
-print("\n", tabulate(table_list,
- headers=table_headers,
- tablefmt='simple'))
+ks.close()
The patch contains some debugging as well. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- examples/page_faults.py | 64 ++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 36 deletions(-)