Commit 40f7f67f authored by Noric Couderc's avatar Noric Couderc
Browse files

Implemented auto checking of counters

When you create a PAPI counter, it will check that this counter is
available on the machine!

That probably means you should create too many counters, but you
probably don't need to.
parent 00b4cb3a
package se.lth.cs.papicounters
import papi.EventSet
import papi.Papi
import papi.PapiException
import se.lth.cs.CounterSpecification
import se.lth.cs.util.Feature
import se.lth.cs.util.FeatureVisitor
import java.lang.RuntimeException
class PAPICounter(val counter : String) : Feature() {
init {
check()
}
fun isValid(): Boolean {
return CounterSpecification.allCounters.contains(counter)
}
fun check() {
Papi.init()
try {
val eventSet = EventSet.create(this.toPAPIConstant()!!)
// eventSet.start()
// var x = 0
// // Some random crap
// for (i in 0 until 10) {
// x += x * 2 - 3
// }
// eventSet.stop()
// eventSet.destroy()
} catch (e : PapiException) {
val msg = "Creating eventSet for single counter '%s' failed: is it available on this machine?"
.format(counter)
throw RuntimeException(msg)
}
}
// You could also output it in different formats
override fun toString(): String {
if (isValid()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment