本文整理汇总了Python中trace.Trace.getTasks方法的典型用法代码示例。如果您正苦于以下问题:Python Trace.getTasks方法的具体用法?Python Trace.getTasks怎么用?Python Trace.getTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trace.Trace
的用法示例。
在下文中一共展示了Trace.getTasks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTrace
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import getTasks [as 别名]
class TestTrace(TestCase):
"""Smoke tests for LISA's Trace class"""
traces_dir = os.path.join(os.path.dirname(__file__), 'traces')
events = [
'sched_switch',
'sched_overutilized',
'cpu_idle',
]
def __init__(self, *args, **kwargs):
super(TestTrace, self).__init__(*args, **kwargs)
self.test_trace = os.path.join(self.traces_dir, 'test_trace.txt')
self.platform = self._get_platform()
self.trace_path = os.path.join(self.traces_dir, 'trace.txt')
self.trace = Trace(self.platform, self.trace_path, self.events)
def make_trace(self, in_data):
with open(self.test_trace, "w") as fout:
fout.write(in_data)
return Trace(self.platform, self.test_trace, self.events,
normalize_time=False)
def _get_platform(self):
with open(os.path.join(self.traces_dir, 'platform.json')) as f:
return json.load(f)
def test_getTaskByName(self):
"""TestTrace: getTaskByName() returns the list of PIDs for all tasks with the specified name"""
for name, pids in [('watchdog/0', [12]),
('sh', [1642, 1702, 1717, 1718]),
('NOT_A_TASK', [])]:
self.assertEqual(self.trace.getTaskByName(name), pids)
def test_getTaskByPid(self):
"""TestTrace: getTaskByPid() returns the name of the task with the specified PID"""
for pid, names in [(15, 'watchdog/1'),
(1639, 'sshd'),
(987654321, None)]:
self.assertEqual(self.trace.getTaskByPid(pid), names)
def test_getTasks(self):
"""TestTrace: getTasks() returns a dictionary mapping PIDs to a single task name"""
tasks_dict = self.trace.getTasks()
for pid, name in [(1, 'init'),
(9, 'rcu_sched'),
(1383, 'jbd2/sda2-8')]:
self.assertEqual(tasks_dict[pid], name)
def test_setTaskName(self):
"""TestTrace: getTaskBy{Pid,Name}() properly track tasks renaming"""
in_data = """
father-1234 [002] 18765.018235: sched_switch: prev_comm=father prev_pid=1234 prev_prio=120 prev_state=0 next_comm=father next_pid=5678 next_prio=120
child-5678 [002] 18766.018236: sched_switch: prev_comm=child prev_pid=5678 prev_prio=120 prev_state=1 next_comm=sh next_pid=3367 next_prio=120
"""
trace = self.make_trace(in_data)
self.assertEqual(trace.getTaskByPid(1234), 'father')
self.assertEqual(trace.getTaskByPid(5678), 'child')
self.assertEqual(trace.getTaskByName('father'), [1234])
os.remove(self.test_trace)
def test_time_range(self):
"""
TestTrace: time_range is the duration of the trace
"""
expected_duration = 6.676497
trace = Trace(self.platform, self.trace_path,
self.events, normalize_time=False
)
self.assertAlmostEqual(trace.time_range, expected_duration, places=6)
def test_time_range_window(self):
"""
TestTrace: time_range is the duration of the trace in the given window
"""
expected_duration = 4.0
trace = Trace(self.platform, self.trace_path,
self.events, normalize_time=False,
window=(76.402065, 80.402065)
)
self.assertAlmostEqual(trace.time_range, expected_duration, places=6)
def test_overutilized_time(self):
"""
TestTrace: overutilized_time is the total time spent while system was overutilized
"""
events = [
76.402065,
80.402065,
82.001337
#.........这里部分代码省略.........
示例2: TestTrace
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import getTasks [as 别名]
class TestTrace(TestCase):
"""Smoke tests for LISA's Trace class"""
traces_dir = os.path.join(os.path.dirname(__file__), 'traces')
events = [
'sched_switch',
'sched_overutilized',
'cpu_idle',
'sched_load_avg_task',
'sched_load_se'
]
def __init__(self, *args, **kwargs):
super(TestTrace, self).__init__(*args, **kwargs)
self.test_trace = os.path.join(self.traces_dir, 'test_trace.txt')
self.platform = self._get_platform()
self.trace_path = os.path.join(self.traces_dir, 'trace.txt')
self.trace = Trace(self.platform, self.trace_path, self.events)
def make_trace(self, in_data):
"""
Get a trace from an embedded string of textual trace data
"""
with open(self.test_trace, "w") as fout:
fout.write(in_data)
return Trace(self.platform, self.test_trace, self.events,
normalize_time=False)
def get_trace(self, trace_name):
"""
Get a trace from a separate provided trace file
"""
dir = os.path.join(self.traces_dir, trace_name)
trace_path = os.path.join(dir, 'trace.dat')
return Trace(self._get_platform(trace_name), trace_path, self.events)
def _get_platform(self, trace_name=None):
trace_dir = self.traces_dir
if trace_name:
trace_dir = os.path.join(trace_dir, trace_name)
with open(os.path.join(trace_dir, 'platform.json')) as f:
return json.load(f)
def test_getTaskByName(self):
"""TestTrace: getTaskByName() returns the list of PIDs for all tasks with the specified name"""
for name, pids in [('watchdog/0', [12]),
('sh', [1642, 1702, 1717, 1718]),
('NOT_A_TASK', [])]:
self.assertEqual(self.trace.getTaskByName(name), pids)
def test_getTaskByPid(self):
"""TestTrace: getTaskByPid() returns the name of the task with the specified PID"""
for pid, names in [(15, 'watchdog/1'),
(1639, 'sshd'),
(987654321, None)]:
self.assertEqual(self.trace.getTaskByPid(pid), names)
def test_getTasks(self):
"""TestTrace: getTasks() returns a dictionary mapping PIDs to a single task name"""
tasks_dict = self.trace.getTasks()
for pid, name in [(1, 'init'),
(9, 'rcu_sched'),
(1383, 'jbd2/sda2-8')]:
self.assertEqual(tasks_dict[pid], name)
def test_setTaskName(self):
"""TestTrace: getTaskBy{Pid,Name}() properly track tasks renaming"""
in_data = """
father-1234 [002] 18765.018235: sched_switch: prev_comm=father prev_pid=1234 prev_prio=120 prev_state=0 next_comm=father next_pid=5678 next_prio=120
child-5678 [002] 18766.018236: sched_switch: prev_comm=child prev_pid=5678 prev_prio=120 prev_state=1 next_comm=sh next_pid=3367 next_prio=120
"""
trace = self.make_trace(in_data)
self.assertEqual(trace.getTaskByPid(1234), 'father')
self.assertEqual(trace.getTaskByPid(5678), 'child')
self.assertEqual(trace.getTaskByName('father'), [1234])
os.remove(self.test_trace)
def test_time_range(self):
"""
TestTrace: time_range is the duration of the trace
"""
expected_duration = 6.676497
trace = Trace(self.platform, self.trace_path,
self.events, normalize_time=False
)
self.assertAlmostEqual(trace.time_range, expected_duration, places=6)
def test_time_range_window(self):
"""
TestTrace: time_range is the duration of the trace in the given window
#.........这里部分代码省略.........
示例3: TestTrace
# 需要导入模块: from trace import Trace [as 别名]
# 或者: from trace.Trace import getTasks [as 别名]
class TestTrace(TestCase):
"""Smoke tests for LISA's Trace class"""
traces_dir = os.path.join(os.path.dirname(__file__), 'traces')
events = [
'sched_switch',
'sched_overutilized',
'cpu_idle',
'sched_load_avg_task',
'sched_load_se'
]
FLOAT_PLACES=6
def __init__(self, *args, **kwargs):
super(TestTrace, self).__init__(*args, **kwargs)
self.test_trace = os.path.join(self.traces_dir, 'test_trace.txt')
self.platform = self._get_platform()
self.trace_path = os.path.join(self.traces_dir, 'trace.txt')
self.trace = Trace(self.trace_path, self.events, self.platform)
def make_trace(self, in_data):
"""
Get a trace from an embedded string of textual trace data
"""
with open(self.test_trace, "w") as fout:
fout.write(in_data)
return Trace(self.test_trace, self.events,
self.platform, normalize_time=False)
def get_trace(self, trace_name):
"""
Get a trace from a separate provided trace file
"""
dir = os.path.join(self.traces_dir, trace_name)
trace_path = os.path.join(dir, 'trace.dat')
return Trace(trace_path, self.events,
self._get_platform(trace_name))
def _get_platform(self, trace_name=None):
trace_dir = self.traces_dir
if trace_name:
trace_dir = os.path.join(trace_dir, trace_name)
with open(os.path.join(trace_dir, 'platform.json')) as f:
return json.load(f)
def test_getTaskByName(self):
"""TestTrace: getTaskByName() returns the list of PIDs for all tasks with the specified name"""
for name, pids in [('watchdog/0', [12]),
('sh', [1642, 1702, 1717, 1718]),
('NOT_A_TASK', [])]:
self.assertEqual(self.trace.getTaskByName(name), pids)
def test_getTaskByPid(self):
"""TestTrace: getTaskByPid() returns the name of the task with the specified PID"""
for pid, names in [(15, 'watchdog/1'),
(1639, 'sshd'),
(987654321, None)]:
self.assertEqual(self.trace.getTaskByPid(pid), names)
def test_getTasks(self):
"""TestTrace: getTasks() returns a dictionary mapping PIDs to a single task name"""
tasks_dict = self.trace.getTasks()
for pid, name in [(1, 'init'),
(9, 'rcu_sched'),
(1383, 'jbd2/sda2-8')]:
self.assertEqual(tasks_dict[pid], name)
def test_setTaskName(self):
"""TestTrace: getTaskBy{Pid,Name}() properly track tasks renaming"""
in_data = """
father-1234 [002] 18765.018235: sched_switch: prev_comm=father prev_pid=1234 prev_prio=120 prev_state=0 next_comm=father next_pid=5678 next_prio=120
child-5678 [002] 18766.018236: sched_switch: prev_comm=child prev_pid=5678 prev_prio=120 prev_state=1 next_comm=sh next_pid=3367 next_prio=120
"""
trace = self.make_trace(in_data)
self.assertEqual(trace.getTaskByPid(1234), 'father')
self.assertEqual(trace.getTaskByPid(5678), 'child')
self.assertEqual(trace.getTaskByName('father'), [1234])
os.remove(self.test_trace)
def test_time_range(self):
"""
TestTrace: time_range is the duration of the trace
"""
expected_duration = 6.676497
trace = Trace(self.trace_path,
self.events,
self.platform,
normalize_time=False
)
#.........这里部分代码省略.........