@@ -65,7 +65,7 @@ object PowerAPI extends App {
6565 powerMeters = Seq ()
6666 }
6767
68- def validate (regex : Regex , str : String ) = str match {
68+ def validate (regex : Regex , str : String ): Boolean = str match {
6969 case regex(_* ) => true
7070 case _ => false
7171 }
@@ -125,7 +125,8 @@ object PowerAPI extends App {
125125 sys.exit(1 )
126126 }
127127
128- def cliMonitorsSubcommand (options : List [Map [Symbol , Any ]], currentMonitor : Map [Symbol , Any ], args : List [String ]): (List [String ], List [Map [Symbol , Any ]]) = args match {
128+ def cliMonitorsSubcommand (options : List [Map [Symbol , Any ]], currentMonitor : Map [Symbol , Any ],
129+ args : List [String ]): (List [String ], List [Map [Symbol , Any ]]) = args match {
129130 case Nil =>
130131 (List (), options :+ currentMonitor)
131132 case " modules" :: value :: " --prefix" :: prefix :: " monitor" :: tail if validate(modulesR, value) =>
@@ -139,25 +140,45 @@ object PowerAPI extends App {
139140 case " --frequency" :: value :: tail if validate(durationR, value) =>
140141 cliMonitorsSubcommand(options, currentMonitor ++ Map (' frequency -> value), tail)
141142 case " --self" :: tail =>
142- cliMonitorsSubcommand(options, currentMonitor + (' targets -> (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] + Process (ManagementFactory .getRuntimeMXBean.getName.split(" @" )(0 ).toInt))), tail)
143+ cliMonitorsSubcommand(options,
144+ currentMonitor + (' targets ->
145+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] + Process (ManagementFactory .getRuntimeMXBean.getName.split(" @" )(0 ).toInt))
146+ ), tail)
143147 case " --pids" :: value :: tail if validate(pidsR, value) =>
144- cliMonitorsSubcommand(options, currentMonitor + (' targets -> (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(pid => Process (pid.toInt)))), tail)
148+ cliMonitorsSubcommand(options,
149+ currentMonitor + (' targets ->
150+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(pid => Process (pid.toInt)))
151+ ), tail)
145152 case " --apps" :: value :: tail if validate(appsR, value) =>
146- cliMonitorsSubcommand(options, currentMonitor + (' targets -> (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(app => Application (app)))), tail)
153+ cliMonitorsSubcommand(options, currentMonitor + (' targets ->
154+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(app => Application (app)))
155+ ), tail)
147156 case " --containers" :: value :: tail if validate(containersR, value) =>
148- cliMonitorsSubcommand(options, currentMonitor + (' targets -> (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(container => Container (container)))), tail)
157+ cliMonitorsSubcommand(options, currentMonitor + (' targets ->
158+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(container => Container (container)))
159+ ), tail)
149160 case " --all" :: tail =>
150- cliMonitorsSubcommand(options, currentMonitor + (' targets -> (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] + All )), tail)
161+ cliMonitorsSubcommand(options, currentMonitor + (' targets ->
162+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] + All )
163+ ), tail)
151164 case " --agg" :: value :: tail if validate(aggR, value) =>
152165 cliMonitorsSubcommand(options, currentMonitor ++ Map (' agg -> value), tail)
153166 case " --console" :: tail =>
154- cliMonitorsSubcommand(options, currentMonitor + (' displays -> (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new ConsoleDisplay )), tail)
167+ cliMonitorsSubcommand(options, currentMonitor + (' displays ->
168+ (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new ConsoleDisplay )
169+ ), tail)
155170 case " --file" :: value :: tail =>
156- cliMonitorsSubcommand(options, currentMonitor + (' displays -> (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new FileDisplay (value))), tail)
171+ cliMonitorsSubcommand(options, currentMonitor + (' displays ->
172+ (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new FileDisplay (value))
173+ ), tail)
157174 case " --chart" :: tail =>
158- cliMonitorsSubcommand(options, currentMonitor + (' displays -> (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new JFreeChartDisplay )), tail)
175+ cliMonitorsSubcommand(options, currentMonitor + (' displays ->
176+ (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new JFreeChartDisplay )
177+ ), tail)
159178 case " --influx" :: host :: user :: pwd :: db :: measurement :: tail =>
160- cliMonitorsSubcommand(options, currentMonitor + (' displays -> (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new InfluxDisplay (host, user, pwd, db, measurement))), tail)
179+ cliMonitorsSubcommand(options, currentMonitor + (' displays ->
180+ (currentMonitor.getOrElse(' displays , Set [Any ]()).asInstanceOf [Set [Any ]] + new InfluxDisplay (host, user, pwd, db, measurement))
181+ ), tail)
161182 case option :: tail =>
162183 println(s " unknown monitor option $option" )
163184 sys.exit(1 )
@@ -169,8 +190,9 @@ object PowerAPI extends App {
169190 }
170191
171192 else {
172- if (System .getProperty(" os.name" ).toLowerCase.indexOf(" nix" ) >= 0 || System .getProperty(" os.name" ).toLowerCase.indexOf(" nux" ) >= 0 ) Seq (" bash" , " scripts/system.bash" ).!
173-
193+ if (System .getProperty(" os.name" ).toLowerCase.indexOf(" nix" ) >= 0 || System .getProperty(" os.name" ).toLowerCase.indexOf(" nux" ) >= 0 ) {
194+ Seq (" bash" , " scripts/system.bash" ).!
195+ }
174196 val (configuration, duration) = cli(List (), " 3600" , args.toList)
175197
176198 var libpfmHelper : Option [LibpfmHelper ] = None
0 commit comments