from collections import MutableMapping
import ctypes as ct
+from functools import reduce
import multiprocessing
import os
def sum(self, key):
if isinstance(self.Leaf(), ct.Structure):
raise IndexError("Leaf must be an integer type for default sum functions")
- return self.sLeaf(reduce(lambda x,y: x+y, self.getvalue(key)))
+ return self.sLeaf(sum(self.getvalue(key)))
def max(self, key):
if isinstance(self.Leaf(), ct.Structure):
def average(self, key):
result = self.sum(key)
- result.value/=self.total_cpu
- return result
+ return result.value / self.total_cpu
class LruPerCpuHash(PerCpuHash):
def __init__(self, *args, **kwargs):
def sum(self, key):
if isinstance(self.Leaf(), ct.Structure):
raise IndexError("Leaf must be an integer type for default sum functions")
- return self.sLeaf(reduce(lambda x,y: x+y, self.getvalue(key)))
+ return self.sLeaf(sum(self.getvalue(key)))
def max(self, key):
if isinstance(self.Leaf(), ct.Structure):
def average(self, key):
result = self.sum(key)
- result.value/=self.total_cpu
- return result
+ return result.value / self.total_cpu
class StackTrace(TableBase):
MAX_DEPTH = 127
COMMAND ${TEST_WRAPPER} py_test_perf_event sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_perf_event.py)
add_test(NAME py_test_utils WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_test_utils sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_utils.py)
+add_test(NAME py_test_percpu WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND ${TEST_WRAPPER} py_test_percpu sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_percpu.py)
add_test(NAME py_test_dump_func WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_dump_func simple ${CMAKE_CURRENT_SOURCE_DIR}/test_dump_func.py)
sum = stats_map.sum(stats_map.Key(0))
avg = stats_map.average(stats_map.Key(0))
max = stats_map.max(stats_map.Key(0))
- self.assertGreater(sum.value, 0L)
- self.assertGreater(max.value, 0L)
+ self.assertGreater(sum.value, int(0))
+ self.assertGreater(max.value, int(0))
bpf_code.detach_kprobe("sys_clone")
def test_u32(self):
sum = stats_map.sum(stats_map.Key(0))
avg = stats_map.average(stats_map.Key(0))
max = stats_map.max(stats_map.Key(0))
- self.assertGreater(sum.value, 0L)
- self.assertGreater(max.value, 0L)
+ self.assertGreater(sum.value, int(0))
+ self.assertGreater(max.value, int(0))
bpf_code.detach_kprobe("sys_clone")
def test_struct_custom_func(self):
f.close()
self.assertEqual(len(stats_map),1)
k = stats_map[ stats_map.Key(0) ]
- self.assertGreater(k.c1, 0L)
+ self.assertGreater(k.c1, int(0))
bpf_code.detach_kprobe("sys_clone")