Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import pickle
import logging
import multiprocessing
import ctypes
import zmq
from powerapi.actor import SafeContext
from powerapi.exception import PowerAPIException
LOCAL_ADDR = 'tcp://127.0.0.1'
class NotConnectedException(PowerAPIException):
"""
Exception raised when attempting to send/receinve a message on a socket
that is not conected
"""
class SocketInterface:
"""
Interface to handle comunication to/from the actor
general methods :
- :meth:`send_control `
client interface methods :
- :meth:`connect_data `
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from powerapi.exception import PowerAPIException
class HandlerException(PowerAPIException):
"""
Exception raised when a problem appear in a handler
"""
def __init__(self, msg):
"""
:param str msg: Message of the error
"""
super().__init__(msg)
class Handler:
"""
Class that handle a message of a given type
"""
def __init__(self, state):
"""
class CrashConfigureError(PowerAPIException):
"""
Exception raised when an actor crash during initialisation
"""
class ActorAlreadySupervisedException(PowerAPIException):
"""
Exception raised when trying to supervise with a supervisor that already
supervise this actor
"""
class ActorAlreadyLaunchedException(PowerAPIException):
"""
Exception raised when trying to supervise with a supervisor that already
supervise this actor
"""
class Supervisor:
def __init__(self):
#: ([powerapi.actor.actor.Actor]): list of supervised actors
self.supervised_actors = []
def launch_actor(self, actor, start_message=True):
"""
Launch the actor :
- start the process that execute the actor code
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from typing import Dict, List, Tuple
from powerapi.exception import PowerAPIException
CSV_HEADER_COMMON = ['timestamp', 'sensor', 'target']
CSV_HEADER_HWPC = CSV_HEADER_COMMON + ['socket', 'cpu']
CSV_HEADER_POWER = CSV_HEADER_COMMON + ['power']
class BadInputData(PowerAPIException):
"""
Exception raised when the data read in input are not
in the good format
"""
class ReportModel:
"""
ReportModel class.
It define all the function that need to be override if we want
to format the raw data read in different kind of database.
"""
def get_type(self):
"""
from powerapi.message import StartMessage, ErrorMessage
class ActorInitError(PowerAPIException):
"""
Exception raised when an error occuried during the actor initialisation
process
"""
def __init__(self, message):
super().__init__()
#: (str): error description
self.message = message
class FailConfigureError(PowerAPIException):
"""
Exception raised when an error occured during the actor setup process
"""
class CrashConfigureError(PowerAPIException):
"""
Exception raised when an actor crash during initialisation
"""
class ActorAlreadySupervisedException(PowerAPIException):
"""
Exception raised when trying to supervise with a supervisor that already
supervise this actor
"""
def _find_longest_name(names):
max_len = 0
longest_name = ''
for name in names:
if len(name) > max_len:
longest_name = name
max_len = len(name)
return longest_name
#############
# EXCEPTION #
#############
class ParserException(PowerAPIException):
def __init__(self, argument_name):
super().__init__()
self.argument_name = argument_name
class NoNameSpecifiedForComponentException(ParserException):
"""
Exception raised when attempting to parse substring thant describe a component which not contains the component name
"""
class ComponentAlreadyExistException(ParserException):
"""
Exception raised when attempting to parse a substring to create a component with a name that already exist
"""
"""
Exception raised when attempting to parse a substring to create a component with a name that already exist
"""
class BadValueException(ParserException):
"""
Exception raised when attempting to parse a value that doens't respect the
check function of its argument
"""
def __init__(self, argument_name, msg):
ParserException.__init__(self, argument_name)
self.msg = msg
class SubParserWithoutNameArgumentException(PowerAPIException):
"""
Exception raised when a subparser without argument name is added to a parser
"""
class TooManyArgumentNamesException(ParserException):
"""
Exception raised when attemtping to add an argument with too much names
"""
def __init__(self, argument_name):
ParserException.__init__(self, argument_name)
class AlreadyAddedArgumentException(ParserException):
"""
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import annotations
from datetime import datetime
from typing import Dict
from powerapi.exception import PowerAPIException
from powerapi.message import Message
class DeserializationFail(PowerAPIException):
"""
Exception raised when the
in the good format
"""
class Report(Message):
"""
Report abtract class.
"""
def __init__(self, timestamp: datetime, sensor: str, target: str):
"""
Initialize a report using the given parameters.
:param datetime timestamp: Timestamp
:param str sensor: Sensor name.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from powerapi.exception import PowerAPIException
from powerapi.message import StartMessage, ErrorMessage
class ActorInitError(PowerAPIException):
"""
Exception raised when an error occuried during the actor initialisation
process
"""
def __init__(self, message):
super().__init__()
#: (str): error description
self.message = message
class FailConfigureError(PowerAPIException):
"""
Exception raised when an error occured during the actor setup process
"""
self.message = message
class FailConfigureError(PowerAPIException):
"""
Exception raised when an error occured during the actor setup process
"""
class CrashConfigureError(PowerAPIException):
"""
Exception raised when an actor crash during initialisation
"""
class ActorAlreadySupervisedException(PowerAPIException):
"""
Exception raised when trying to supervise with a supervisor that already
supervise this actor
"""
class ActorAlreadyLaunchedException(PowerAPIException):
"""
Exception raised when trying to supervise with a supervisor that already
supervise this actor
"""
class Supervisor:
def __init__(self):