@@ -26,12 +26,11 @@ import java.lang.management.ManagementFactory
26
26
27
27
import org .powerapi .core .target .{Application , All , Process , Target }
28
28
import org .powerapi .module .rapl .RAPLModule
29
- import org .powerapi .module .sigar .SigarModule
30
29
import org .powerapi .reporter .{FileDisplay , JFreeChartDisplay , ConsoleDisplay }
31
30
import org .powerapi .{PowerMonitoring , PowerMeter }
32
31
import org .powerapi .core .power ._
33
32
import org .powerapi .module .cpu .dvfs .CpuDvfsModule
34
- import org .powerapi .module .cpu .simple .CpuSimpleModule
33
+ import org .powerapi .module .cpu .simple .{ SigarCpuSimpleModule , ProcFSCpuSimpleModule }
35
34
import org .powerapi .module .libpfm .{LibpfmHelper , LibpfmCoreProcessModule , LibpfmCoreModule }
36
35
import org .powerapi .module .powerspy .PowerSpyModule
37
36
import scala .concurrent .duration .DurationInt
@@ -45,7 +44,7 @@ import scala.sys.process.stringSeqToProcess
45
44
* @author <a href="mailto:[email protected] ">Loïc Huertas</a>
46
45
*/
47
46
object PowerAPI extends App {
48
- val modulesR = """ (cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-process|powerspy|rapl|sigar )(,(cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-process|powerspy|rapl|sigar ))*""" .r
47
+ val modulesR = """ (procfs- cpu-simple|sigar- cpu-simple|cpu- dvfs|libpfm-core|libpfm-core-process|powerspy|rapl)(,(procfs- cpu-simple|sigar- cpu-simple|cpu- dvfs|libpfm-core|libpfm-core-process|powerspy|rapl))*""" .r
49
48
val aggR = """ max|min|geomean|logsum|mean|median|stdev|sum|variance""" .r
50
49
val durationR = """ \d+""" .r
51
50
val pidR = """ (\d+)""" .r
@@ -111,14 +110,16 @@ object PowerAPI extends App {
111
110
"""
112
111
|PowerAPI, Spirals Team
113
112
|
114
- |Build a software-defined power meter. Do not forget to configure correctly the modules (see the documentation).
113
+ |Build a software-defined power meter. Do not forget to configure correctly the modules.
114
+ |You can use different settings per software-defined power meter for some modules by using the optional prefix option.
115
+ |Please, refer to the documentation inside the GitHub wiki for further details.
115
116
|
116
- |usage: ./powerapi modules [cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-proces|powerspy|rapl,...] \
117
+ |usage: ./powerapi modules [procfs- cpu-simple|sigar- cpu-simple|cpu- dvfs|libpfm-core|libpfm-core-proces|powerspy|rapl,...] *--prefix [name]* \
117
118
| monitor --frequency [ms] --targets [pid, ..., app, ...|all] --agg [max|min|geomean|logsum|mean|median|stdev|sum|variance] --[console,file [filepath],chart] \
118
119
| duration [s]
119
120
|
120
- |example: ./powerapi modules cpu-simple monitor --frequency 1000 --targets firefox --agg max --console monitor --targets chrome --agg max --console \
121
- | modules powerspy monitor --frequency 1000 --targets all --agg max --console \
121
+ |example: ./powerapi modules procfs- cpu-simple monitor --frequency 1000 --targets firefox, chrome --agg max --console \
122
+ | modules powerspy --prefix powermeter2 monitor --frequency 1000 --targets all --agg max --console \
122
123
| duration 30
123
124
""" .stripMargin
124
125
@@ -127,16 +128,21 @@ object PowerAPI extends App {
127
128
128
129
def cli (options : List [Map [Symbol , Any ]], duration : String , args : List [String ]): (List [Map [Symbol , Any ]], String ) = args match {
129
130
case Nil => (options, duration)
131
+ case " modules" :: value :: " --prefix" :: prefix :: " monitor" :: tail if validateModules(value) => {
132
+ val (remainingArgs, monitors) = cliMonitorsSubcommand(List (), Map (), tail.map(_.toString))
133
+ cli(options :+ Map (' modules -> value, ' prefix -> Some (prefix), ' monitors -> monitors), duration, remainingArgs)
134
+ }
130
135
case " modules" :: value :: " monitor" :: tail if validateModules(value) => {
131
136
val (remainingArgs, monitors) = cliMonitorsSubcommand(List (), Map (), tail.map(_.toString))
132
- cli(options :+ Map (' modules -> value, ' monitors -> monitors), duration, remainingArgs)
137
+ cli(options :+ Map (' modules -> value, ' prefix -> None , ' monitors -> monitors), duration, remainingArgs)
133
138
}
134
139
case " duration" :: value :: tail if validateDuration(value) => cli(options, value, tail)
135
140
case option :: tail => println(s " unknown cli option $option" ); sys.exit(1 )
136
141
}
137
142
138
143
def cliMonitorsSubcommand (options : List [Map [Symbol , Any ]], currentMonitor : Map [Symbol , Any ], args : List [String ]): (List [String ], List [Map [Symbol , Any ]]) = args match {
139
144
case Nil => (List (), options :+ currentMonitor)
145
+ case " modules" :: value :: " --prefix" :: prefix :: " monitor" :: tail if validateModules(value) => (List (" modules" , value, " --prefix" , prefix, " monitor" ) ++ tail, options :+ currentMonitor)
140
146
case " modules" :: value :: " monitor" :: tail if validateModules(value) => (List (" modules" , value, " monitor" ) ++ tail, options :+ currentMonitor)
141
147
case " duration" :: value :: tail if validateDuration(value) => (List (" duration" , value) ++ tail, options :+ currentMonitor)
142
148
case " monitor" :: tail => cliMonitorsSubcommand(options :+ currentMonitor, Map (), tail)
@@ -155,7 +161,7 @@ object PowerAPI extends App {
155
161
}
156
162
157
163
else {
158
- if (! System .getProperty(" os.name" ).startsWith( " Windows " ) ) Seq (" bash" , " scripts/system.bash" ).!
164
+ if (System .getProperty(" os.name" ).toLowerCase.indexOf( " nix " ) >= 0 || System .getProperty( " os.name " ).toLowerCase.indexOf( " nux " ) >= 0 ) Seq (" bash" , " scripts/system.bash" ).!
159
165
val (configuration, duration) = cli(List (), " 3600" , args.toList)
160
166
161
167
var libpfmHelper : Option [LibpfmHelper ] = None
@@ -166,17 +172,15 @@ object PowerAPI extends App {
166
172
}
167
173
168
174
for (powerMeterConf <- configuration) {
169
- val modulesStr = powerMeterConf(' modules ).toString
170
-
171
- val modules = (for (module <- modulesStr.split(" ," )) yield {
175
+ val modules = (for (module <- powerMeterConf(' modules ).toString.split(" ," )) yield {
172
176
module match {
173
- case " cpu-simple" => CpuSimpleModule ()
177
+ case " procfs-cpu-simple" => ProcFSCpuSimpleModule ()
178
+ case " sigar-cpu-simple" => SigarCpuSimpleModule ()
174
179
case " cpu-dvfs" => CpuDvfsModule ()
175
- case " libpfm-core" => LibpfmCoreModule (libpfmHelper.get)
176
- case " libpfm-core-process" => LibpfmCoreProcessModule (libpfmHelper.get)
180
+ case " libpfm-core" => LibpfmCoreModule (powerMeterConf( ' prefix ). asInstanceOf [ Option [ String ]], libpfmHelper.get)
181
+ case " libpfm-core-process" => LibpfmCoreProcessModule (powerMeterConf( ' prefix ). asInstanceOf [ Option [ String ]], libpfmHelper.get)
177
182
case " powerspy" => PowerSpyModule ()
178
183
case " rapl" => RAPLModule ()
179
- case " sigar" => SigarModule ()
180
184
}
181
185
}).toSeq
182
186
0 commit comments