Skip to content

Commit 48980d0

Browse files
committed
refactor(report): Cleanup hwpc and power reports code
1 parent 20956d5 commit 48980d0

File tree

9 files changed

+344
-160
lines changed

9 files changed

+344
-160
lines changed

src/powerapi/report/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
from powerapi.report.report import Report, BadInputData
31-
from powerapi.report.power_report import PowerReport
32-
from powerapi.report.hwpc_report import HWPCReport
33-
from powerapi.report.control_report import ControlReport
34-
from powerapi.report.procfs_report import ProcfsReport
35-
from powerapi.report.formula_report import FormulaReport
30+
from .control_report import ControlReport
31+
from .formula_report import FormulaReport
32+
from .hwpc_report import HWPCReport
33+
from .power_report import PowerReport
34+
from .report import Report, BadInputData

src/powerapi/report/hwpc_report.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,3 @@ def _create_group(row, groups, group_name):
185185
for current_key, value in row.items():
186186
if current_key not in CSV_HEADER_HWPC:
187187
groups[group_name][row[SOCKET_KEY]][row[CPU_KEY]][current_key] = int(value)
188-
189-
@staticmethod
190-
def create_empty_report():
191-
"""
192-
Creates an empty report
193-
"""
194-
return HWPCReport(None, None, None, {})

src/powerapi/report/power_report.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,6 @@ def to_csv_lines(report: PowerReport, tags: list[str]) -> CsvLines:
139139
final_dict = {'PowerReport': [line]}
140140
return CSV_HEADER_POWER, final_dict
141141

142-
@staticmethod
143-
def to_virtiofs_db(report: PowerReport) -> tuple[str, str]:
144-
"""
145-
return a tuple containing the power value and the name of the file to store the value.
146-
"""
147-
if 'socket' not in report:
148-
raise BadInputData('no tag socket in power report', report)
149-
filename = 'power_consumption_package' + str(report['socket'])
150-
power = report.power
151-
return filename, power
152-
153142
def generate_tags(self, selected_tags: None | list[str] = None) -> dict[str, Any]:
154143
"""
155144
Generate the report tags from its metadata.
@@ -205,10 +194,3 @@ def from_mongodb(data: dict) -> Report:
205194
:return: a PowerReport from a dictionary pulled from mongodb
206195
"""
207196
return PowerReport.from_json(data)
208-
209-
@staticmethod
210-
def create_empty_report():
211-
"""
212-
Creates an empty report
213-
"""
214-
return PowerReport(None, None, None, 0)

src/powerapi/report/report.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ def _extract_timestamp(ts):
133133

134134
raise ValueError('Invalid timestamp format')
135135

136-
@staticmethod
137-
def create_empty_report():
138-
"""
139-
Creates an empty report
140-
"""
141-
return Report(None, None, None)
142-
143136
@staticmethod
144137
def sanitize_tags_name(tags: Iterable[str]) -> dict[str, str]:
145138
"""

tests/unit/report/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2025, Inria
2+
# Copyright (c) 2025, University of Lille
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
#
11+
# * Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# * Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

tests/unit/report/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
2930
from datetime import datetime
3031

3132
import pytest

0 commit comments

Comments
 (0)