forked from powerapi-ng/powerapi-scala
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request powerapi-ng#31 from Spirals-Team/feature/procfs-mo…
…dule Feature/procfs module
- Loading branch information
Showing
48 changed files
with
1,980 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/scala/org/powerapi/configuration/LogicalCoresConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.configuration | ||
|
||
import org.powerapi.core.Configuration | ||
|
||
/** | ||
* Number of logical cores / Configuration. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait LogicalCoresConfiguration { | ||
self: Configuration => | ||
|
||
import org.powerapi.core.ConfigValue | ||
|
||
lazy val cores = load { _.getInt("powerapi.hardware.cores") } match { | ||
case ConfigValue(nbCores) => nbCores | ||
case _ => 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,16 @@ package org.powerapi.core | |
import akka.actor.SupervisorStrategy.{Directive, Resume} | ||
import akka.actor.{Actor, Cancellable, PoisonPill, Props} | ||
import akka.event.LoggingReceive | ||
|
||
import scala.concurrent.duration.{Duration, FiniteDuration} | ||
|
||
/** | ||
* One child clock is created per frequency. | ||
* Allows to publish a message in the right topics for a given frequency. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
class ClockChild(eventBus: MessageBus, frequency: FiniteDuration) extends Component { | ||
import org.powerapi.core.ClockChannel.{ClockStart, ClockStop, ClockStopAll, publishTick} | ||
class ClockChild(eventBus: MessageBus, frequency: FiniteDuration) extends ActorComponent { | ||
import org.powerapi.core.ClockChannel.{ClockStart, ClockStop, ClockStopAll, publishClockTick} | ||
|
||
def receive: PartialFunction[Any, Unit] = LoggingReceive { | ||
case ClockStart(_, freq) if frequency == freq => start() | ||
|
@@ -60,7 +61,7 @@ class ClockChild(eventBus: MessageBus, frequency: FiniteDuration) extends Compon | |
*/ | ||
def start(): Unit = { | ||
val timer = context.system.scheduler.schedule(Duration.Zero, frequency) { | ||
publishTick(frequency)(eventBus) | ||
publishClockTick(frequency)(eventBus) | ||
} (context.system.dispatcher) | ||
|
||
log.info("clock started, reference: {}", frequency.toNanos) | ||
|
@@ -89,12 +90,14 @@ class ClockChild(eventBus: MessageBus, frequency: FiniteDuration) extends Compon | |
/** | ||
* This clock listens the bus on a given topic and reacts on the received message. | ||
* It is responsible to handle a pool of clocks for the monitored frequencies. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
class Clocks(eventBus: MessageBus) extends Component with Supervisor { | ||
import org.powerapi.core.ClockChannel.{ClockStart, ClockStop, ClockStopAll, formatClockChildName, stopAllClock, subscribeTickSubscription} | ||
class Clocks(eventBus: MessageBus) extends Supervisor { | ||
import org.powerapi.core.ClockChannel.{ClockStart, ClockStop, ClockStopAll, formatClockChildName, stopAllClock, subscribeClockChannel} | ||
|
||
override def preStart(): Unit = { | ||
subscribeTickSubscription(eventBus)(self) | ||
subscribeClockChannel(eventBus)(self) | ||
} | ||
|
||
override def postStop(): Unit = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,15 @@ | |
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
|
||
package org.powerapi.core | ||
|
||
import akka.actor.ActorRef | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
|
||
|
||
/** | ||
* Clock channel and messages. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
object ClockChannel extends Channel { | ||
|
||
|
@@ -47,15 +46,6 @@ object ClockChannel extends Channel { | |
frequency: FiniteDuration, | ||
timestamp: Long = System.currentTimeMillis) extends ClockMessage | ||
|
||
/** | ||
* ClockTickSubscription is represented as a dedicated type of message. | ||
* | ||
* @param topic: subject used for routing the message. | ||
* @param frequency: clock frequency. | ||
*/ | ||
case class ClockTickSubscription(topic: String, | ||
frequency: FiniteDuration) extends ClockMessage | ||
|
||
/** | ||
* ClockStart is represented as a dedicated type of message. | ||
* | ||
|
@@ -82,17 +72,17 @@ object ClockChannel extends Channel { | |
/** | ||
* Topic for communicating with the Clock. | ||
*/ | ||
private val topic = "tick:subscription" | ||
private val topic = "clock:handling" | ||
|
||
/** | ||
* External methods used by the Monitor actors to subscribe/unsubscribe, | ||
* start/stop a clock which runs at a frequency. | ||
*/ | ||
def subscribeClock(frequency: FiniteDuration): (MessageBus => ActorRef => Unit) = { | ||
def subscribeClockTick(frequency: FiniteDuration): MessageBus => ActorRef => Unit = { | ||
subscribe(clockTickTopic(frequency)) | ||
} | ||
|
||
def unsubscribeClock(frequency: FiniteDuration): MessageBus => ActorRef => Unit = { | ||
def unsubscribeClockTick(frequency: FiniteDuration): MessageBus => ActorRef => Unit = { | ||
unsubscribe(clockTickTopic(frequency)) | ||
} | ||
|
||
|
@@ -107,7 +97,7 @@ object ClockChannel extends Channel { | |
/** | ||
* Internal methods used by the Clocks actor for interacting with the bus. | ||
*/ | ||
def subscribeTickSubscription: MessageBus => ActorRef => Unit = { | ||
def subscribeClockChannel: MessageBus => ActorRef => Unit = { | ||
subscribe(topic) | ||
} | ||
|
||
|
@@ -116,7 +106,7 @@ object ClockChannel extends Channel { | |
/** | ||
* Internal methods used by the ClockChild actors for interacting with the bus. | ||
*/ | ||
def publishTick(frequency: FiniteDuration): MessageBus => Unit = { | ||
def publishClockTick(frequency: FiniteDuration): MessageBus => Unit = { | ||
publish(ClockTick(clockTickTopic(frequency), frequency)) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,19 @@ | |
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
|
||
package org.powerapi.core | ||
|
||
import akka.actor.{OneForOneStrategy, SupervisorStrategy, SupervisorStrategyConfigurator, ActorLogging, Actor} | ||
import akka.actor.SupervisorStrategy.{Directive, Resume} | ||
import akka.actor.{Actor, ActorLogging, OneForOneStrategy, SupervisorStrategy, SupervisorStrategyConfigurator} | ||
|
||
import akka.event.LoggingReceive | ||
import scala.concurrent.duration.DurationInt | ||
|
||
/** | ||
* Base trait for components which use Actor. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait Component extends Actor with ActorLogging { | ||
trait ActorComponent extends Actor with ActorLogging { | ||
/** | ||
* Default behavior when a received message is unknown. | ||
*/ | ||
|
@@ -40,10 +41,19 @@ trait Component extends Actor with ActorLogging { | |
} | ||
} | ||
|
||
/** | ||
* Base trait for API component. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait APIComponent extends ActorComponent | ||
|
||
/** | ||
* Supervisor strategy. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait Supervisor extends Component { | ||
trait Supervisor extends ActorComponent { | ||
def handleFailure: PartialFunction[Throwable, Directive] | ||
|
||
override def supervisorStrategy: SupervisorStrategy = | ||
|
@@ -53,6 +63,8 @@ trait Supervisor extends Component { | |
/** | ||
* This class is used for defining a default supervisor strategy for the Guardian Actor. | ||
* The Guardian Actor is the main actor used when system.actorOf(...) is used. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
class GuardianFailureStrategy extends SupervisorStrategyConfigurator { | ||
def handleFailure: PartialFunction[Throwable, Directive] = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,20 +24,23 @@ package org.powerapi.core | |
|
||
import com.typesafe.config.{Config, ConfigException, ConfigFactory} | ||
|
||
|
||
/** | ||
* Base trait for configuration result. | ||
*/ | ||
trait ConfigResult[T] | ||
|
||
/** | ||
* Subtypes to specify the different types of result. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
case class ConfigValue[T](value: T) extends ConfigResult[T] | ||
case class ConfigError[T](exception: Throwable) extends ConfigResult[T] | ||
|
||
/** | ||
* Base trait for dealing with configuration files. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait Configuration { | ||
private lazy val conf = ConfigFactory.load() | ||
|
@@ -47,7 +50,7 @@ trait Configuration { | |
* | ||
* @param request: request for getting information. | ||
*/ | ||
def load[T](request: Config => T): ConfigResult[T] = { | ||
protected def load[T](request: Config => T): ConfigResult[T] = { | ||
try { | ||
ConfigValue(request(conf)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* This software is licensed under the GNU Affero General Public License, quoted below. | ||
* | ||
* This file is a part of PowerAPI. | ||
* | ||
* Copyright (C) 2011-2014 Inria, University of Lille 1. | ||
* | ||
* PowerAPI is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PowerAPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with PowerAPI. | ||
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
package org.powerapi.core | ||
|
||
/** | ||
* Implement the Loan's pattern for closing automatically a resource. | ||
* | ||
* @see https://wiki.scala-lang.org/display/SYGN/Loan | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
object FileHelper { | ||
def using[A <: { def close(): Unit }, B](resource: A)(f: A => B): B = { | ||
try { | ||
f(resource) | ||
} | ||
finally { | ||
resource.close() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,16 @@ | |
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html. | ||
*/ | ||
|
||
package org.powerapi.core | ||
|
||
import java.util.UUID | ||
|
||
import akka.actor.ActorRef | ||
import akka.event.LookupClassification | ||
|
||
|
||
/** | ||
* Messages are the messages used to route the messages in the bus. | ||
* | ||
* @author Romain Rouvoy <[email protected]> | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait Message { | ||
/** | ||
|
@@ -40,15 +39,10 @@ trait Message { | |
} | ||
|
||
/** | ||
* Reports are the base messages exchanged between PowerAPI components. | ||
* Main types definition. | ||
* | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
trait Report extends Message { | ||
/** | ||
* A report is associated with a monitor unique identifier (MUID), which is at the origin of the report flow. | ||
*/ | ||
def muid: UUID | ||
} | ||
|
||
trait EventBus extends akka.event.EventBus { | ||
type Event = Message | ||
type Classifier = String | ||
|
@@ -57,6 +51,9 @@ trait EventBus extends akka.event.EventBus { | |
|
||
/** | ||
* Common event bus used by PowerAPI components to communicate. | ||
* | ||
* @author Loic Huertas <[email protected]> | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
class MessageBus extends EventBus with LookupClassification { | ||
// is used for extracting the classifier from the incoming events | ||
|
@@ -80,19 +77,22 @@ class MessageBus extends EventBus with LookupClassification { | |
|
||
/** | ||
* Used to specify the channels used by the components. | ||
* | ||
* @author Romain Rouvoy <[email protected]> | ||
* @author Maxime Colmant <[email protected]> | ||
*/ | ||
class Channel { | ||
type M <: Message | ||
|
||
def subscribe(topic: String)(bus: EventBus)(subscriber: ActorRef): Unit = { | ||
protected def subscribe(topic: String)(bus: EventBus)(subscriber: ActorRef): Unit = { | ||
bus.subscribe(subscriber, topic) | ||
} | ||
|
||
def unsubscribe(topic: String)(bus: EventBus)(subscriber: ActorRef): Unit = { | ||
protected def unsubscribe(topic: String)(bus: EventBus)(subscriber: ActorRef): Unit = { | ||
bus.unsubscribe(subscriber, topic) | ||
} | ||
|
||
def publish(message: M)(bus: EventBus): Unit = { | ||
protected def publish(message: M)(bus: EventBus): Unit = { | ||
bus.publish(message) | ||
} | ||
} |
Oops, something went wrong.