Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions scripts/gdb/linux/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def list_for_each_entry(head, gdbtype, member):

def list_check(head):
nb = 0
if (head.type == list_head.get_type().pointer()):
if head.type == list_head.get_type().pointer():
head = head.dereference()
elif (head.type != list_head.get_type()):
elif head.type != list_head.get_type():
raise gdb.GdbError('argument must be of type (struct list_head [*])')
c = head
try:
Expand Down Expand Up @@ -90,9 +90,8 @@ def list_check(head):
current=c
))
return
c = n
nb += 1
if c == head:
if n == head:
gdb.write("list is consistent: {} node(s)\n".format(nb))
return

Expand All @@ -106,7 +105,7 @@ def __init__(self):

def invoke(self, arg, from_tty):
argv = gdb.string_to_argv(arg)
if len(argv) != 1:
if not argv:
raise gdb.GdbError("lx-list-check takes one argument")
list_check(gdb.parse_and_eval(argv[0]))

Expand Down
56 changes: 15 additions & 41 deletions tools/perf/scripts/python/intel-pt-events.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def trace_end():
print "End"

def trace_unhandled(event_name, context, event_fields_dict):
print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
print " ".join("%s=%s" % pair for pair in sorted(event_fields_dict.items()))

def print_ptwrite(raw_buf):
data = struct.unpack_from("<IQ", raw_buf)
Expand All @@ -42,47 +42,46 @@ def print_cbr(raw_buf):
cbr = data[0]
f = (data[4] + 500) / 1000
p = ((cbr * 1000 / data[2]) + 5) / 10
print "%3u freq: %4u MHz (%3u%%)" % (cbr, f, p),
print "%3u freq: %4u MHz (%3u%%)" % (cbr, f, p)

def print_mwait(raw_buf):
data = struct.unpack_from("<IQ", raw_buf)
payload = data[1]
hints = payload & 0xff
extensions = (payload >> 32) & 0x3
print "hints: %#x extensions: %#x" % (hints, extensions),
print "hints: %#x extensions: %#x" % (hints, extensions)

def print_pwre(raw_buf):
data = struct.unpack_from("<IQ", raw_buf)
payload = data[1]
hw = (payload >> 7) & 1
cstate = (payload >> 12) & 0xf
subcstate = (payload >> 8) & 0xf
print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate)

def print_exstop(raw_buf):
data = struct.unpack_from("<I", raw_buf)
flags = data[0]
exact_ip = flags & 1
print "IP: %u" % (exact_ip),
print "IP: %u" % exact_ip

def print_pwrx(raw_buf):
data = struct.unpack_from("<IQ", raw_buf)
payload = data[1]
deepest_cstate = payload & 0xf
last_cstate = (payload >> 4) & 0xf
wake_reason = (payload >> 8) & 0xf
print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason)

def print_common_start(comm, sample, name):
ts = sample["time"]
cpu = sample["cpu"]
pid = sample["pid"]
tid = sample["tid"]
print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10**9, ts % 10**9, name)

def print_common_ip(sample, symbol, dso):
ip = sample["ip"]
print "%16x %s (%s)" % (ip, symbol, dso)
print "%16x %s (%s)" % (sample["ip"], symbol, dso)

def process_event(param_dict):
event_attr = param_dict["attr"]
Expand All @@ -92,37 +91,12 @@ def process_event(param_dict):
name = param_dict["ev_name"]

# Symbol and dso info are not always resolved
if (param_dict.has_key("dso")):
dso = param_dict["dso"]
else:
dso = "[unknown]"

if (param_dict.has_key("symbol")):
symbol = param_dict["symbol"]
else:
symbol = "[unknown]"

if name == "ptwrite":
print_common_start(comm, sample, name)
print_ptwrite(raw_buf)
print_common_ip(sample, symbol, dso)
elif name == "cbr":
print_common_start(comm, sample, name)
print_cbr(raw_buf)
print_common_ip(sample, symbol, dso)
elif name == "mwait":
print_common_start(comm, sample, name)
print_mwait(raw_buf)
print_common_ip(sample, symbol, dso)
elif name == "pwre":
print_common_start(comm, sample, name)
print_pwre(raw_buf)
print_common_ip(sample, symbol, dso)
elif name == "exstop":
print_common_start(comm, sample, name)
print_exstop(raw_buf)
print_common_ip(sample, symbol, dso)
elif name == "pwrx":
dso = param_dict.get("dso", "[unknown]")
symbol = param_dict.get("symbol", "[unknown")

