Skip to content

Commit 5b94105

Browse files
committed
Added some heuristics to tdp_finder.py (related to issue #2)
Due the sparse nature of CPU spec repositories https://github.com/felixsteinke/cpu-spec-dataset and https://github.com/JosuaCarl/cpu-spec-dataset , where, depending on the processor model, their consumptions can be described in very disparate columns, the code now implements some heuristics and pattern matching instead of hard-coding the names of the columns.
1 parent 64cc5eb commit 5b94105

2 files changed

Lines changed: 71 additions & 17 deletions

File tree

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,39 @@ For instance, the sample directory was obtained just running next command line:
102102

103103
## Digestion
104104

105-
The program `tdp-finder.py` helps to obtain the TDP of a processor, using the gathered metadata stored at `cpu_details.json` within the series directory.
105+
The program `tdp-finder.py` helps to obtain the TDP of an Intel processor, using the gathered metadata stored at `cpu_details.json` within the series directory.
106106

107107
Repository https://github.com/felixsteinke/cpu-spec-dataset contains at
108108
[dataset](https://github.com/felixsteinke/cpu-spec-dataset/tree/main/dataset) subdirectory several tables in CSV format with
109-
this and other details for many Intel, AMD and Ampere processors.
109+
this and other details for many Intel, AMD and Ampere processors. The key column here is `ProcessorNumber`.
110110

111-
For instance:
111+
Forked repository https://github.com/JosuaCarl/cpu-spec-dataset contains at
112+
[dataset](https://github.com/JosuaCarl/cpu-spec-dataset/tree/main/dataset) subdirectory tables in CSV similar to the ones from original repo, but with different column names. The key column here to match the processor is `Processor Number`.
113+
114+
Usage would be something like next:
112115

113116
```bash
114117
git clone https://github.com/felixsteinke/cpu-spec-dataset
115118
python tdp-finder.py sample-series/Wetlab2Variations_metrics/2025_05_20-02_19-14001/ cpu-spec-dataset/dataset/intel-cpus.csv
116119
```
117120

118121
```
119-
TDP => 28.0 W
122+
TDP (ConfigTDPMax) => 28.0 W
123+
```
124+
125+
or
126+
127+
```bash
128+
git clone https://github.com/JosuaCarl/cpu-spec-dataset cpu-spec-dataset_Josua
129+
python tdp-finder.py sample-series/Wetlab2Variations_metrics/2025_05_20-02_19-14001/ cpu-spec-dataset_Josua/dataset/intel-cpus.csv
130+
```
131+
132+
```
133+
TDP (Configurable TDP-up) => 28.0 W
120134
```
121135

122136
The program `metrics-aggregator.py` is an initial proof of concept to digest the gathered process tree time series. As it tries
123-
computing the Wh of each part being executed, it needs the TDP (Thermal Design Power) from the CPU.
137+
computing the Wh of each part being executed, it needs the TDP (Thermal Design Power) or similar from the CPU.
124138

125139
For instance, getting all the consumptions from main steps of a workflow execution (which was using docker for its steps)
126140
and it was collected, would be:

execution_process_metrics_collector/tdp_finder.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
import pathlib
2424
import re
2525
import sys
26+
from typing import TYPE_CHECKING
27+
28+
if TYPE_CHECKING:
29+
from typing import (
30+
Tuple,
31+
)
2632

2733
import pandas as pd
2834

@@ -33,7 +39,9 @@
3339
logger = logging.getLogger(__name__)
3440

3541

36-
def tdp_finder(series_dir: "pathlib.Path", processors_file: "pathlib.Path") -> "float":
42+
def tdp_finder(
43+
series_dir: "pathlib.Path", processors_file: "pathlib.Path"
44+
) -> "Tuple[str, float]":
3745
if not series_dir.is_dir():
3846
logger.error(f"Path {series_dir.as_posix()} is not a directory")
3947
raise Exception()
@@ -48,24 +56,56 @@ def tdp_finder(series_dir: "pathlib.Path", processors_file: "pathlib.Path") -> "
4856

4957
model_name = cpu_details[0]["model name"]
5058

51-
cpus = pd.read_csv(processors_file)
59+
# low_memory is needed to avoid a warning in some CSV files with mixed data
60+
cpus = pd.read_csv(processors_file, low_memory=False)
5261

53-
tdp_str = cpus[
54-
cpus["ProcessorNumber"].apply(lambda pn: str(pn) in model_name)
55-
].ConfigTDPMax.values[0]
56-
matched = re.search(r"^([0-9]+(?:\.[0-9]+])?) W", tdp_str)
57-
if matched is not None:
58-
tdp_matched = matched.group(1)
62+
for key_column in ("ProcessorNumber", "Processor Number"):
63+
if key_column in cpus.columns:
64+
break
5965
else:
60-
tdp_matched = tdp_str
66+
logger.error(
67+
f"Unable to find a valid processor identification column in file {processors_file.as_posix()}"
68+
)
69+
raise Exception()
6170

62-
return float(tdp_matched)
71+
filtered_cpus = cpus[cpus[key_column].apply(lambda pn: str(pn) in model_name)]
72+
73+
if len(filtered_cpus) == 0:
74+
logger.error(
75+
f"Unable to match a valid processor row for {model_name} in file {processors_file.as_posix()}"
76+
)
77+
raise Exception()
78+
79+
matches = []
80+
for column_name, column in filtered_cpus.items():
81+
if not column.hasnans:
82+
putative_tdp_str = column.values[0]
83+
if isinstance(putative_tdp_str, str):
84+
matched = re.search(
85+
r"^(?:[0-9]+(?:\.[0-9]+])?-)?([0-9]+(?:\.[0-9]+])?) W",
86+
putative_tdp_str,
87+
)
88+
if matched:
89+
matches.append((str(column_name), matched.group(1)))
90+
91+
if len(matches) == 0:
92+
logger.error(
93+
f"Unable to find processor package consumption values for {model_name} in file {processors_file.as_posix()}"
94+
)
95+
raise Exception()
96+
97+
# Now, sort by consumption
98+
matches.sort(key=lambda t: t[1], reverse=True)
99+
100+
return (matches[0][0], float(matches[0][1]))
63101

64102

65103
def main() -> "None":
66104
if len(sys.argv) >= 3:
67-
tdp_in_w = tdp_finder(pathlib.Path(sys.argv[1]), pathlib.Path(sys.argv[2]))
68-
print(f"TDP => {tdp_in_w} W")
105+
tdp_column, tdp_in_w = tdp_finder(
106+
pathlib.Path(sys.argv[1]), pathlib.Path(sys.argv[2])
107+
)
108+
print(f"TDP ({tdp_column}) => {tdp_in_w} W")
69109
else:
70110
print(
71111
f"Usage: {sys.argv[0]} {{series_dir}} {{intel_datasheets_dir}}",

0 commit comments

Comments
 (0)