-
Notifications
You must be signed in to change notification settings - Fork 8
/
pluginMeasureCpu.py
99 lines (76 loc) · 2.7 KB
/
pluginMeasureCpu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import logging
import jc
from typing import Any
from typing import cast
import task
import pluginbase
import tftbase
from task import PluginTask
from task import TaskOperation
from testSettings import TestSettings
from tftbase import BaseOutput
from tftbase import PluginOutput
logger = logging.getLogger("tft." + __name__)
class PluginMeasureCpu(pluginbase.Plugin):
PLUGIN_NAME = "measure_cpu"
def _enable(
self,
*,
ts: TestSettings,
node_server_name: str,
node_client_name: str,
perf_server: task.ServerTask,
perf_client: task.ClientTask,
tenant: bool,
) -> list[PluginTask]:
return [
TaskMeasureCPU(ts, node_server_name, tenant),
TaskMeasureCPU(ts, node_client_name, tenant),
]
plugin = pluginbase.register_plugin(PluginMeasureCpu())
class TaskMeasureCPU(PluginTask):
@property
def plugin(self) -> pluginbase.Plugin:
return plugin
def __init__(self, ts: TestSettings, node_name: str, tenant: bool):
super().__init__(ts, 0, node_name, tenant)
self.in_file_template = "./manifests/tools-pod.yaml.j2"
self.out_file_yaml = (
f"./manifests/yamls/tools-pod-{self.node_name}-measure-cpu.yaml"
)
self.pod_name = f"tools-pod-{self.node_name}-measure-cpu"
self.node_name = node_name
def get_template_args(self) -> dict[str, str | list[str]]:
return {
**super().get_template_args(),
"pod_name": self.pod_name,
"test_image": tftbase.get_tft_test_image(),
}
def initialize(self) -> None:
super().initialize()
self.render_file("Server Pod Yaml")
def _create_task_operation(self) -> TaskOperation:
def _thread_action() -> BaseOutput:
self.ts.clmo_barrier.wait()
cmd = f"mpstat -P ALL {self.get_duration()} 1"
r = self.run_oc_exec(cmd)
data = r.out
# satisfy the linter. jc.parse returns a list of dicts in this case
parsed_data = cast(list[dict[str, Any]], jc.parse("mpstat", data))
return PluginOutput(
plugin_metadata=self.get_plugin_metadata(),
command=cmd,
result=parsed_data[0],
)
return TaskOperation(
log_name=self.log_name,
thread_action=_thread_action,
)
def _aggregate_output(
self,
result: tftbase.AggregatableOutput,
tft_result_builder: tftbase.TftResultBuilder,
) -> None:
result = tft_result_builder.add_plugin(result)
p_idle = result.result["percent_idle"]
logger.info(f"Idle on {self.node_name} = {p_idle}%")