From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: rostedt@goodmis.org, Douglas.Raillard@arm.com,
Valentin.Schneider@arm.com, nd@arm.com,
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH v2 08/12] trace-cruncher: Adapt page_faults.py to use the new module
Date: Tue, 7 Jan 2020 19:03:08 +0200 [thread overview]
Message-ID: <20200107170312.27116-9-y.karadz@gmail.com> (raw)
In-Reply-To: <20200107170312.27116-1-y.karadz@gmail.com>
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(-)
diff --git a/examples/page_faults.py b/examples/page_faults.py
index 446b12d..e0ce4e2 100755
--- a/examples/page_faults.py
+++ b/examples/page_faults.py
@@ -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()
--
2.20.1
next prev parent reply other threads:[~2020-01-07 17:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 17:03 [PATCH v2 00/12] Build trace-cruncher as Python pakage Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 01/12] trace-cruncher: Refactor the part of the interface that relies on libkshark Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 02/12] trace-cruncher: Refactor the part of the interface that relies on libtraceevent Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 03/12] trace-cruncher: Refactor NumPy based data wrapper Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 04/12] trace-cruncher: Add "utils" Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 05/12] trace-cruncher: Adapt sched_wakeup.py to use the new module Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 06/12] trace-cruncher: Add Makefile Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 07/12] trace-cruncher: Adapt gpareto_fit.py to use the new module Yordan Karadzhov (VMware)
2020-01-07 17:03 ` Yordan Karadzhov (VMware) [this message]
2020-01-07 17:03 ` [PATCH v2 09/12] trace-cruncher: Automate the third-party build Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 10/12] trace-cruncher: Update README.md Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 11/12] trace-cruncher: Remove all leftover files Yordan Karadzhov (VMware)
2020-01-07 17:03 ` [PATCH v2 12/12] trace-cruncher: Improve Makefile Provide more robust and better looking build process Yordan Karadzhov (VMware)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200107170312.27116-9-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=Douglas.Raillard@arm.com \
--cc=Valentin.Schneider@arm.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=nd@arm.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).