Skip to content

Commit 6f7c981

Browse files
committed
Fixed issue #9
The fix just implements the `-q` flag on `tdp-finder.py`, `cpuinfo-tdp-finder.py` and `modelname-tdp-finder.py` to only print the found TDP value.
1 parent 3fbd053 commit 6f7c981

3 files changed

Lines changed: 166 additions & 53 deletions

File tree

README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,45 @@ For the third source, there is a scraping program within this repository, which
145145
python -m treecript.tdp_sources cpumark_table.csv
146146
```
147147

148+
### `tdp-finder.py`
149+
148150
Once these datasets are locally available, usage of `tdp-finder.py` would be something like next, using an already generated (or even ongoing) metrics directory:
149151

150152
```bash
151153
python tdp-finder.py sample-series/Wetlab2Variations_metrics/2025_05_20-02_19-14001/ cpu-spec-dataset_Josua/dataset/*.csv cpumark_table.csv
152154
```
153155

154156
```
155-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
156-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
157-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
158-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
157+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
158+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
159+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
160+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
159161
Model [11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz] => TDP [Configurable TDP-up] => 28.0 W => File cpu-spec-dataset_Josua/dataset/intel-cpus.csv
160162
```
161163

164+
In case you want to gather the TDP value without parsing the output, you can use the `-q` parameter:
165+
166+
```bash
167+
python tdp-finder.py -q sample-series/Wetlab2Variations_metrics/2025_05_20-02_19-14001/ cpu-spec-dataset_Josua/dataset/*.csv cpumark_table.csv
168+
```
169+
170+
```
171+
28.0
172+
```
173+
174+
### `cpuinfo-tdp-finder.py`
175+
162176
Usage of `cpuinfo-tdp-finder.py` (which does not require to have a gathered metrics directory) would be something like next:
163177

164178
```bash
165179
python cpuinfo-tdp-finder.py /proc/cpuinfo cpu-spec-dataset_Josua/dataset/*.csv cpumark_table.csv
166180
```
167181

168182
```
169-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
170-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
171-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
172-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
183+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
184+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
185+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
186+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
173187
Model [11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz] => TDP [Configurable TDP-up] => 28.0 W => File cpu-spec-dataset_Josua/dataset/intel-cpus.csv
174188
```
175189

@@ -180,22 +194,24 @@ python cpuinfo-tdp-finder.py sample_cpuinfo/cpuinfo-amd.txt cpu-spec-dataset_Jos
180194
```
181195

182196
```
183-
Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
184-
Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
197+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
198+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
185199
Model [AMD EPYC 7742 64-Core Processor] => TDP [TDP] => 225.0 W => File cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
186200
```
187201

202+
### `modelname-tdp-finder.py`
203+
188204
If we have the processor model string, usage of `modelname-tdp-finder.py` would be something like next:
189205

190206
```bash
191207
python modelname-tdp-finder.py "11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz" cpu-spec-dataset_Josua/dataset/*.csv cpumark_table.csv
192208
```
193209

194210
```
195-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
196-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
197-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
198-
Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
211+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
212+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
213+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
214+
WARNING:treecript.common:Unable to match a valid processor row for 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
199215
Model [11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz] => TDP [Configurable TDP-up] => 28.0 W => File cpu-spec-dataset_Josua/dataset/intel-cpus.csv
200216
```
201217

@@ -204,8 +220,8 @@ python modelname-tdp-finder.py "AMD EPYC 7742 64-Core Processor" cpu-spec-datase
204220
```
205221

206222
```
207-
Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
208-
Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
223+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
224+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 7742 64-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
209225
Model [AMD EPYC 7742 64-Core Processor] => TDP [TDP] => 225.0 W => File cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
210226
```
211227

@@ -214,11 +230,11 @@ python modelname-tdp-finder.py "AMD EPYC 9V74 80-Core Processor" cpu-spec-datase
214230
```
215231

216232
```
217-
Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
218-
Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
219-
Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
220-
Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
221-
Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/intel-cpus.csv
233+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/amd-cpus.csv
234+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/ampere-cpus.csv
235+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/benchmark-cpus.csv
236+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/cpuworld-cpus.csv
237+
WARNING:treecript.common:Unable to match a valid processor row for AMD EPYC 9V74 80-Core Processor in file cpu-spec-dataset_Josua/dataset/intel-cpus.csv
222238
Model [AMD EPYC 9V74 80-Core Processor] => TDP [TDP] => 400.0 W => File cpumark_table.csv
223239
```
224240

treecript/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _tdp_finder_from_model_name(
150150

151151
if len(filtered_cpus) == 0:
152152
errmsg = f"Unable to match a valid processor row for {model_name} in file {processors_file.as_posix()}"
153-
logger.error(errmsg)
153+
logger.warning(errmsg)
154154
raise LookupError(errmsg)
155155

156156
matches: "List[Tuple[str, Union[str, float, int]]]" = []
@@ -181,7 +181,7 @@ def _tdp_finder_from_model_name(
181181
else:
182182
submsg = "no match on model description"
183183
errmsg = f"Unable to find processor package consumption values for {model_name} in file {processors_file.as_posix()} ({submsg})"
184-
logger.error(errmsg)
184+
logger.warning(errmsg)
185185
raise ValueError(errmsg)
186186
elif len(matches) > 1:
187187
# Now, sort by consumption

treecript/tdp_finder.py

Lines changed: 127 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
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+
import argparse
2122
import json
2223
import logging
2324
import pathlib
24-
import sys
2525
from typing import TYPE_CHECKING
2626

2727
if TYPE_CHECKING:
@@ -71,48 +71,145 @@ def tdp_finder_from_raw(
7171

7272

7373
def main_tdp_finder() -> "None":
74-
if len(sys.argv) >= 3:
75-
for model_name, tdp_column, tdp_in_w, processors_file in tdp_finder_from_series(
76-
pathlib.Path(sys.argv[1]), list(map(pathlib.Path, sys.argv[2:]))
77-
):
74+
par_parser = argparse.ArgumentParser()
75+
76+
meg = par_parser.add_mutually_exclusive_group()
77+
meg.add_argument(
78+
"-q",
79+
dest="logging_level",
80+
const=logging.ERROR,
81+
help="Be quiet, print only the consumption",
82+
action="store_const",
83+
)
84+
meg.add_argument(
85+
"-d",
86+
dest="logging_level",
87+
const=logging.DEBUG,
88+
help="Switch logging to Be quiet, print only the consumption",
89+
action="store_const",
90+
)
91+
92+
par_parser.add_argument(
93+
"series_dir",
94+
help="Directory of the gathered metrics timeline, where the CPU details were recorded",
95+
)
96+
par_parser.add_argument(
97+
"cpu_database_files",
98+
nargs="+",
99+
help="The CSV files where the list of CPUs are available, along with their consumptions",
100+
)
101+
102+
args = par_parser.parse_args()
103+
104+
logging_level = (
105+
args.logging_level if args.logging_level is not None else logging.WARNING
106+
)
107+
108+
logging.basicConfig(level=logging_level)
109+
110+
for model_name, tdp_column, tdp_in_w, processors_file in tdp_finder_from_series(
111+
pathlib.Path(args.series_dir), list(map(pathlib.Path, args.cpu_database_files))
112+
):
113+
if logging_level < logging.ERROR:
78114
print(
79115
f"Model [{model_name}] => TDP [{tdp_column}] => {tdp_in_w} W => File {processors_file.as_posix()}"
80116
)
81-
else:
82-
print(
83-
f"Usage: {sys.argv[0]} {{series_dir}} {{intel_datasheets_dir}}",
84-
file=sys.stderr,
85-
)
86-
sys.exit(1)
117+
else:
118+
print(str(tdp_in_w))
87119

88120

89121
def main_cpuinfo_tdp_finder() -> "None":
90-
if len(sys.argv) >= 3:
91-
for model_name, tdp_column, tdp_in_w, processors_file in tdp_finder_from_raw(
92-
pathlib.Path(sys.argv[1]), list(map(pathlib.Path, sys.argv[2:]))
93-
):
122+
par_parser = argparse.ArgumentParser()
123+
124+
meg = par_parser.add_mutually_exclusive_group()
125+
meg.add_argument(
126+
"-q",
127+
dest="logging_level",
128+
const=logging.ERROR,
129+
help="Be quiet, print only the consumption",
130+
action="store_const",
131+
)
132+
meg.add_argument(
133+
"-d",
134+
dest="logging_level",
135+
const=logging.DEBUG,
136+
help="Switch logging to Be quiet, print only the consumption",
137+
action="store_const",
138+
)
139+
140+
par_parser.add_argument(
141+
"cpuinfo_file",
142+
help="CPU details provided by Linux kernel, usually available at /proc/cpuinfo",
143+
)
144+
par_parser.add_argument(
145+
"cpu_database_files",
146+
nargs="+",
147+
help="The CSV files where the list of CPUs are available, along with their consumptions",
148+
)
149+
150+
args = par_parser.parse_args()
151+
152+
logging_level = (
153+
args.logging_level if args.logging_level is not None else logging.WARNING
154+
)
155+
156+
logging.basicConfig(level=logging_level)
157+
158+
for model_name, tdp_column, tdp_in_w, processors_file in tdp_finder_from_raw(
159+
pathlib.Path(args.cpuinfo_file),
160+
list(map(pathlib.Path, args.cpu_database_files)),
161+
):
162+
if logging_level < logging.ERROR:
94163
print(
95164
f"Model [{model_name}] => TDP [{tdp_column}] => {tdp_in_w} W => File {processors_file.as_posix()}"
96165
)
97-
else:
98-
print(
99-
f"Usage: {sys.argv[0]} {{cpuinfo_file}} {{intel_datasheets_dir}}",
100-
file=sys.stderr,
101-
)
102-
sys.exit(1)
166+
else:
167+
print(str(tdp_in_w))
103168

104169

105170
def main_modelname_tdp_finder() -> "None":
106-
if len(sys.argv) >= 3:
107-
model_name, tdp_column, tdp_in_w, processors_file = tdp_finder_from_model_name(
108-
sys.argv[1], list(map(pathlib.Path, sys.argv[2:]))
109-
)
171+
par_parser = argparse.ArgumentParser()
172+
173+
meg = par_parser.add_mutually_exclusive_group()
174+
meg.add_argument(
175+
"-q",
176+
dest="logging_level",
177+
const=logging.ERROR,
178+
help="Be quiet, print only the consumption",
179+
action="store_const",
180+
)
181+
meg.add_argument(
182+
"-d",
183+
dest="logging_level",
184+
const=logging.DEBUG,
185+
help="Switch logging to Be quiet, print only the consumption",
186+
action="store_const",
187+
)
188+
189+
par_parser.add_argument(
190+
"model_string",
191+
help="Processor model string to be searched",
192+
)
193+
par_parser.add_argument(
194+
"cpu_database_files",
195+
nargs="+",
196+
help="The CSV files where the list of CPUs are available, along with their consumptions",
197+
)
198+
199+
args = par_parser.parse_args()
200+
201+
logging_level = (
202+
args.logging_level if args.logging_level is not None else logging.WARNING
203+
)
204+
205+
logging.basicConfig(level=logging_level)
206+
207+
model_name, tdp_column, tdp_in_w, processors_file = tdp_finder_from_model_name(
208+
args.model_string, list(map(pathlib.Path, args.cpu_database_files))
209+
)
210+
if logging_level < logging.ERROR:
110211
print(
111212
f"Model [{model_name}] => TDP [{tdp_column}] => {tdp_in_w} W => File {processors_file.as_posix()}"
112213
)
113214
else:
114-
print(
115-
f"Usage: {sys.argv[0]} {{model_string}} {{intel_datasheets_dir}}",
116-
file=sys.stderr,
117-
)
118-
sys.exit(1)
215+
print(str(tdp_in_w))

0 commit comments

Comments
 (0)