func = globals().get("print_%s" % name, None)

if func is not None:
print_common_start(comm, sample, name)
print_pwrx(raw_buf)
func(raw_buf)
print_common_ip(sample, symbol, dso)
41 changes: 18 additions & 23 deletions tools/perf/scripts/python/mem-phys-addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@

def parse_iomem():
global f
f = open('/proc/iomem', 'r')
f = open('/proc/iomem')
for i, j in enumerate(f):
m = re.split('-|:',j,2)
if m[2].strip() == 'System RAM':
system_ram.append(long(m[0], 16))
system_ram.append(long(m[1], 16))
if m[2].strip() == 'Persistent Memory':
pmem.append(long(m[0], 16))
pmem.append(long(m[1], 16))
m = re.split('-|:', j, 2)
m[2] = m[2].strip()
if m[2] == 'System RAM':
system_ram.extend([long(m[0], 16), long(m[1], 16)])
elif m[2] == 'Persistent Memory':
pmem.extend([long(m[0], 16), long(m[1], 16)])

def print_memory_type():
print "Event: %s" % (event_name)
print "Event: %s" % event_name
print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"),
print "%-40s %10s %10s\n" % ("----------------------------------------", \
"-----------", "-----------"),
total = sum(load_mem_type_cnt.values())
for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
key = lambda(k, v): (v, k), reverse = True):
for mem_type, count in sorted(load_mem_type_cnt.most_common(),
key = lambda k, v: v, k,
reverse = True):
print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total),

def trace_begin():
Expand All @@ -57,29 +57,24 @@ def trace_end():
def is_system_ram(phys_addr):
#/proc/iomem is sorted
position = bisect.bisect(system_ram, phys_addr)
if position % 2 == 0:
return False
return True
return position & 1

def is_persistent_mem(phys_addr):
position = bisect.bisect(pmem, phys_addr)
if position % 2 == 0:
return False
return True
return position & 1

def find_memory_type(phys_addr):
if phys_addr == 0:
if not phys_addr:
return "N/A"
if is_system_ram(phys_addr):
elif is_system_ram(phys_addr):
return "System RAM"

if is_persistent_mem(phys_addr):
elif is_persistent_mem(phys_addr):
return "Persistent Memory"

#slow path, search all
f.seek(0, 0)
for j in f:
m = re.split('-|:',j,2)
m = re.split('-|:', j, 2)
if long(m[0], 16) <= phys_addr <= long(m[1], 16):
return m[2]
return "N/A"
Expand All @@ -90,6 +85,6 @@ def process_event(param_dict):
phys_addr = sample["phys_addr"]

global event_name
if event_name == None:
if event_name is None:
event_name = name
load_mem_type_cnt[find_memory_type(phys_addr)] += 1
15 changes: 7 additions & 8 deletions tools/perf/scripts/python/net_dropmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def get_kallsyms_table():
global kallsyms

try:
f = open("/proc/kallsyms", "r")
except:
f = open("/proc/kallsyms")
except IOError:
return

for line in f:
Expand All @@ -45,9 +45,8 @@ def get_sym(sloc):
# and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0])
if start >= 0:
symloc, name = kallsyms[start]
return (name, loc - symloc)
else:
return (None, 0)
return name, loc - symloc
return None, 0

def print_drop_table():
print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
Expand All @@ -66,11 +65,11 @@ def trace_end():
get_kallsyms_table()
print_drop_table()

# called from perf, when it finds a correspoinding event
# called from perf, when it finds a corresponding event
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain,
skbaddr, location, protocol):
slocation = str(location)
try:
drop_log[slocation] = drop_log[slocation] + 1
except:
drop_log[slocation] += 1
except TypeError:
drop_log[slocation] = 1
Loading