Skip to content

Commit 5bca06f

Browse files
committed
Added alternatives to tdp-finder.py
Now it is possible to find the cpu power from raw details, like `/proc/cpuinfo` or the raw model name.
1 parent 0c0e651 commit 5bca06f

9 files changed

Lines changed: 314 additions & 120 deletions

File tree

cpuinfo-tdp-finder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
# treecript, a process tree metrics gatherer.
6+
# Copyright (C) 2026 Barcelona Supercomputing Center, José M. Fernández
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful, but
14+
# WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
from treecript.tdp_finder import main_cpuinfo_tdp_finder
22+
23+
if __name__ == "__main__":
24+
main_cpuinfo_tdp_finder()

modelname-tdp-finder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
# treecript, a process tree metrics gatherer.
6+
# Copyright (C) 2026 Barcelona Supercomputing Center, José M. Fernández
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful, but
14+
# WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
from treecript.tdp_finder import main_modelname_tdp_finder
22+
23+
if __name__ == "__main__":
24+
main_modelname_tdp_finder()

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767
]
6868
},
6969
scripts=[
70+
"cpuinfo-tdp-finder.py",
7071
"execution-metrics-collector.py",
7172
"process-metrics-collector.py",
7273
"metrics-aggregator.py",
74+
"modelname-tdp-finder.py",
7375
"plotGraph.py",
7476
"tdp-finder.py",
7577
"execution-metrics-collector.sh",

tdp-finder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# You should have received a copy of the GNU General Public License
1919
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2020

21-
from treecript.tdp_finder import main
21+
from treecript.tdp_finder import main_tdp_finder
2222

2323
if __name__ == "__main__":
24-
main()
24+
main_tdp_finder()

tests/core/test_collector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import subprocess
2626

2727
from treecript.collector import execution_metrics_collector
28-
from treecript.tdp_finder import tdp_finder
28+
from treecript.tdp_finder import tdp_finder_from_series
2929

3030
from typing import (
3131
TYPE_CHECKING,
@@ -88,7 +88,7 @@ def test_collector(
8888

8989

9090
@COLLECTOR_TESTBED
91-
def test_tdp_finder(
91+
def test_tdp_finder_from_series(
9292
tmpdir: "str",
9393
command_line: "Sequence[str]",
9494
should_fail: "Optional[Sequence[str]]",
@@ -110,7 +110,7 @@ def test_tdp_finder(
110110
assert processors_file.exists()
111111

112112
try:
113-
tdp_finder(metrics_path, processors_file)
113+
tdp_finder_from_series(metrics_path, processors_file)
114114
except BaseException:
115115
current_frame = inspect.currentframe()
116116
if (

treecript/collector.py

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
if TYPE_CHECKING:
4343
from typing import (
4444
Any,
45-
Final,
4645
Mapping,
4746
MutableMapping,
4847
MutableSequence,
@@ -52,78 +51,23 @@
5251
Tuple,
5352
)
5453

55-
from typing_extensions import (
56-
TypeAlias,
57-
)
58-
59-
CPUInfo: TypeAlias = MutableMapping[str, Any]
60-
61-
CPU_DETAILS_FILENAME: "Final[str]" = "cpu_details.json"
62-
CORE_AFFINITY_FILENAME: "Final[str]" = "core_affinity.json"
63-
REFERENCE_PID_FILENAME: "Final[str]" = "reference_pid.txt"
64-
SAMPLING_PERIOD_FILENAME: "Final[str]" = "sampling-period-seconds.txt"
65-
PIDS_FILENAME: "Final[str]" = "pids.txt"
66-
AGGREGATION_METRICS_FILENAME: "Final[str]" = "agg_metrics.tsv"
67-
68-
METRICS_CSV_FILENAME_TEMPLATE: "Final[str]" = "metrics-{0}_{1}.csv"
69-
COMMAND_TXT_FILENAME_TEMPLATE: "Final[str]" = "command-{0}_{1}.txt"
70-
COMMAND_JSON_FILENAME_TEMPLATE: "Final[str]" = "command-{0}_{1}.json"
54+
from .common import (
55+
AGGREGATION_METRICS_FILENAME,
56+
COMMAND_JSON_FILENAME_TEMPLATE,
57+
COMMAND_TXT_FILENAME_TEMPLATE,
58+
CPU_DETAILS_FILENAME,
59+
CORE_AFFINITY_FILENAME,
60+
METRICS_CSV_FILENAME_TEMPLATE,
61+
PIDS_FILENAME,
62+
REFERENCE_PID_FILENAME,
63+
SAMPLING_PERIOD_FILENAME,
64+
parse_cpuinfo,
65+
)
7166

7267
# Module level logger
7368
logger = logging.getLogger(__name__)
7469

7570

76-
def parse_cpuinfo(
77-
cpuinfo_filename: "str" = "/proc/cpuinfo",
78-
) -> "Tuple[Mapping[str, CPUInfo], Mapping[str, Tuple[str, str]]]":
79-
kvsplitter = re.compile(r"\s*:\s*")
80-
81-
entries = []
82-
curr_entry: "CPUInfo" = dict()
83-
cpu_hash: "MutableMapping[str, CPUInfo]" = {}
84-
processor2corecpu: "MutableMapping[str, Tuple[str, str]]" = {}
85-
with open(cpuinfo_filename, mode="r", encoding="latin1") as cH:
86-
for line in cH:
87-
line = line.rstrip("\n")
88-
tokens = kvsplitter.split(line)
89-
if len(tokens) < 2:
90-
entries.append(curr_entry)
91-
physical_id = curr_entry.get("physical id")
92-
assert isinstance(physical_id, str)
93-
processor = curr_entry.get("processor")
94-
assert isinstance(processor, str)
95-
if physical_id in cpu_hash:
96-
curr_cpu = cpu_hash[physical_id]
97-
else:
98-
curr_cpu = copy.copy(curr_entry)
99-
curr_cpu["processors"] = []
100-
cpu_hash[physical_id] = curr_cpu
101-
curr_cpu["processors"].append(processor)
102-
core_id = curr_entry.get("core id")
103-
assert isinstance(core_id, str)
104-
processor2corecpu[processor] = (physical_id, core_id)
105-
curr_entry = dict()
106-
else:
107-
curr_entry[tokens[0]] = tokens if len(tokens) > 2 else tokens[1]
108-
if curr_entry:
109-
entries.append(curr_entry)
110-
physical_id = curr_entry.get("physical id")
111-
assert isinstance(physical_id, str)
112-
processor = curr_entry.get("processor")
113-
assert isinstance(processor, str)
114-
if physical_id in cpu_hash:
115-
curr_cpu = cpu_hash[physical_id]
116-
else:
117-
curr_cpu = copy.copy(curr_entry)
118-
curr_cpu["processors"] = []
119-
curr_cpu["processors"].append(processor)
120-
core_id = curr_entry.get("core id")
121-
assert isinstance(core_id, str)
122-
processor2corecpu[processor] = (physical_id, core_id)
123-
124-
return cpu_hash, processor2corecpu
125-
126-
12771
def analyse_list_of_processes(
12872
children: "Sequence[psutil.Process]",
12973
processor2corecpu: "Mapping[str, Tuple[str, str]]",

0 commit comments

Comments
 (0)