├── tests ├── unit │ ├── dispatcher │ │ └── __init__.py │ ├── __init__.py │ ├── actor │ │ └── __init__.py │ ├── cli │ │ └── __init__.py │ ├── formula │ │ └── __init__.py │ ├── puller │ │ └── __init__.py │ ├── pusher │ │ ├── __init__.py │ │ └── conftest.py │ ├── database │ │ ├── __init__.py │ │ └── conftest.py │ ├── processor │ │ ├── __init__.py │ │ └── pre │ │ │ ├── __init__.py │ │ │ └── k8s │ │ │ ├── __init__.py │ │ │ └── conftest.py │ ├── report │ │ └── __init__.py │ ├── dispatch_rule │ │ └── __init__.py │ └── conftest.py ├── utils │ ├── report │ │ ├── __init__.py │ │ └── power.py │ ├── db │ │ ├── csv_files │ │ │ ├── bad_common_miss_sensor.csv │ │ │ ├── bad_common_miss_target.csv │ │ │ ├── bad_common_miss_timestamp.csv │ │ │ ├── rapl1_miss_second.csv │ │ │ ├── rapl1_miss_first.csv │ │ │ ├── rapl2.csv │ │ │ ├── core1_miss_second.csv │ │ │ ├── core1_miss_first.csv │ │ │ ├── pcu2.csv │ │ │ └── core2.csv │ │ ├── __init__.py │ │ ├── csv.py │ │ ├── mongo.py │ │ └── socket.py │ ├── cli │ │ ├── basic_configuration_without_mandatory_arguments.json │ │ ├── basic_configuration.json │ │ ├── root_manager_basic_configuration_with_unknown_argument.json │ │ ├── basic_configuration_without_arguments_with_default_values.json │ │ ├── basic_configuration_with_long_and_short_names.json │ │ ├── root_manager_basic_configuration.json │ │ ├── root_manager_basic_configuration_with_no_argument_with_default_value.json │ │ ├── root_manager_basic_configuration_with_long_and_short_names.json │ │ ├── root_manager_basic_configuration_with_wrong_argument_type_value.json │ │ ├── k8s_pre_processor_configuration.json │ │ ├── csv_input_output_stream_mode_enabled_configuration.json │ │ ├── output_input_configuration.json │ │ ├── basic_configuration_with_subgroups.json │ │ ├── mongo_input_output_stream_mode_enabled_configuration.json │ │ ├── basic_configuration_with_subgroups_wrong_argument_type_value.json │ │ ├── root_manager_configuration_with_subgroups_and_no_argument_default_value.json │ │ ├── several_k8s_pre_processors_without_some_arguments_configuration.json │ │ ├── root_manager_configuration_with_subgroups.json │ │ ├── root_manager_configuration_with_subgroups_and_long_and_short_names.json │ │ ├── root_manager_configuration_with_subgroups_and_unknown_arguments.json │ │ ├── k8s_pre_processor_complete_configuration.json │ │ ├── k8s_pre_processor_wrong_binding_configuration.json │ │ ├── k8s_pre_processor_with_non_existing_puller_configuration.json │ │ ├── root_manager_configuration_with_subgroups_and_wrong_argument_type_value.json │ │ ├── several_k8s_pre_processors_configuration.json │ │ ├── k8s_pre_processor_with_reused_puller_in_bindings_configuration.json │ │ ├── single_input_multiple_outputs_with_different_report_type_configuration.json │ │ ├── __init__.py │ │ └── several_inputs_outputs_stream_mode_enabled_configuration.json │ ├── __init__.py │ ├── actor │ │ ├── __init__.py │ │ ├── dummy_handlers.py │ │ └── dummy_actor.py │ ├── formula │ │ ├── __init__.py │ │ └── dummy │ │ │ ├── __init__.py │ │ │ └── dummy_handlers.py │ └── dispatcher │ │ └── __init__.py └── __init__.py ├── CODEOWNERS ├── docs └── joss-paper │ ├── .gitignore │ ├── powerapi-overview.png │ ├── client-consumption-sn.png │ ├── client-consumption-ts.png │ ├── server-consumption-sn.png │ ├── server-consumption-ts.png │ └── README.md ├── .dockerignore ├── .codecov.yml ├── .github ├── dependabot.yml ├── workflows │ ├── pull-request.yml │ ├── codeql.yml │ └── build.yml └── chglog │ ├── CHANGELOG.tpl.md │ └── config.yml ├── .ruff.toml ├── SECURITY.md ├── Dockerfile ├── LICENSE ├── src └── powerapi │ ├── utils │ └── __init__.py │ ├── processor │ ├── pre │ │ ├── __init__.py │ │ ├── k8s │ │ │ ├── __init__.py │ │ │ └── _utils.py │ │ └── openstack │ │ │ ├── __init__.py │ │ │ └── _utils.py │ ├── __init__.py │ ├── handlers.py │ └── processor_actor.py │ ├── __init__.py │ ├── cli │ └── __init__.py │ ├── puller │ └── __init__.py │ ├── pusher │ └── __init__.py │ ├── database │ ├── socket │ │ ├── __init__.py │ │ └── codecs.py │ ├── opentsdb │ │ ├── __init__.py │ │ └── codecs.py │ ├── csv │ │ └── __init__.py │ ├── influxdb2 │ │ └── __init__.py │ ├── json │ │ └── __init__.py │ ├── prometheus │ │ ├── __init__.py │ │ └── codecs.py │ ├── mongodb │ │ ├── __init__.py │ │ └── codecs.py │ ├── __init__.py │ ├── exceptions.py │ └── driver.py │ ├── filter │ ├── __init__.py │ └── filter.py │ ├── dispatcher │ ├── __init__.py │ ├── handlers.py │ └── route_table.py │ ├── backend_supervisor │ └── __init__.py │ ├── handler │ ├── __init__.py │ ├── start_handler.py │ └── poison_pill_message_handler.py │ ├── formula │ ├── __init__.py │ ├── handlers.py │ └── abstract_cpu_dram_formula.py │ ├── dispatch_rule │ ├── __init__.py │ ├── dispatch_rule.py │ └── power_dispatch_rule.py │ ├── report │ ├── __init__.py │ ├── formula_report.py │ ├── hwpc_report.py │ ├── power_report.py │ └── control_report.py │ └── actor │ ├── __init__.py │ └── message.py ├── CITATION.cff ├── pyproject.toml └── .gitignore /tests/unit/dispatcher/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/utils/report/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Default owner for everything in the repo. 2 | * @powerapi-ng/oss-maintainers 3 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/bad_common_miss_sensor.csv: -------------------------------------------------------------------------------- 1 | timestamp,target,cpu,TRUC1,TRUC2 2 | 100000,example,2,455,4555 3 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/bad_common_miss_target.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,cpu,TRUC1,TRUC2 2 | 100000,example,2,455,4555 3 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/bad_common_miss_timestamp.csv: -------------------------------------------------------------------------------- 1 | sensor,target,cpu,TRUC1,TRUC2 2 | 100000,example,2,455,4555 3 | -------------------------------------------------------------------------------- /docs/joss-paper/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore inara output files. 2 | # https://github.com/openjournals/inara 3 | jats/* 4 | paper.pdf 5 | -------------------------------------------------------------------------------- /docs/joss-paper/powerapi-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powerapi-ng/powerapi/HEAD/docs/joss-paper/powerapi-overview.png -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration_without_mandatory_arguments.json: -------------------------------------------------------------------------------- 1 | { "arg1": 15, 2 | "arg3": false, 3 | "arg5": "a value" 4 | } -------------------------------------------------------------------------------- /docs/joss-paper/client-consumption-sn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powerapi-ng/powerapi/HEAD/docs/joss-paper/client-consumption-sn.png -------------------------------------------------------------------------------- /docs/joss-paper/client-consumption-ts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powerapi-ng/powerapi/HEAD/docs/joss-paper/client-consumption-ts.png -------------------------------------------------------------------------------- /docs/joss-paper/server-consumption-sn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powerapi-ng/powerapi/HEAD/docs/joss-paper/server-consumption-sn.png -------------------------------------------------------------------------------- /docs/joss-paper/server-consumption-ts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powerapi-ng/powerapi/HEAD/docs/joss-paper/server-consumption-ts.png -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration.json: -------------------------------------------------------------------------------- 1 | { "arg1": 5, 2 | "argumento2": "this a mandatory argument", 3 | "argument3": false, 4 | "arg4": 10.5 5 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_basic_configuration_with_unknown_argument.json: -------------------------------------------------------------------------------- 1 | { "a1": 5, 2 | "2": "this is an arg", 3 | "argument3": true, 4 | "arg4": 899 5 | } -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration_without_arguments_with_default_values.json: -------------------------------------------------------------------------------- 1 | { "argumento2": "this a mandatory argument", 2 | "argument3": false, 3 | "arg4": 10.5 4 | } -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration_with_long_and_short_names.json: -------------------------------------------------------------------------------- 1 | { "arg1": 5, 2 | "argumento2": "this a mandatory argument", 3 | "arg3": false, 4 | "arg4": 10.5, 5 | "5": "arg5 value" 6 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_basic_configuration.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "arg5" : "this is a value" 6 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_basic_configuration_with_no_argument_with_default_value.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": true, 4 | "arg4": 10.5 5 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_basic_configuration_with_long_and_short_names.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "5" : "this is a value 3" 6 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_basic_configuration_with_wrong_argument_type_value.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "2": "this is a mandatory argument", 3 | "argument3": "wrong value", 4 | "arg4": 98.0, 5 | "5" : "this is a value" 6 | } -------------------------------------------------------------------------------- /tests/utils/cli/k8s_pre_processor_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "pre-processor": { 4 | "my_processor": { 5 | "type": "k8s", 6 | "api-mode": "manual", 7 | "puller": "my_puller" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # Ignore everything by default 2 | * 3 | 4 | # Include the necessary files to install with setuptools 5 | !src/ 6 | !LICENSE 7 | !README.md 8 | !pyproject.toml 9 | 10 | # Ignore Byte-compiled / optimized / DLL files 11 | **/__pycache__ 12 | **/*.py[cod] 13 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/rapl1_miss_second.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,RAPL_ENERGY_DRAM,RAPL_ENERGY_PKG,time_enabled,time_running 2 | 1539260664189,grvingt-12,system,0,58,116981760,722468864,4511621,4511621 3 | 1539260664189,grvingt-12,system,1,21,81592320,603979776,4508661,4508661 4 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/rapl1_miss_first.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,RAPL_ENERGY_DRAM,RAPL_ENERGY_PKG,time_enabled,time_running 2 | 1539260665189,grvingt-12,system,0,58,10479468544,83577274368,932483893,932483893 3 | 1539260665189,grvingt-12,system,1,21,3448832000,33809760256,932481124,932481124 4 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: down 4 | range: "50...100" 5 | status: 6 | project: 7 | default: 8 | target: auto 9 | threshold: 5% 10 | patch: 11 | default: 12 | informational: true 13 | 14 | comment: 15 | layout: "reach, diff, files" 16 | behavior: default 17 | require_changes: true 18 | -------------------------------------------------------------------------------- /docs/joss-paper/README.md: -------------------------------------------------------------------------------- 1 | # PowerAPI paper for the [Journal of Open Source Software](https://joss.theoj.org/) 2 | This folder contains the source of the [PowerAPI paper submitted to the JOSS journal](https://joss.theoj.org/papers/10.21105/joss.06670). 3 | You can [follow the steps on the official documentation](https://joss.readthedocs.io/en/latest/paper.html#checking-that-your-paper-compiles) to build the pdf of the paper. 4 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/rapl2.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,RAPL_ENERGY_DRAM,RAPL_ENERGY_PKG,time_enabled,time_running 2 | 1539260664189,grvingt-12,system,0,58,116981760,722468864,4511621,4511621 3 | 1539260664189,grvingt-12,system,1,21,81592320,603979776,4508661,4508661 4 | 1539260665189,grvingt-12,system,0,58,10479468544,83577274368,932483893,932483893 5 | 1539260665189,grvingt-12,system,1,21,3448832000,33809760256,932481124,932481124 6 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/core1_miss_second.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,CPU_CLK_THREAD_UNHALTED:REF_P,CPU_CLK_THREAD_UNHALTED:THREAD_P,INSTRUCTIONS_RETIRED,LLC_MISSES,time_enabled,time_running 2 | 1539260664189,grvingt-12,system,0,56,2402,92576,12323,111,6475677,6475677 3 | 1539260664189,grvingt-12,system,0,12,2107,81091,11747,79,6471931,6471931 4 | 1539260664189,grvingt-12,system,1,49,3390,125535,28369,242,5264527,5264527 5 | 1539260664189,grvingt-12,system,1,13,1691,55476,6431,135,5283057,5283057 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | labels: 9 | - "dependencies" 10 | 11 | - package-ecosystem: "pip" 12 | directory: "/" 13 | schedule: 14 | interval: "daily" 15 | labels: 16 | - "dependencies" 17 | 18 | - package-ecosystem: "docker" 19 | directory: "/" 20 | schedule: 21 | interval: "daily" 22 | labels: 23 | - "dependencies" 24 | -------------------------------------------------------------------------------- /tests/utils/db/csv_files/core1_miss_first.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,CPU_CLK_THREAD_UNHALTED:REF_P,CPU_CLK_THREAD_UNHALTED:THREAD_P,INSTRUCTIONS_RETIRED,LLC_MISSES,time_enabled,time_running 2 | 1539260665189,grvingt-12,system,0,56,22834,908566,351781,3498,933527522,933527522 3 | 1539260665189,grvingt-12,system,0,12,10567,420761,77244,906,933516131,933516131 4 | 1539260665189,grvingt-12,system,1,49,8334,326647,113475,907,933275619,933275619 5 | 1539260665189,grvingt-12,system,1,13,1541,54031,6134,137,933300569,933300569 6 | -------------------------------------------------------------------------------- /tests/utils/cli/csv_input_output_stream_mode_enabled_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "puller": { 6 | "model": "HWPCReport", 7 | "type": "csv", 8 | "files": "/tmp/rapl.csv,/tmp/msr.csv", 9 | "name": "my_puller" 10 | } 11 | }, 12 | "output": { 13 | "pusher_power": { 14 | "type": "csv", 15 | "model": "PowerReport", 16 | "directory": "/tmp/formula_results", 17 | "name": "my_pusher" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /tests/utils/db/csv_files/pcu2.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,UNC_P_CLOCKTICKS,UNC_P_POWER_STATE_OCCUPANCY:CORES_C0,UNC_P_POWER_STATE_OCCUPANCY:CORES_C3,UNC_P_POWER_STATE_OCCUPANCY:CORES_C6,time_enabled,time_running 2 | 1539260664189,grvingt-12,system,0,58,4971375,41106603,0,37786439,4535232,4535232 3 | 1539260664189,grvingt-12,system,1,21,4969735,20515164,0,58206587,4534414,4534414 4 | 1539260665189,grvingt-12,system,0,58,1018376086,218985707,0,16074125411,932511305,932511305 5 | 1539260665189,grvingt-12,system,1,21,1018360289,106194644,0,16187259445,932506985,932506985 6 | -------------------------------------------------------------------------------- /tests/utils/cli/output_input_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /.ruff.toml: -------------------------------------------------------------------------------- 1 | target-version = "py310" # should match minimal python version of PowerAPI 2 | 3 | [lint] 4 | select = [ 5 | "F", # pyflakes 6 | "E", # pycodestyle errors 7 | "W", # pycodestyle warnings 8 | "B", # flake8-bugbear 9 | "G", # flake8-logging-format 10 | "PT", # flake8-pytest-style 11 | "UP", # pyupgrade 12 | "ERA", # eradicate 13 | "RUF", # ruff 14 | ] 15 | 16 | ignore = [ 17 | "E501", # line too long 18 | 19 | "B006", # mutable-argument-default 20 | "F401", # unused-import 21 | "B010", # set-attr-with-constant 22 | ] 23 | -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration_with_subgroups.json: -------------------------------------------------------------------------------- 1 | { "arg1": 5, 2 | "argumento2": "this a mandatory argument", 3 | "arg3": false, 4 | "arg4": 10.5, 5 | "5": "arg5 value", 6 | "g1": { 7 | "g1_sg1": { 8 | "type": "type1", 9 | "a1": 5, 10 | "a2": true, 11 | "a3": 569 12 | }, 13 | "g1_sg2": { 14 | "type": "type1", 15 | "a1": 10, 16 | "a2": false, 17 | "a3": "a value again" 18 | } 19 | }, 20 | "g2": { 21 | "g2_sg1": { 22 | "type": "type2", 23 | "a1": 5, 24 | "a3": "a value", 25 | "a4": "a value" 26 | } 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | - reopened 10 | 11 | permissions: 12 | contents: read 13 | 14 | jobs: 15 | check-pr: 16 | name: Check Pull Request 17 | runs-on: ubuntu-latest 18 | permissions: 19 | pull-requests: read 20 | statuses: write 21 | 22 | steps: 23 | - name: Validate title 24 | uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | -------------------------------------------------------------------------------- /tests/utils/cli/mongo_input_output_stream_mode_enabled_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/utils/cli/basic_configuration_with_subgroups_wrong_argument_type_value.json: -------------------------------------------------------------------------------- 1 | { "arg1": 5, 2 | "argumento2": "this a mandatory argument", 3 | "arg3": false, 4 | "arg4": 10.5, 5 | "5": "arg5 value", 6 | "g1": { 7 | "g1_sg1": { 8 | "type": "type1", 9 | "a1": 5, 10 | "a2": true, 11 | "a3": 569 12 | }, 13 | "g1_sg2": { 14 | "type": "type1", 15 | "a1": 10, 16 | "a2": false, 17 | "a3": "a value again" 18 | } 19 | }, 20 | "g2": { 21 | "g2_sg1": { 22 | "type": "type2", 23 | "a1": "wrong type", 24 | "a3": "a value", 25 | "4": "a value" 26 | } 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_configuration_with_subgroups_and_no_argument_default_value.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "arg5" : "this is a value", 6 | "input": { 7 | "in1": { 8 | "model": "i1_model", 9 | "type": "i1_type", 10 | "db": "i1_db" 11 | } 12 | }, 13 | "output": { 14 | "o1": { 15 | "model": "o1_model", 16 | "type": "o1_type", 17 | "db": "o1_db", 18 | "collection": "o1_col" 19 | }, 20 | "o2": { 21 | "model": "o2_model", 22 | "type": "o2_type", 23 | "db": "o2_db", 24 | "collection": "o2_col" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /tests/utils/cli/several_k8s_pre_processors_without_some_arguments_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "pre-processor": { 4 | "my_processor_1": { 5 | "type": "k8s", 6 | "puller": "my_puller_1" 7 | }, 8 | "my_processor_2": { 9 | "type": "k8s", 10 | "puller": "my_puller_2" 11 | }, 12 | "my_processor_3": { 13 | "type": "k8s", 14 | "puller": "my_puller_3" 15 | }, 16 | "my_processor_4": { 17 | "type": "k8s", 18 | "puller": "my_puller_4" 19 | }, 20 | "my_processor_5": { 21 | "type": "k8s", 22 | "puller": "my_puller_5" 23 | }, 24 | "my_processor_6": { 25 | "type": "k8s", 26 | "puller": "my_puller_6" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_configuration_with_subgroups.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "arg5" : "this is a value", 6 | "input": { 7 | "in1": { 8 | "model": "i1_model", 9 | "type": "i1_type", 10 | "db": "i1_db", 11 | "name": "in1_name" 12 | } 13 | }, 14 | "output": { 15 | "o1": { 16 | "model": "o1_model", 17 | "type": "o1_type", 18 | "db": "o1_db", 19 | "collection": "o1_col", 20 | "name": "o1_name" 21 | }, 22 | "o2": { 23 | "model": "o2_model", 24 | "type": "o2_type", 25 | "db": "o2_db", 26 | "collection": "o2_col", 27 | "name": "o2_name" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_configuration_with_subgroups_and_long_and_short_names.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "5" : "this is a value", 6 | "input": { 7 | "in1": { 8 | "model": "i1_model", 9 | "type": "i1_type", 10 | "db": "i1_db", 11 | "name": "i1_name" 12 | } 13 | }, 14 | "output": { 15 | "o1": { 16 | "model": "o1_model_x", 17 | "type": "o1_type", 18 | "db": "o1_db", 19 | "collection": "o1_col", 20 | "name": "o1_name" 21 | }, 22 | "o2": { 23 | "model": "o2_model", 24 | "type": "o2_type", 25 | "db": "o2_db", 26 | "collection": "o2_col", 27 | "name": "o2_name" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_configuration_with_subgroups_and_unknown_arguments.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "arg5" : "this is a value", 6 | "input": { 7 | "in1": { 8 | "model2": "i1_model", 9 | "type55": "i1_type", 10 | "db": "i1_db", 11 | "name": "i1_name" 12 | } 13 | }, 14 | "output": { 15 | "o1": { 16 | "model": "o1_model", 17 | "type55": "o1_type", 18 | "db": "o1_db", 19 | "collection": "o1_col", 20 | "name": "o1_name" 21 | }, 22 | "o2": { 23 | "model": "o2_model", 24 | "type": "o2_type", 25 | "db": "o2_db", 26 | "collection": "o2_col", 27 | "name": "o2_name" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /tests/utils/cli/k8s_pre_processor_complete_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | }, 22 | "pre-processor": { 23 | "my_processor": { 24 | "type": "k8s", 25 | "api_mode": "manual", 26 | "puller": "one_puller" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/cli/k8s_pre_processor_wrong_binding_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | }, 22 | "pre-processor": { 23 | "my_processor": { 24 | "type": "k8s", 25 | "api-mode": "manual", 26 | "puller": "one_pusher" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/cli/k8s_pre_processor_with_non_existing_puller_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | }, 22 | "pre-processor": { 23 | "my_processor": { 24 | "type": "k8s", 25 | "api-mode": "manual", 26 | "puller": "non_existent_puller" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/cli/root_manager_configuration_with_subgroups_and_wrong_argument_type_value.json: -------------------------------------------------------------------------------- 1 | { "argument1": 5, 2 | "argumento2": "this is a mandatory argument", 3 | "argument3": false, 4 | "arg4": 98.0, 5 | "arg5" : "this is a value", 6 | "input": { 7 | "in1": { 8 | "model": "i1_model", 9 | "type": "i1_type", 10 | "db": "i1_db", 11 | "name": "i1_name", 12 | "port": "port" 13 | } 14 | }, 15 | "output": { 16 | "o1": { 17 | "model": "o1_model", 18 | "type": "o1_type", 19 | "db": "o1_db", 20 | "collection": "o1_col", 21 | "name": "o1_name" 22 | }, 23 | "o2": { 24 | "model": "o2_model", 25 | "type": "o2_type", 26 | "db": "o2_db", 27 | "collection": "o2_col", 28 | "name": "o2_name" 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /tests/utils/db/csv_files/core2.csv: -------------------------------------------------------------------------------- 1 | timestamp,sensor,target,socket,cpu,CPU_CLK_THREAD_UNHALTED:REF_P,CPU_CLK_THREAD_UNHALTED:THREAD_P,INSTRUCTIONS_RETIRED,LLC_MISSES,time_enabled,time_running 2 | 1539260664189,grvingt-12,system,0,56,2402,92576,12323,111,6475677,6475677 3 | 1539260664189,grvingt-12,system,0,12,2107,81091,11747,79,6471931,6471931 4 | 1539260664189,grvingt-12,system,1,49,3390,125535,28369,242,5264527,5264527 5 | 1539260664189,grvingt-12,system,1,13,1691,55476,6431,135,5283057,5283057 6 | 1539260665189,grvingt-12,system,0,56,22834,908566,351781,3498,933527522,933527522 7 | 1539260665189,grvingt-12,system,0,12,10567,420761,77244,906,933516131,933516131 8 | 1539260665189,grvingt-12,system,1,49,8334,326647,113475,907,933275619,933275619 9 | 1539260665189,grvingt-12,system,1,13,1541,54031,6134,137,933300569,933300569 10 | -------------------------------------------------------------------------------- /.github/chglog/CHANGELOG.tpl.md: -------------------------------------------------------------------------------- 1 | {{ range .Versions }} 2 | 3 | ## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }}) 4 | 5 | {{ range .CommitGroups -}} 6 | ### {{ .Title }} 7 | 8 | {{ range .Commits -}} 9 | * {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ upperFirst .Subject }} 10 | {{ end }} 11 | {{ end -}} 12 | 13 | {{- if .RevertCommits -}} 14 | ### Reverts 15 | 16 | {{ range .RevertCommits -}} 17 | * {{ .Revert.Header }} 18 | {{ end }} 19 | {{ end -}} 20 | 21 | {{- if .NoteGroups -}} 22 | {{ range .NoteGroups -}} 23 | ### {{ .Title }} 24 | 25 | {{ range .Notes }} 26 | {{ upperFirst .Body }} 27 | {{ end }} 28 | {{ end -}} 29 | {{ end -}} 30 | {{ end -}} 31 | -------------------------------------------------------------------------------- /tests/utils/cli/several_k8s_pre_processors_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "pre-processor": { 4 | "my_processor_1": { 5 | "type": "k8s", 6 | "api-mode": "manual", 7 | "puller": "my_puller_1" 8 | }, 9 | "my_processor_2": { 10 | "type": "k8s", 11 | "api-mode": "manual", 12 | "puller": "my_puller_2" 13 | }, 14 | "my_processor_3": { 15 | "type": "k8s", 16 | "api-mode": "manual", 17 | "puller": "my_puller_3" 18 | }, 19 | "my_processor_4": { 20 | "type": "k8s", 21 | "api-mode": "manual", 22 | "puller": "my_puller_4" 23 | }, 24 | "my_processor_5": { 25 | "type": "k8s", 26 | "api-mode": "manual", 27 | "puller": "my_puller_5" 28 | }, 29 | "my_processor_6": { 30 | "type": "k8s", 31 | "api-mode": "manual", 32 | "puller": "my_puller_6" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/utils/cli/k8s_pre_processor_with_reused_puller_in_bindings_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "one_puller": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection" 11 | } 12 | }, 13 | "output": { 14 | "one_pusher": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "second_uri", 18 | "db": "my_db_result", 19 | "collection": "my_collection_result" 20 | } 21 | }, 22 | "pre-processor": { 23 | "my_processor": { 24 | "type": "k8s", 25 | "api-mode": "manual", 26 | "puller": "one_puller" 27 | }, 28 | "my_processor_2": { 29 | "type": "k8s", 30 | "api-mode": "manual", 31 | "puller": "one_puller" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/utils/cli/single_input_multiple_outputs_with_different_report_type_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "hwpcsensor": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "mongodb://example", 9 | "db": "inputdb", 10 | "collection": "hwpcsensor" 11 | } 12 | }, 13 | "output": { 14 | "powerrep1": { 15 | "type": "mongodb", 16 | "model": "PowerReport", 17 | "uri": "mongodb://example", 18 | "db": "outputdb", 19 | "collection": "powerrep" 20 | }, 21 | "powerrep2": { 22 | "type": "csv", 23 | "model": "PowerReport", 24 | "directory": "/tmp/powerapi-csv-export-test" 25 | }, 26 | "formularep": { 27 | "type": "mongodb", 28 | "model": "FormulaReport", 29 | "uri": "mongodb://example", 30 | "db": "outputdb", 31 | "collection": "formularep" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/chglog/config.yml: -------------------------------------------------------------------------------- 1 | style: github 2 | template: CHANGELOG.tpl.md 3 | info: 4 | title: CHANGELOG 5 | repository_url: https://github.com/powerapi-ng/powerapi 6 | options: 7 | commits: 8 | filters: 9 | Type: 10 | - feat 11 | - fix 12 | - perf 13 | - refactor 14 | - style 15 | - docs 16 | - test 17 | - build 18 | - ci 19 | - chore 20 | commit_groups: 21 | title_maps: 22 | feat: Features 23 | fix: Bug Fixes 24 | perf: Performance Improvements 25 | refactor: Code Refactoring 26 | docs: Documentation 27 | test: Tests 28 | build: Build System 29 | ci: Continuous Integration 30 | chore: Miscellaneous Chores 31 | header: 32 | pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\/\\s]*)\\))?\\:\\s(.*)$" 33 | pattern_maps: 34 | - Type 35 | - Scope 36 | - Subject 37 | notes: 38 | keywords: 39 | - BREAKING CHANGE 40 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting Security Issues 4 | 5 | The PowerAPI team and community take security bugs seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. 6 | 7 | To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/powerapi-ng/powerapi/security/advisories/new) tab. 8 | **Please do not report security vulnerabilities through public GitHub issues.** 9 | 10 | The PowerAPI team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. 11 | 12 | Report security bugs in third-party modules to the person or team maintaining the module. 13 | If your report is about a security issue in a formula, please follow the Security Policy in its own repository. 14 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: ["master"] 6 | pull_request: 7 | branches: ["master"] 8 | schedule: 9 | - cron: "36 9 * * 0" 10 | 11 | permissions: 12 | contents: read 13 | 14 | jobs: 15 | analyze: 16 | name: Analyze 17 | runs-on: ubuntu-latest 18 | permissions: 19 | actions: read 20 | contents: read 21 | security-events: write 22 | 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | language: ["python"] 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 31 | 32 | - name: Initialize CodeQL 33 | uses: github/codeql-action/init@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v3.29.5 34 | with: 35 | languages: ${{ matrix.language }} 36 | queries: +security-and-quality 37 | 38 | - name: Autobuild 39 | uses: github/codeql-action/autobuild@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v3.29.5 40 | 41 | - name: Perform CodeQL Analysis 42 | uses: github/codeql-action/analyze@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v3.29.5 43 | with: 44 | category: "/language:${{matrix.language}}" 45 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # ---- Image configuration flags: 2 | ARG POWERAPI_INSTALL_METHOD="pypi" 3 | ARG POWERAPI_COMPONENTS="everything" 4 | ARG POWERAPI_VERSION="" 5 | 6 | # ---- Base stage (common setup): 7 | FROM python:3-slim@sha256:fd2aff39e5a3ed23098108786a9966fb036fdeeedd487d5360e466bb2a84377b AS base 8 | 9 | RUN useradd -m -s /bin/bash powerapi 10 | WORKDIR /home/powerapi 11 | 12 | RUN python -m venv --clear /opt/powerapi-venv 13 | ENV VIRTUAL_ENV=/opt/powerapi-venv PATH="/opt/powerapi-venv/bin:${PATH}" 14 | 15 | # ---- Install PowerAPI package from PyPI.org: 16 | FROM base AS pypi 17 | 18 | ARG POWERAPI_COMPONENTS 19 | ARG POWERAPI_VERSION 20 | 21 | RUN python -m pip install --no-cache-dir "powerapi[${POWERAPI_COMPONENTS}]${POWERAPI_VERSION:+==$POWERAPI_VERSION}" 22 | 23 | # ---- Install PowerAPI package from local sources (editable install): 24 | FROM base AS local 25 | 26 | ARG POWERAPI_COMPONENTS 27 | 28 | COPY --chown=powerapi . /tmp/powerapi 29 | RUN python -m pip install --no-cache-dir "/tmp/powerapi[${POWERAPI_COMPONENTS}]" && rm -r /tmp/powerapi 30 | 31 | # ---- Final stage: 32 | FROM ${POWERAPI_INSTALL_METHOD} AS final 33 | 34 | ENTRYPOINT ["sh", "-c", "echo 'This container image is intended to be used as a base and should not be run directly.' >&2; exit 1"] 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, INRIA 4 | Copyright (c) 2018, University of Lille 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of the copyright holder nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | -------------------------------------------------------------------------------- /tests/utils/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/actor/__init__.py: -------------------------------------------------------------------------------- 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. 29 | -------------------------------------------------------------------------------- /tests/unit/cli/__init__.py: -------------------------------------------------------------------------------- 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. 29 | -------------------------------------------------------------------------------- /tests/unit/formula/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/puller/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/pusher/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | -------------------------------------------------------------------------------- /src/powerapi/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Inria 2 | # Copyright (c) 2021, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/database/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, Inria 2 | # Copyright (c) 2024, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/database/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, Inria 2 | # Copyright (c) 2024, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/processor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, Inria 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/report/__init__.py: -------------------------------------------------------------------------------- 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. 29 | -------------------------------------------------------------------------------- /tests/utils/actor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/utils/formula/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /src/powerapi/processor/pre/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/dispatch_rule/__init__.py: -------------------------------------------------------------------------------- 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. 29 | -------------------------------------------------------------------------------- /tests/unit/processor/pre/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, Inria 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /tests/unit/processor/pre/k8s/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | -------------------------------------------------------------------------------- /src/powerapi/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | __version__ = "2.10.0" 31 | -------------------------------------------------------------------------------- /src/powerapi/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from .config_validator import ConfigValidator 31 | -------------------------------------------------------------------------------- /tests/utils/dispatcher/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | 30 | from .dispatcher import FakeDispatcher 31 | -------------------------------------------------------------------------------- /src/powerapi/processor/pre/k8s/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | 30 | from .actor import K8sPreProcessorActor 31 | -------------------------------------------------------------------------------- /src/powerapi/puller/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.puller.puller_actor import PullerActor 31 | -------------------------------------------------------------------------------- /src/powerapi/pusher/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.pusher.pusher_actor import PusherActor 31 | -------------------------------------------------------------------------------- /tests/utils/db/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Inria 2 | # Copyright (c) 2021, 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. 29 | 30 | from .db import SilentFakeDB, make_report, generate_reports 31 | -------------------------------------------------------------------------------- /src/powerapi/database/socket/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.socket.driver import Socket 31 | -------------------------------------------------------------------------------- /src/powerapi/database/opentsdb/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.opentsdb.driver import OpenTSDB 31 | -------------------------------------------------------------------------------- /src/powerapi/filter/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.filter.filter import Filter, FilterUselessError 31 | -------------------------------------------------------------------------------- /src/powerapi/database/csv/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.csv.driver import CSVInput, CSVOutput 31 | -------------------------------------------------------------------------------- /src/powerapi/database/influxdb2/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.influxdb2.driver import InfluxDB2 31 | -------------------------------------------------------------------------------- /src/powerapi/database/json/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.json.driver import JsonInput, JsonOutput 31 | -------------------------------------------------------------------------------- /src/powerapi/database/prometheus/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.prometheus.driver import Prometheus 31 | -------------------------------------------------------------------------------- /tests/utils/formula/dummy/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | from tests.utils.formula.dummy.dummy_formula_actor import DummyFormulaActor 30 | -------------------------------------------------------------------------------- /src/powerapi/dispatcher/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.dispatcher.dispatcher_actor import DispatcherActor, RouteTable 31 | -------------------------------------------------------------------------------- /src/powerapi/processor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | 30 | from powerapi.processor.processor_actor import ProcessorActor, ProcessorState 31 | -------------------------------------------------------------------------------- /src/powerapi/database/mongodb/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.mongodb.driver import MongodbInput, MongodbOutput 31 | -------------------------------------------------------------------------------- /src/powerapi/backend_supervisor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.backend_supervisor.backend_supervisor import BackendSupervisor 31 | -------------------------------------------------------------------------------- /src/powerapi/processor/pre/openstack/__init__.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.processor.pre.openstack.actor import OpenStackPreProcessorActor 31 | -------------------------------------------------------------------------------- /src/powerapi/handler/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.handler.handler import Handler, InitHandler, HandlerException 31 | from powerapi.handler.poison_pill_message_handler import PoisonPillMessageHandler 32 | from powerapi.handler.start_handler import StartHandler 33 | -------------------------------------------------------------------------------- /src/powerapi/formula/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.formula.handlers import FormulaPoisonPillMessageHandler 31 | from powerapi.formula.abstract_cpu_dram_formula import AbstractCpuDramFormula 32 | from powerapi.formula.formula_actor import FormulaActor, FormulaState 33 | -------------------------------------------------------------------------------- /src/powerapi/dispatch_rule/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from powerapi.dispatch_rule.dispatch_rule import DispatchRule 31 | from powerapi.dispatch_rule.hwpc_dispatch_rule import HWPCDispatchRule, HWPCDepthLevel 32 | from powerapi.dispatch_rule.power_dispatch_rule import PowerDispatchRule, PowerDepthLevel 33 | -------------------------------------------------------------------------------- /src/powerapi/report/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from powerapi.report.report import Report 31 | from powerapi.report.hwpc_report import HWPCReport 32 | from powerapi.report.power_report import PowerReport 33 | from powerapi.report.formula_report import FormulaReport 34 | from powerapi.report.control_report import ControlReport 35 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: ["master"] 6 | pull_request: 7 | branches: ["master"] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | run-tests: 14 | name: Run linters and unit tests 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: ["3.10", "3.x"] 19 | 20 | steps: 21 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 22 | 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | 28 | - name: Install uv 29 | uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7.1.5 30 | 31 | - name: Install dependencies 32 | run: | 33 | uv sync --extra everything --dev 34 | 35 | - name: Run ruff 36 | run: | 37 | uv run ruff check --output-format=github src/ tests/ 38 | 39 | - name: Run unit tests with coverage 40 | run: | 41 | uv run pytest --cov=powerapi --cov-report=term --cov-report=xml tests/unit 42 | 43 | - name: Upload coverage reports to Codecov 44 | uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 45 | with: 46 | token: ${{ secrets.CODECOV_TOKEN }} 47 | 48 | build-container-image: 49 | name: Build container image 50 | runs-on: ubuntu-latest 51 | 52 | steps: 53 | - name: Setup Docker buildx 54 | uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 55 | 56 | - name: Build image 57 | uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 58 | with: 59 | push: false 60 | provenance: false 61 | load: true 62 | tags: localbuild/powerapi:sha-${{ github.sha }} 63 | build-args: | 64 | POWERAPI_INSTALL_METHOD=local 65 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite our article in the Journal of Open Source Software." 3 | title: "PowerAPI: A Python framework for building software-defined power meters" 4 | license: "BSD-3-Clause" 5 | type: software 6 | url: "https://powerapi.org" 7 | repository-code: "https://github.com/powerapi-ng/powerapi" 8 | doi: 10.5281/zenodo.11453194 9 | keywords: 10 | - powerapi 11 | - energy 12 | - green-computing 13 | - python-framework 14 | authors: 15 | - given-names: "Guillaume" 16 | family-names: "Fieni" 17 | affiliation: "Inria" 18 | orcid: "https://orcid.org/0000-0002-0165-6824" 19 | - given-names: "Daniel" 20 | family-names: "Romero Acero" 21 | affiliation: "Inria" 22 | orcid: "https://orcid.org/0000-0002-5317-2610" 23 | - given-names: "Pierre" 24 | family-names: "Rust" 25 | affiliation: "Orange Labs" 26 | orcid: "https://orcid.org/0000-0002-2761-4702" 27 | - given-names: "Romain" 28 | family-names: "Rouvoy" 29 | affiliation: "University of Lille" 30 | orcid: "https://orcid.org/0000-0003-1771-8791" 31 | preferred-citation: 32 | authors: 33 | - given-names: "Guillaume" 34 | family-names: "Fieni" 35 | orcid: "https://orcid.org/0000-0002-0165-6824" 36 | - given-names: "Daniel" 37 | family-names: "Romero Acero" 38 | orcid: "https://orcid.org/0000-0002-5317-2610" 39 | - given-names: "Pierre" 40 | family-names: "Rust" 41 | orcid: "https://orcid.org/0000-0002-2761-4702" 42 | - given-names: "Romain" 43 | family-names: "Rouvoy" 44 | orcid: "https://orcid.org/0000-0003-1771-8791" 45 | date-published: 2024-06-04 46 | doi: 10.21105/joss.06670 47 | issn: 2475-9066 48 | issue: 98 49 | journal: Journal of Open Source Software 50 | publisher: 51 | name: Open Journals 52 | start: 6670 53 | title: "PowerAPI: A Python framework for building software-defined power meters" 54 | type: article 55 | url: "https://joss.theoj.org/papers/10.21105/joss.06670" 56 | volume: 9 57 | 58 | -------------------------------------------------------------------------------- /tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "stream": true, 4 | "input": { 5 | "puller1": { 6 | "model": "HWPCReport", 7 | "type": "mongodb", 8 | "uri": "one_uri", 9 | "db": "my_db", 10 | "collection": "my_collection", 11 | "name": "puller1" 12 | }, 13 | "puller2": { 14 | "model": "HWPCReport", 15 | "type": "csv", 16 | "files": "/tmp/rapl.csv,/tmp/msr.csv", 17 | "name": "puller2" 18 | }, 19 | "puller3": { 20 | "model": "HWPCReport", 21 | "type": "socket", 22 | "host": "localhost", 23 | "port": 1111, 24 | "name": "puller3" 25 | } 26 | }, 27 | "output": { 28 | "one_pusher": { 29 | "type": "mongodb", 30 | "model": "PowerReport", 31 | "uri": "second_uri", 32 | "db": "my_db_result", 33 | "collection": "my_collection_result" 34 | }, 35 | "third_pusher": { 36 | "type": "prometheus", 37 | "model": "PowerReport", 38 | "addr": "127.0.0.1", 39 | "port": 2222, 40 | "metric-name": "my_metric", 41 | "metric-description": "a description", 42 | "aggregation-period": 11 43 | }, 44 | "fourth_pusher": { 45 | "type": "csv", 46 | "model": "PowerReport", 47 | "directory": "my_dir" 48 | }, 49 | "fifth_pusher": { 50 | "type": "influxdb2", 51 | "model": "PowerReport", 52 | "uri": "127.0.0.1", 53 | "port": 1111, 54 | "bucket": "my_db_result_5", 55 | "token": "my_token", 56 | "org": "my_org", 57 | "tags": "t1,t2,t3" 58 | }, 59 | "sixth": { 60 | "type": "opentsdb", 61 | "model": "PowerReport", 62 | "uri": "127.0.0.1", 63 | "port": 1111, 64 | "metric-name": "my metric opentsdb" 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/powerapi/actor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.actor.socket_interface import SocketInterface, NotConnectedException 31 | from powerapi.actor.supervisor import Supervisor, ActorInitError, ActorAlreadySupervisedException 32 | from powerapi.actor.supervisor import CrashConfigureError, FailConfigureError 33 | from powerapi.actor.state import State 34 | from powerapi.actor.actor import Actor, InitializationException 35 | -------------------------------------------------------------------------------- /src/powerapi/formula/handlers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.handler import PoisonPillMessageHandler 31 | 32 | 33 | class FormulaPoisonPillMessageHandler(PoisonPillMessageHandler): 34 | """ 35 | Default Handler for dealing with PoisonPillMessage 36 | """ 37 | def teardown(self, soft=False): 38 | for pushers in self.state.pushers.values(): 39 | for pusher in pushers: 40 | pusher.socket_interface.close() 41 | -------------------------------------------------------------------------------- /src/powerapi/processor/handlers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | from powerapi.handler import InitHandler 30 | from powerapi.report import Report 31 | 32 | 33 | class ProcessorReportHandler(InitHandler): 34 | """ 35 | Processor the report by modifying it in some way and then send the modified report to targets actos 36 | """ 37 | 38 | def _send_report(self, report: Report): 39 | """ 40 | Send the report to the actor target 41 | """ 42 | for target in self.state.target_actors: 43 | target.send_data(report) 44 | -------------------------------------------------------------------------------- /src/powerapi/dispatch_rule/dispatch_rule.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | 31 | class DispatchRule: 32 | """ 33 | Group by rule 34 | """ 35 | def __init__(self, primary: bool = False, fields: list[str] | None = None): 36 | self.is_primary = primary 37 | self.fields = fields 38 | 39 | def get_formula_id(self, report): 40 | """ 41 | return id of the formula that the received report must be sent 42 | 43 | :param report: 44 | :type report: powerapi.report.report.Report 45 | :rtype: ([tuple]) a list formula identifier 46 | """ 47 | raise NotImplementedError() 48 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "powerapi" 7 | description = "PowerAPI is a middleware toolkit for building software-defined power meters." 8 | readme = "README.md" 9 | keywords = ["powerapi", "energy", "power-meter", "green-computing"] 10 | license = {text = "BSD-3-Clause"} 11 | requires-python = ">=3.10" 12 | version = "2.10.0" 13 | 14 | classifiers = [ 15 | "Programming Language :: Python :: 3.10", 16 | "Programming Language :: Python :: 3.11", 17 | "Programming Language :: Python :: 3.12", 18 | "Programming Language :: Python :: 3.13", 19 | "Programming Language :: Python :: 3.14", 20 | "License :: OSI Approved :: BSD License", 21 | "Intended Audience :: Science/Research", 22 | "Intended Audience :: Developers", 23 | "Development Status :: 5 - Production/Stable", 24 | "Topic :: Software Development :: Libraries :: Python Modules" 25 | ] 26 | 27 | authors = [ 28 | {name = "PowerAPI Staff", email = "powerapi-staff@inria.fr"}, 29 | ] 30 | 31 | dependencies = [ 32 | "pyzmq >= 18.1.0", 33 | "setproctitle >= 1.1.8" 34 | ] 35 | 36 | [project.optional-dependencies] 37 | # Databases: 38 | mongodb = ["pymongo >= 3.7.2"] 39 | influxdb = ["influxdb-client >= 1.30.0"] 40 | opentsdb = ["opentsdb-py >= 0.6.0"] 41 | prometheus = ["prometheus-client >= 0.9.0"] 42 | 43 | # Plaforms: 44 | kubernetes = ["kubernetes >= 27.0.2"] 45 | openstack = ["openstacksdk >= 4.7.0"] 46 | 47 | # Aliases: 48 | all-databases = ["powerapi[mongodb, influxdb, opentsdb, prometheus]"] 49 | all-platforms = ["powerapi[kubernetes, openstack]"] 50 | everything = ["powerapi[all-databases, all-platforms]"] 51 | 52 | [dependency-groups] 53 | test = [ 54 | "pytest >= 7.0.1", 55 | "pytest-timeout >= 1.4.2", 56 | "pytest-cov >= 4.0.0" 57 | ] 58 | 59 | docs = [ 60 | "sphinx >= 1.8.1", 61 | "sphinx-autodoc-typehints >= 1.6.0" 62 | ] 63 | 64 | lint = [ 65 | "ruff == 0.14.8" 66 | ] 67 | 68 | dev = [ 69 | {include-group = 'test'}, 70 | {include-group = 'docs'}, 71 | {include-group = 'lint'} 72 | ] 73 | 74 | [project.urls] 75 | homepage = "https://powerapi.org" 76 | documentation = "https://powerapi.readthedocs.org" 77 | repository = "https://github.com/powerapi-ng/powerapi" 78 | -------------------------------------------------------------------------------- /tests/utils/db/csv.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | import os 30 | import pytest 31 | 32 | import tests.utils.db as parent_module 33 | 34 | OUTPUT_PATH = '/tmp/powerapi_test_csv/' 35 | ROOT_PATH = parent_module.__path__[0] + '/csv_files/' 36 | FILES = [ROOT_PATH + 'core2.csv', 37 | ROOT_PATH + "rapl2.csv", 38 | ROOT_PATH + "pcu2.csv"] 39 | 40 | 41 | @pytest.fixture 42 | def files(): 43 | """ 44 | fixture that remove csv files used by test module before launching the test and after the test end 45 | """ 46 | os.system('rm -Rf ' + OUTPUT_PATH) 47 | os.system('mkdir -p ' + OUTPUT_PATH) 48 | yield None 49 | os.system('rm -Rf ' + OUTPUT_PATH) 50 | -------------------------------------------------------------------------------- /src/powerapi/report/formula_report.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, Inria 2 | # Copyright (c) 2022, 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. 29 | 30 | from datetime import datetime 31 | from typing import Any 32 | 33 | from powerapi.report.report import Report 34 | 35 | 36 | class FormulaReport(Report): 37 | """ 38 | FormulaReport class. 39 | Used to export information about a running formula. 40 | """ 41 | 42 | def __init__(self, timestamp: datetime, sensor: str, target: str, metadata: dict[str, Any] | None = None): 43 | """ 44 | :param timestamp: Report timestamp 45 | :param sensor: Sensor name 46 | :param target: Target name 47 | :param metadata: Metadata values 48 | """ 49 | super().__init__(timestamp, sensor, target, metadata) 50 | -------------------------------------------------------------------------------- /tests/unit/pusher/conftest.py: -------------------------------------------------------------------------------- 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. 29 | 30 | import pytest 31 | 32 | from powerapi.actor import Actor 33 | from powerapi.pusher.handlers import ReportHandler 34 | from powerapi.pusher.pusher_actor import PusherState 35 | 36 | 37 | @pytest.fixture 38 | def pusher_report_handler(fake_database): 39 | """ 40 | Factory fixture for creating a pusher report handler. 41 | """ 42 | def _create_handler(flush_interval: float = 1.0, buffer_size: int = 10, last_write_ts: float = 0.0): 43 | state = PusherState(Actor('test-actor'), fake_database) 44 | handler = ReportHandler(state, flush_interval, buffer_size) 45 | handler._last_write_ts = last_write_ts 46 | return handler 47 | 48 | return _create_handler 49 | -------------------------------------------------------------------------------- /tests/utils/actor/dummy_handlers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | import logging 30 | 31 | from powerapi.handler import Handler 32 | from powerapi.actor.message import Message 33 | 34 | 35 | class DummyHandler(Handler): 36 | 37 | """ 38 | Dummy actor handler for testing purposes 39 | """ 40 | 41 | def __init__(self, state): 42 | Handler.__init__(self, state) 43 | 44 | def handle(self, msg: Message): 45 | """ 46 | Handle a message and return a new state value of the actor 47 | 48 | :param Object msg: the message received by the actor 49 | """ 50 | self.state.pipe.send((self.state.actor.name, msg)) 51 | logging.debug('Received message: %s', msg, extra={'actor_name': self.state.actor.name}) 52 | -------------------------------------------------------------------------------- /src/powerapi/database/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from powerapi.database.driver import ReadableDatabase, WritableDatabase, ReadableWritableDatabase, DatabaseDriver 31 | from powerapi.database.codec import CodecOptions, ReportEncoder, ReportEncoderRegistry, ReportDecoder, ReportDecoderRegistry 32 | from powerapi.database.exceptions import DBError, ConnectionFailed, NotConnected, WriteFailed, ReadFailed 33 | from powerapi.database.csv import CSVInput, CSVOutput 34 | from powerapi.database.mongodb import MongodbInput, MongodbOutput 35 | from powerapi.database.opentsdb import OpenTSDB 36 | from powerapi.database.influxdb2 import InfluxDB2 37 | from powerapi.database.prometheus import Prometheus 38 | from powerapi.database.socket import Socket 39 | from powerapi.database.json import JsonInput, JsonOutput 40 | -------------------------------------------------------------------------------- /src/powerapi/database/exceptions.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.exception import PowerAPIExceptionWithMessage 31 | 32 | 33 | class DBError(PowerAPIExceptionWithMessage): 34 | """ 35 | Exception raised when an error occurs during a database operation. 36 | """ 37 | pass 38 | 39 | class ConnectionFailed(DBError): 40 | """ 41 | Exception raised when a database fails to connect. 42 | """ 43 | 44 | class NotConnected(DBError): 45 | """ 46 | Exception raised when trying to do an operation on a database that is not connected. 47 | """ 48 | 49 | class WriteFailed(DBError): 50 | """ 51 | Exception raised when a write operation fails. 52 | """ 53 | 54 | class ReadFailed(DBError): 55 | """ 56 | Exception raised when a read operation fails. 57 | """ 58 | -------------------------------------------------------------------------------- /tests/unit/processor/pre/k8s/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, Inria 2 | # Copyright (c) 2024, 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. 29 | 30 | from multiprocessing import Manager 31 | 32 | import pytest 33 | 34 | from powerapi.processor.pre.k8s.metadata_cache_manager import K8sMetadataCacheManager 35 | from powerapi.processor.pre.k8s.monitor_agent import K8sMonitorAgent 36 | 37 | 38 | @pytest.fixture(name='initialized_metadata_cache_manager') 39 | def fx_initialized_metadata_cache_manager(): 40 | """ 41 | Returns an initialized metadata cache manager. 42 | """ 43 | manager = Manager() 44 | yield K8sMetadataCacheManager(manager) 45 | 46 | manager.shutdown() 47 | 48 | 49 | @pytest.fixture 50 | def initialized_monitor_agent(initialized_metadata_cache_manager): 51 | """ 52 | Returns an initialized monitor agent. 53 | """ 54 | agent = K8sMonitorAgent(initialized_metadata_cache_manager, 'manual', '', '') 55 | return agent 56 | -------------------------------------------------------------------------------- /src/powerapi/processor/pre/k8s/_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, Inria 2 | # Copyright (c) 2024, 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. 29 | 30 | 31 | def is_target_a_valid_k8s_cgroups_path(target: str) -> bool: 32 | """ 33 | Checks if the provided target is a valid Kubernetes cgroups path. 34 | """ 35 | return target.startswith('/kubepods') 36 | 37 | 38 | def extract_container_id_from_k8s_cgroups_path(cgroups_path: str) -> str: 39 | """ 40 | Extract the container id from a Kubernetes cgroups path. 41 | :param cgroups_path: Cgroups path of the target 42 | :return: The container id 43 | """ 44 | container_id = cgroups_path.rsplit('/', 1)[1] 45 | 46 | # handle cgroups v2 (systemd) paths: 47 | if container_id.endswith('.scope'): 48 | container_id = container_id.replace('.scope', '') 49 | container_id = container_id.rsplit('-', 1)[1] # remove CRI prefix (i.e. 'containerd-') 50 | 51 | return container_id 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Python ### 2 | # Byte-compiled / optimized / DLL files 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | build/ 13 | develop-eggs/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | .pytest_cache/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Sphinx documentation 57 | docs/_build/ 58 | 59 | # Jupyter Notebook 60 | .ipynb_checkpoints 61 | 62 | # IPython 63 | profile_default/ 64 | ipython_config.py 65 | 66 | # pyenv 67 | .python-version 68 | 69 | # Environments 70 | .env 71 | .venv 72 | env/ 73 | venv/ 74 | ENV/ 75 | env.bak/ 76 | venv.bak/ 77 | 78 | # mypy 79 | .mypy_cache/ 80 | .dmypy.json 81 | dmypy.json 82 | 83 | # Pyre type checker 84 | .pyre/ 85 | 86 | ### Emacs ### 87 | *~ 88 | \#*\# 89 | /.emacs.desktop 90 | /.emacs.desktop.lock 91 | *.elc 92 | auto-save-list 93 | tramp 94 | .\#* 95 | 96 | # Org-mode 97 | .org-id-locations 98 | *_archive 99 | 100 | # flymake-mode 101 | *_flymake.* 102 | 103 | # eshell files 104 | /eshell/history 105 | /eshell/lastdir 106 | 107 | # elpa packages 108 | /elpa/ 109 | 110 | # reftex files 111 | *.rel 112 | 113 | # AUCTeX auto folder 114 | /auto/ 115 | 116 | # cask packages 117 | .cask/ 118 | dist/ 119 | 120 | # Flycheck 121 | flycheck_*.el 122 | 123 | # server auth directory 124 | /server/ 125 | 126 | # projectiles files 127 | .projectile 128 | 129 | # directory configuration 130 | .dir-locals.el 131 | 132 | # network security 133 | /network-security.data 134 | 135 | ### Vim ### 136 | # Swap 137 | [._]*.s[a-v][a-z] 138 | [._]*.sw[a-p] 139 | [._]s[a-rt-v][a-z] 140 | [._]ss[a-gi-z] 141 | [._]sw[a-p] 142 | 143 | # Session 144 | Session.vim 145 | 146 | # Temporary 147 | .netrwhist 148 | # Auto-generated tag files 149 | tags 150 | # Persistent undo 151 | [._]*.un~ 152 | 153 | ### IntelliJ IDEA ### 154 | .idea/ -------------------------------------------------------------------------------- /src/powerapi/processor/pre/openstack/_utils.py: -------------------------------------------------------------------------------- 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. 29 | 30 | import re 31 | 32 | LIBVIRT_INSTANCE_NAME_REGEX = re.compile(r"(instance-\d+)") 33 | 34 | 35 | def get_instance_name_from_libvirt_cgroup(target: str) -> str | None: 36 | """ 37 | Returns the instance name of the target. 38 | :param target: Cgroup path 39 | :return: Instance name (``instance-XXXXXXXX``) 40 | """ 41 | if "\\x" in target: 42 | # Some systems (cgroups v2 managed by systemd) escape special characters in the cgroup path. 43 | # Decoding the path is required in order to reliably extract the instance name. 44 | # For example: /sys/fs/cgroup/machine.slice/machine-qemu\\x2d3\\x2dinstance\\x2d00000003.scope/libvirt/emulator 45 | target = target.encode("utf-8").decode("unicode_escape") 46 | 47 | match = LIBVIRT_INSTANCE_NAME_REGEX.match(target) 48 | if match: 49 | return match.group(1) 50 | 51 | return None 52 | -------------------------------------------------------------------------------- /tests/unit/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from multiprocessing import active_children 31 | 32 | import pytest 33 | 34 | from powerapi.report import Report 35 | from tests.utils.db import SilentFakeDB 36 | 37 | 38 | @pytest.fixture 39 | def shutdown_system(): 40 | """ 41 | Shutdown the actor system, i.e., all actors are killed 42 | """ 43 | yield None 44 | active = active_children() 45 | for child in active: 46 | child.kill() 47 | 48 | 49 | @pytest.fixture 50 | def make_fake_database(): 51 | """ 52 | Factory fixture for creating a fake database with optional content. 53 | """ 54 | def _make(content: list[Report] | None = None) -> SilentFakeDB: 55 | return SilentFakeDB(content or []) 56 | 57 | return _make 58 | 59 | 60 | @pytest.fixture 61 | def fake_database(request) -> SilentFakeDB: 62 | """ 63 | Fixture to create a SilentFakeDB without content. 64 | """ 65 | return SilentFakeDB() 66 | -------------------------------------------------------------------------------- /src/powerapi/database/socket/codecs.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from datetime import datetime, timezone 31 | 32 | from powerapi.database.codec import CodecOptions, ReportDecoder, ReportDecoderRegistry 33 | from powerapi.report import HWPCReport 34 | 35 | 36 | class HWPCReportDecoder(ReportDecoder[dict, HWPCReport]): 37 | """ 38 | HwPC report decoder for the Socket database. 39 | """ 40 | 41 | @staticmethod 42 | def decode(data: dict, opts: CodecOptions | None = None) -> HWPCReport: 43 | timestamp = datetime.fromtimestamp(data['timestamp'] / 1000, tz=timezone.utc) # Unix timestamp in milliseconds 44 | return HWPCReport(timestamp, data['sensor'], data['target'], data['groups'], data.get('metadata', {})) 45 | 46 | 47 | class ReportDecoders(ReportDecoderRegistry): 48 | """ 49 | Socket database decoders registry. 50 | Contains the report decoders supported by the Socket database. 51 | """ 52 | 53 | ReportDecoders.register(HWPCReport, HWPCReportDecoder) 54 | -------------------------------------------------------------------------------- /src/powerapi/database/opentsdb/codecs.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from datetime import timezone 31 | 32 | from powerapi.database.codec import CodecOptions, ReportEncoder, ReportEncoderRegistry 33 | from powerapi.report import PowerReport 34 | 35 | 36 | class PowerReportEncoder(ReportEncoder[PowerReport, tuple[float, dict]]): 37 | """ 38 | Power Report encoder for the OpenTSDB database. 39 | """ 40 | 41 | @staticmethod 42 | def encode(report: PowerReport, opts: CodecOptions | None = None) -> tuple[float, dict]: 43 | timestamp = int(report.timestamp.replace(tzinfo=timezone.utc).timestamp()) 44 | tags = {'timestamp': timestamp, 'host': report.sensor, 'target': report.target} 45 | return report.power, tags 46 | 47 | 48 | class ReportEncoders(ReportEncoderRegistry): 49 | """ 50 | OpenTSDB database encoders registry. 51 | Contains the report encoders supported by the OpenTSDB database. 52 | """ 53 | 54 | ReportEncoders.register(PowerReport, PowerReportEncoder) 55 | -------------------------------------------------------------------------------- /src/powerapi/dispatcher/handlers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.handler import InitHandler, PoisonPillMessageHandler 31 | from powerapi.report import Report 32 | 33 | 34 | class DispatcherPoisonPillMessageHandler(PoisonPillMessageHandler): 35 | """ 36 | Dispatcher Handler for PoisonPillMessage 37 | """ 38 | def teardown(self, soft=False): 39 | self.state.supervisor.kill_actors(soft) 40 | 41 | 42 | class FormulaDispatcherReportHandler(InitHandler): 43 | """ 44 | Send the received reports to their corresponding formula. 45 | """ 46 | 47 | def handle(self, msg: Report): 48 | """ 49 | Send the report to its corresponding formula(s). 50 | :param msg: The report to process 51 | """ 52 | dispatch_rule = self.state.route_table.get_dispatch_rule(msg) 53 | for formula_id in dispatch_rule.get_formula_id(msg): 54 | formula = self.state.get_formula(formula_id) 55 | if formula.is_alive(): 56 | formula.send_data(msg) 57 | -------------------------------------------------------------------------------- /src/powerapi/handler/start_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.actor.message import OKMessage, StartMessage, ErrorMessage 31 | from .handler import Handler 32 | 33 | 34 | class StartHandler(Handler): 35 | """ 36 | Initialize the received state 37 | """ 38 | 39 | def handle(self, msg): 40 | """ 41 | Allow to initialize the state of the actor, then reply to the control 42 | socket. 43 | 44 | :param powerapi.StartMessage msg: Message that initialize the actor 45 | """ 46 | if self.state.initialized: 47 | self.state.actor.send_control(ErrorMessage('Actor already initialized')) 48 | return 49 | 50 | if not isinstance(msg, StartMessage): 51 | return 52 | 53 | self.initialization() 54 | 55 | if self.state.alive: 56 | self.state.initialized = True 57 | self.state.actor.send_control(OKMessage()) 58 | 59 | def initialization(self): 60 | """ 61 | Abstract method that initialize the actor after receiving a start msg 62 | """ 63 | -------------------------------------------------------------------------------- /src/powerapi/actor/message.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, Inria 2 | # Copyright (c) 2022, 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. 29 | 30 | 31 | class Message: 32 | """ 33 | Abstract actor Message class. 34 | """ 35 | 36 | 37 | class OKMessage(Message): 38 | """ 39 | Message sent by an actor after a successful startup. 40 | """ 41 | 42 | 43 | class ErrorMessage(Message): 44 | """ 45 | Message sent by an actor when an error occurs during startup. 46 | """ 47 | 48 | def __init__(self, error_message: str): 49 | """ 50 | :param error_message: Message associated to the encountered error. 51 | """ 52 | self.error_message = error_message 53 | 54 | 55 | class StartMessage(Message): 56 | """ 57 | Message sent to an actor to initiate its startup. 58 | """ 59 | 60 | 61 | class PoisonPillMessage(Message): 62 | """ 63 | Message sent to an actor to initiate its shutdown. 64 | """ 65 | 66 | def __init__(self, soft: bool = True): 67 | """ 68 | :param bool soft: Indicate whether the actor should process all its messages before shutting down. 69 | """ 70 | self.is_soft = soft 71 | -------------------------------------------------------------------------------- /src/powerapi/report/hwpc_report.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Inria 2 | # Copyright (c) 2021, 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. 29 | 30 | from datetime import datetime 31 | from typing import Any 32 | 33 | from powerapi.report.report import Report 34 | 35 | 36 | class HWPCReport(Report): 37 | """ 38 | HWPCReport class. 39 | Stores Hardware Performance Counters samples coming from the HwPC-Sensor. 40 | """ 41 | 42 | def __init__(self, timestamp: datetime, sensor: str, target: str, groups: dict[str, dict], metadata: dict[str, Any] | None = None): 43 | """ 44 | :param timestamp: Timestamp of the report 45 | :param sensor: Sensor name 46 | :param target: Target name 47 | :param groups: Events groups 48 | """ 49 | super().__init__(timestamp, sensor, target, metadata) 50 | 51 | self.groups = groups 52 | 53 | def __repr__(self) -> str: 54 | return f'HWPCReport({self.timestamp}, {self.sensor}, {self.target}, {sorted(self.groups.keys())})' 55 | 56 | def __eq__(self, other: object) -> bool: 57 | if not isinstance(other, HWPCReport): 58 | return NotImplemented 59 | 60 | return super().__eq__(other) and self.groups == other.groups 61 | -------------------------------------------------------------------------------- /src/powerapi/report/power_report.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Inria 2 | # Copyright (c) 2021, 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. 29 | 30 | from datetime import datetime 31 | from typing import Any 32 | 33 | from powerapi.report.report import Report 34 | 35 | 36 | class PowerReport(Report): 37 | """ 38 | PowerReport class. 39 | Used to export the power estimations computed by a formula. 40 | """ 41 | 42 | def __init__(self, timestamp: datetime, sensor: str, target: str, power: float, metadata: dict[str, Any] | None = None): 43 | """ 44 | :param timestamp: Report timestamp 45 | :param sensor: Sensor name 46 | :param target: Target name 47 | :param power: Power estimation value 48 | :param metadata: Dictionary of metadata values 49 | """ 50 | super().__init__(timestamp, sensor, target, metadata) 51 | 52 | self.power = power 53 | 54 | def __repr__(self) -> str: 55 | return f'PowerReport({self.timestamp}, {self.sensor}, {self.target}, {self.power})' 56 | 57 | def __eq__(self, other: object) -> bool: 58 | if not isinstance(other, PowerReport): 59 | return NotImplemented 60 | 61 | return super().__eq__(other) and self.power == other.power 62 | -------------------------------------------------------------------------------- /tests/utils/report/power.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | import datetime 30 | 31 | from powerapi.report import PowerReport 32 | 33 | SENSOR_NAME = 'sensor_test' 34 | TARGET_NAME = 'target_test' 35 | 36 | POWER_REPORT_1 = PowerReport(0, SENSOR_NAME, TARGET_NAME, 1234, {'socket': 0, 'metadata1': 'truc', 'metadata2': 'oui'}) 37 | 38 | 39 | def gen_json_power_report(number_of_reports): 40 | """ 41 | generate number_of_reports power report with json format 42 | each power report have the same sensor, target and power value (100W) 43 | only the timestamp is different. 44 | timestamp is generated from 01/01/1970 0:00.0 for the first report and is incremented by 1s for each returned report 45 | """ 46 | reports = [] 47 | for ts in range(number_of_reports): 48 | tmstp_tmp = str(datetime.datetime.fromtimestamp(ts)) 49 | tmstp = tmstp_tmp[:tmstp_tmp.index(' ')] + 'T' + tmstp_tmp[tmstp_tmp.index(' ') + 1:] + '.0' 50 | reports.append( 51 | { 52 | "timestamp": tmstp, 53 | "sensor": SENSOR_NAME, 54 | "target": TARGET_NAME, 55 | "power": 42, 56 | } 57 | ) 58 | return reports 59 | -------------------------------------------------------------------------------- /src/powerapi/formula/abstract_cpu_dram_formula.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | import logging 31 | from typing import Any 32 | 33 | from powerapi.actor import Actor 34 | from powerapi.formula.formula_actor import FormulaActor, FormulaState 35 | from powerapi.pusher import PusherActor 36 | 37 | 38 | class AbstractCpuDramFormulaState(FormulaState): 39 | """ 40 | Formula values with configurable sleeping time for dummy formula 41 | """ 42 | 43 | def __init__(self, actor: Actor, pushers: dict[str, Actor], metadata: dict[str, Any], socket: str, core: str): 44 | FormulaState.__init__(self, actor, pushers, metadata) 45 | self.socket = socket 46 | self.core = core 47 | 48 | 49 | class AbstractCpuDramFormula(FormulaActor): 50 | """ 51 | Formula that handle CPU or DRAM related data 52 | It can be launched to handle data from a specific part of a cpu (whole cpu, a socket or a core) 53 | """ 54 | 55 | def __init__(self, name, pushers: dict[str, PusherActor], socket: str, core: str, level_logger=logging.WARNING, 56 | timeout=None): 57 | FormulaActor.__init__(self, name, pushers, level_logger, timeout) 58 | self.state = AbstractCpuDramFormulaState(self, pushers, self.formula_metadata, socket, core) 59 | -------------------------------------------------------------------------------- /src/powerapi/database/prometheus/codecs.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from dataclasses import dataclass 31 | 32 | from powerapi.database.codec import CodecOptions, ReportEncoder, ReportEncoderRegistry 33 | from powerapi.report import PowerReport 34 | 35 | 36 | @dataclass 37 | class EncoderOptions(CodecOptions): 38 | """ 39 | Encoder options for the Prometheus database. 40 | """ 41 | dynamic_tags_name: list[str] 42 | 43 | 44 | class PowerReportEncoder(ReportEncoder[PowerReport, tuple[tuple[str, ...], tuple[float, float]]]): 45 | """ 46 | Power Report encoder for the Prometheus database. 47 | """ 48 | 49 | @staticmethod 50 | def encode(report: PowerReport, opts: EncoderOptions | None = None) -> tuple[tuple[str, ...], tuple[float, float]]: 51 | flattened_tags = report.flatten_tags(report.metadata) 52 | dynamic_tags = [flattened_tags.get(tag_name, 'unknown') for tag_name in opts.dynamic_tags_name] 53 | return (report.sensor, report.target, *dynamic_tags), (report.timestamp.timestamp(), report.power) 54 | 55 | 56 | class ReportEncoders(ReportEncoderRegistry): 57 | """ 58 | Prometheus database encoders registry. 59 | Contains the report encoders supported by the Prometheus database. 60 | """ 61 | 62 | ReportEncoders.register(PowerReport, PowerReportEncoder) 63 | -------------------------------------------------------------------------------- /src/powerapi/report/control_report.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Inria 2 | # Copyright (c) 2021, 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. 29 | 30 | from datetime import datetime 31 | from typing import Any 32 | 33 | from powerapi.report import Report 34 | 35 | 36 | class ControlReport(Report): 37 | """ 38 | ControlReport class. 39 | Stores information about an action, which can be used to control external tools from a formula. 40 | """ 41 | 42 | def __init__(self, timestamp: datetime, sensor: str, target: str, action: str, parameters: list, metadata: dict[str, Any] | None = None): 43 | """ 44 | :param timestamp: Report timestamp 45 | :param sensor: Sensor name 46 | :param target: Target name 47 | :param action: Action name 48 | :param parameters: Parameter values 49 | """ 50 | super().__init__(timestamp, sensor, target, metadata) 51 | 52 | self.action = action 53 | self.parameters = parameters 54 | 55 | def __repr__(self) -> str: 56 | return f'ControlReport({self.timestamp}, {self.sensor}, {self.target}, {self.action}, {self.parameters})' 57 | 58 | def __eq__(self, other: object) -> bool: 59 | if not isinstance(other, ControlReport): 60 | return NotImplemented 61 | 62 | return super().__eq__(other) and self.action == other.action and self.parameters == other.parameters 63 | -------------------------------------------------------------------------------- /tests/utils/actor/dummy_actor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.handler import PoisonPillMessageHandler, StartHandler 31 | from powerapi.actor.message import StartMessage, PoisonPillMessage 32 | from powerapi.actor import Actor, State 33 | from tests.utils.actor.dummy_handlers import DummyHandler 34 | 35 | LOGGER_NAME = 'multiprocess_test_logger' 36 | 37 | 38 | class DummyActorState(State): 39 | """ 40 | Message used to start a DummyActor 41 | :param pipe: pipe used to send message to pytest process 42 | """ 43 | 44 | def __init__(self, actor: Actor, pipe): 45 | State.__init__(self, actor) 46 | self.pipe = pipe 47 | 48 | 49 | class DummyActor(Actor): 50 | """ 51 | Actor that forward all start message (except StartMessage) into a pipe to the test process 52 | """ 53 | 54 | def __init__(self, name: str, pipe, message_type): 55 | Actor.__init__(self, name) 56 | self.state = DummyActorState(self, pipe) 57 | self.message_type = message_type 58 | 59 | def setup(self): 60 | """ 61 | Define message handler 62 | """ 63 | self.add_handler(self.message_type, DummyHandler(self.state)) 64 | self.add_handler(PoisonPillMessage, PoisonPillMessageHandler(self.state)) 65 | self.add_handler(StartMessage, StartHandler(self.state)) 66 | -------------------------------------------------------------------------------- /src/powerapi/database/driver.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from abc import ABC, abstractmethod 31 | from collections.abc import Iterable 32 | 33 | from powerapi.report import Report 34 | 35 | 36 | class DatabaseDriver(ABC): 37 | """ 38 | Abstract base class for database drivers. 39 | """ 40 | 41 | @abstractmethod 42 | def connect(self) -> None: ... 43 | 44 | @abstractmethod 45 | def disconnect(self) -> None: ... 46 | 47 | 48 | class ReadableDatabase(DatabaseDriver, ABC): 49 | """ 50 | Interface for database drivers that can retrieve reports. 51 | """ 52 | 53 | @staticmethod 54 | @abstractmethod 55 | def supported_read_types() -> Iterable[type[Report]]: ... 56 | 57 | @abstractmethod 58 | def read(self, stream_mode: bool = False) -> Iterable[Report]: ... 59 | 60 | 61 | class WritableDatabase(DatabaseDriver, ABC): 62 | """ 63 | Interface for database drivers that can persist reports. 64 | """ 65 | 66 | @staticmethod 67 | @abstractmethod 68 | def supported_write_types() -> Iterable[type[Report]]: ... 69 | 70 | @abstractmethod 71 | def write(self, reports: Iterable[Report]) -> None: ... 72 | 73 | 74 | class ReadableWritableDatabase(ReadableDatabase, WritableDatabase, ABC): 75 | """ 76 | Interface for database drivers that can both persist and retrieve reports. 77 | """ 78 | -------------------------------------------------------------------------------- /tests/utils/db/mongo.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | import pytest 30 | import pymongo 31 | 32 | 33 | MONGO_URI = "mongodb://127.0.0.1:27017/" 34 | MONGO_INPUT_COLLECTION_NAME = 'test_input' 35 | MONGO_OUTPUT_COLLECTION_NAME = 'test_output' 36 | MONGO_DATABASE_NAME = 'MongoDB1' 37 | 38 | 39 | @pytest.fixture 40 | def mongo_database(mongodb_content): 41 | """ 42 | connect to a local mongo database (localhost:27017) and store data contained in the list influxdb_content 43 | after test end, delete the data 44 | """ 45 | _gen_base_db_test(MONGO_URI, mongodb_content) 46 | yield None 47 | _clean_base_db_test(MONGO_URI) 48 | 49 | 50 | def _gen_base_db_test(uri, content): 51 | mongo = pymongo.MongoClient(uri) 52 | db = mongo[MONGO_DATABASE_NAME] 53 | 54 | # delete collection if it already exist 55 | db[MONGO_INPUT_COLLECTION_NAME].drop() 56 | db.create_collection(MONGO_INPUT_COLLECTION_NAME) 57 | for item in content: 58 | db[MONGO_INPUT_COLLECTION_NAME].insert_one(item) 59 | 60 | # delete output collection 61 | db[MONGO_OUTPUT_COLLECTION_NAME].drop() 62 | mongo.close() 63 | 64 | 65 | def _clean_base_db_test(uri): 66 | """ 67 | drop test_hwrep and test_result collections 68 | """ 69 | mongo = pymongo.MongoClient(uri) 70 | db = mongo[MONGO_DATABASE_NAME] 71 | db[MONGO_INPUT_COLLECTION_NAME].drop() 72 | db[MONGO_OUTPUT_COLLECTION_NAME].drop() 73 | mongo.close() 74 | -------------------------------------------------------------------------------- /src/powerapi/dispatcher/route_table.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from powerapi.dispatch_rule import DispatchRule 31 | from powerapi.report import Report 32 | 33 | 34 | class RouteTable: 35 | """ 36 | Routing Table used by the Dispatcher to map report types to dispatch rules. 37 | """ 38 | 39 | def __init__(self): 40 | """ 41 | Initializes a new Routing Table. 42 | """ 43 | self.route_table = {} 44 | self.primary_dispatch_rule = None 45 | 46 | def get_dispatch_rule(self, report: Report) -> DispatchRule | None: 47 | """ 48 | Return the corresponding dispatch rule for the given report. 49 | param msg: The report to get the dispatch rule for 50 | return: The corresponding dispatch rule or None if no dispatch rule exists for the report type. 51 | """ 52 | return self.route_table.get(report.__class__.__name__, None) 53 | 54 | def add_dispatch_rule(self, report_type: type[Report], dispatch_rule: DispatchRule): 55 | """ 56 | Add a dispatch rule for the given report type. 57 | :param report_type: The report type to which the dispatch rule should map to 58 | :param dispatch_rule: The dispatch rule to handle the reports of the given type 59 | """ 60 | if dispatch_rule.is_primary: 61 | self.primary_dispatch_rule = dispatch_rule 62 | 63 | self.route_table[report_type.__name__] = dispatch_rule 64 | -------------------------------------------------------------------------------- /src/powerapi/processor/processor_actor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, INRIA 2 | # Copyright (c) 2023, 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. 29 | 30 | import logging 31 | 32 | from powerapi.actor import State, Actor 33 | 34 | 35 | class ProcessorState(State): 36 | """ 37 | Processor Actor State. 38 | """ 39 | 40 | def __init__(self, actor: Actor, target_actors: list, target_actors_names: list): 41 | """ 42 | :param list target_actors: List of target actors for the processor 43 | """ 44 | super().__init__(actor) 45 | 46 | if not target_actors: 47 | target_actors = [] 48 | 49 | self.target_actors = target_actors 50 | self.target_actors_names = target_actors_names 51 | 52 | 53 | class ProcessorActor(Actor): 54 | """ 55 | Processor actor class. 56 | A processor modifies a report and sends the modified report to a list of targets actor. 57 | """ 58 | 59 | def __init__(self, name: str, level_logger: int = logging.WARNING, timeout: int = 5000): 60 | super().__init__(name, level_logger, timeout) 61 | self.state = ProcessorState(self, [], []) 62 | 63 | def setup(self): 64 | """ 65 | Set up the Processor actor. 66 | """ 67 | raise NotImplementedError 68 | 69 | def add_target_actor(self, actor: Actor): 70 | """ 71 | Add the given actor to the list of targets 72 | :param actor: Actor to be defined as target 73 | """ 74 | self.state.target_actors.append(actor) 75 | -------------------------------------------------------------------------------- /tests/utils/formula/dummy/dummy_handlers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, INRIA 2 | # Copyright (c) 2022, 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. 29 | 30 | from powerapi.handler import Handler 31 | from powerapi.report import PowerReport 32 | 33 | 34 | class ReportHandler(Handler): 35 | """ 36 | Basic handler behaviour for a kind of Report 37 | """ 38 | 39 | def _estimate(self, report): 40 | """ 41 | Method that estimate the power consumption from an input report 42 | :param report: Input Report 43 | :return: List of PowerReport 44 | """ 45 | socket_id = self.state.socket if self.state.socket is not None else -1 46 | 47 | metadata = report.metadata 48 | 49 | metadata['formula_name'] = self.state.actor.name 50 | metadata['socket'] = socket_id 51 | 52 | result_msg = PowerReport(report.timestamp, report.sensor, report.target, 42, metadata) 53 | return [result_msg] 54 | 55 | def handle(self, msg): 56 | """ 57 | Process a report and send the result to the pusher actor 58 | :param powerapi.Report msg: Received message 59 | """ 60 | results = self._estimate(msg) 61 | 62 | # Send the reports to every available pusher because a lot of unit tests don't set up their test actor correctly. 63 | # FIXME: Reports should only be sent to theirs corresponding pusher(s) 64 | for pushers in self.state.pushers.values(): 65 | for pusher in pushers: 66 | for result in results: 67 | pusher.send_data(result) 68 | -------------------------------------------------------------------------------- /tests/utils/db/socket.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | import json 30 | import time 31 | from threading import Thread 32 | from socket import socket 33 | 34 | 35 | class ClientThread(Thread): 36 | """ 37 | Thread that open a connection to a socket and send it a list of reports 38 | """ 39 | 40 | def __init__(self, msg_list, port): 41 | Thread.__init__(self) 42 | 43 | self.msg_list = msg_list 44 | self.socket = socket() 45 | self.port = port 46 | 47 | def run(self): 48 | 49 | self.socket.connect(('127.0.0.1', self.port)) 50 | for msg in self.msg_list: 51 | self.socket.send(bytes(json.dumps(msg), 'utf-8')) 52 | self.socket.close() 53 | 54 | 55 | class ClientThreadDelay(Thread): 56 | """ 57 | Thread that open a connection to a socket and send it a list of reports 58 | insert a delay of one second after sending half of the messages 59 | """ 60 | 61 | def __init__(self, msg_list, port): 62 | Thread.__init__(self) 63 | 64 | self.msg_list = msg_list 65 | self.socket = socket() 66 | self.port = port 67 | 68 | def run(self): 69 | 70 | self.socket.connect(('127.0.0.1', self.port)) 71 | midle = int(len(self.msg_list) / 2) 72 | for msg in self.msg_list[:midle]: 73 | self.socket.send(bytes(json.dumps(msg), 'utf-8')) 74 | time.sleep(1) 75 | for msg in self.msg_list[midle:]: 76 | self.socket.send(bytes(json.dumps(msg), 'utf-8')) 77 | self.socket.close() 78 | -------------------------------------------------------------------------------- /src/powerapi/handler/poison_pill_message_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.actor.message import PoisonPillMessage 31 | from powerapi.exception import UnknownMessageTypeException 32 | from .handler import Handler 33 | 34 | 35 | class PoisonPillMessageHandler(Handler): 36 | """ 37 | Generic handler for PoisonPillMessage 38 | """ 39 | 40 | def teardown(self, soft=False): 41 | """ 42 | function called before terminating the actor process 43 | could be redefined 44 | """ 45 | 46 | def handle_msg(self, msg): 47 | """ 48 | Handle the given message 49 | :param msg: The message to handle 50 | """ 51 | Handler.delegate_message_handling(self, msg) 52 | 53 | def _empty_mail_box(self): 54 | while True: 55 | self.state.actor.socket_interface.timeout = 0.1 56 | msg = self.state.actor.socket_interface.receive() 57 | 58 | if msg is not None: 59 | self.handle_msg(msg) 60 | else: 61 | return 62 | 63 | def handle(self, msg): 64 | """ 65 | Set the :attr:`alive ` 66 | attribute of the actor state to False 67 | 68 | :param Object msg: the message received by the actor 69 | """ 70 | if not isinstance(msg, PoisonPillMessage): 71 | raise UnknownMessageTypeException(type(msg)) 72 | 73 | if msg.is_soft: 74 | self._empty_mail_box() 75 | self.teardown(soft=msg.is_soft) 76 | self.state.alive = False 77 | -------------------------------------------------------------------------------- /src/powerapi/filter/filter.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, INRIA 2 | # Copyright (c) 2018, 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. 29 | 30 | from powerapi.exception import PowerAPIException 31 | 32 | 33 | class FilterUselessError(PowerAPIException): 34 | """ 35 | Exception raised when a filter route with 0 filters 36 | """ 37 | 38 | 39 | class Filter: 40 | """ 41 | Filter class 42 | 43 | A filter allow the Puller to route Report of the database to Dispatchers 44 | by fixing some rules. 45 | """ 46 | 47 | def __init__(self): 48 | self.filters = [] 49 | 50 | def filter(self, rule, dispatcher): 51 | """ 52 | Define a rule for a kind of report, and send it to the dispatcher 53 | if the rule accept it. 54 | 55 | :param (func(report) -> bool) rule: Function which return if 56 | the report has to be send to 57 | this dispatcher 58 | :param powerapi.Dispatcher dispatcher: Dispatcher we want to send the 59 | report 60 | """ 61 | self.filters.append((rule, dispatcher)) 62 | 63 | def route(self, report): 64 | """ 65 | Get the list of dispatchers to whom send the report, or None 66 | 67 | :param powerapi.Report report: Message to send 68 | """ 69 | # Error if filters is empty 70 | if not self.filters: 71 | raise FilterUselessError() 72 | 73 | dispatchers = [] 74 | for rule, dispatcher in self.filters: 75 | if rule(report): 76 | dispatchers.append(dispatcher) 77 | 78 | return dispatchers 79 | -------------------------------------------------------------------------------- /src/powerapi/dispatch_rule/power_dispatch_rule.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, INRIA 2 | # Copyright (c) 2021, 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. 29 | 30 | from enum import IntEnum 31 | 32 | from powerapi.report import PowerReport 33 | from .dispatch_rule import DispatchRule 34 | 35 | 36 | class PowerDepthLevel(IntEnum): 37 | """ 38 | Enumeration that specify which report level use to group by the reports 39 | """ 40 | 41 | TARGET = -1 42 | SENSOR = 0 43 | SOCKET = 1 44 | CORE = 2 45 | 46 | 47 | def extract_id_from_report(report: PowerReport, depth: PowerDepthLevel) -> tuple: 48 | """ 49 | :return: a report id generated from the report and the given depth 50 | """ 51 | if depth == PowerDepthLevel.TARGET: 52 | return (report.target,) 53 | 54 | if depth == PowerDepthLevel.SENSOR: 55 | return (report.sensor,) 56 | 57 | if depth == PowerDepthLevel.SOCKET: 58 | return *extract_id_from_report(report, depth - 1), report.metadata['socket'] 59 | 60 | return *extract_id_from_report(report, depth - 1), report.metadata['core'] 61 | 62 | 63 | class PowerDispatchRule(DispatchRule): 64 | """ 65 | Group by rule for HWPC report 66 | """ 67 | def __init__(self, depth: PowerDepthLevel, primary: bool = False): 68 | """ 69 | :param depth: 70 | :type depth: HWPCDepthLevel 71 | """ 72 | DispatchRule.__init__(self, primary, self._get_fields_by_depth(depth)) 73 | self.depth = depth 74 | 75 | @staticmethod 76 | def _get_fields_by_depth(depth: PowerDepthLevel) -> list[str]: 77 | if depth == PowerDepthLevel.TARGET: 78 | return ['target'] 79 | 80 | return ['sensor', 'socket', 'core'][:(depth + 1)] 81 | 82 | def get_formula_id(self, report): 83 | return [extract_id_from_report(report, self.depth)] 84 | -------------------------------------------------------------------------------- /src/powerapi/database/mongodb/codecs.py: -------------------------------------------------------------------------------- 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. 29 | 30 | from powerapi.database.codec import CodecOptions, ReportEncoder, ReportEncoderRegistry, ReportDecoder, ReportDecoderRegistry 31 | from powerapi.report import PowerReport, FormulaReport, HWPCReport 32 | 33 | 34 | class PowerReportEncoder(ReportEncoder[PowerReport, dict]): 35 | """ 36 | Power Report encoder for the MongoDB database. 37 | """ 38 | 39 | @staticmethod 40 | def encode(report: PowerReport, opts: CodecOptions | None = None) -> dict: 41 | return vars(report) 42 | 43 | class FormulaReportEncoder(ReportEncoder[FormulaReport, dict]): 44 | """ 45 | Formula report encoder for the MongoDB database. 46 | """ 47 | 48 | @staticmethod 49 | def encode(report: FormulaReport, opts: CodecOptions | None = None) -> dict: 50 | return vars(report) 51 | 52 | class HWPCReportDecoder(ReportDecoder[dict, HWPCReport]): 53 | """ 54 | HwPC Report decoder for the MongoDB database. 55 | """ 56 | 57 | @staticmethod 58 | def decode(data: dict, opts: CodecOptions | None = None) -> HWPCReport: 59 | return HWPCReport(data['timestamp'], data['sensor'], data['target'], data['groups'], data.get('metadata', {})) 60 | 61 | 62 | class ReportEncoders(ReportEncoderRegistry): 63 | """ 64 | MongoDB database encoders registry. 65 | Contains the report encoders supported by the MongoDB database. 66 | """ 67 | 68 | ReportEncoders.register(PowerReport, PowerReportEncoder) 69 | ReportEncoders.register(FormulaReport, FormulaReportEncoder) 70 | 71 | class ReportDecoders(ReportDecoderRegistry): 72 | """ 73 | MongoDB database decoders registry. 74 | Contains the report decoders supported by the MongoDB database. 75 | """ 76 | 77 | ReportDecoders.register(HWPCReport, HWPCReportDecoder) 78 | --------------------------------------------------------------------------------