Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Noric Couderc
JBrainy
Commits
c7e894de
Commit
c7e894de
authored
Nov 20, 2021
by
Noric Couderc
Browse files
Refactoring: Automatically build eventSet
No need to manually call "accept" on the features, that's kinda ugly
parent
b8261e9f
Changes
4
Show whitespace changes
Inline
Side-by-side
core/src/main/kotlin/se/lth/cs/papicounters/EventSetBuilder.kt
View file @
c7e894de
package
se.lth.cs.papicounters
package
se.lth.cs.papicounters
import
papi.EventSet
import
papi.EventSet
import
papi.Papi
import
se.lth.cs.util.*
import
se.lth.cs.util.*
import
java.lang.RuntimeException
/**
/**
* Creates an eventSet from a FeatureSet
* Creates an eventSet from a FeatureSet
*/
*/
class
EventSetBuilder
:
FeatureVisitor
{
class
EventSetBuilder
(
val
features
:
FeatureSet
)
:
FeatureVisitor
{
private
var
counterSet
:
LinkedHashSet
<
PAPICounter
>
=
java
.
util
.
LinkedHashSet
()
private
var
counterSet
:
LinkedHashSet
<
PAPICounter
>
=
java
.
util
.
LinkedHashSet
()
init
{
features
.
accept
(
this
)
}
override
fun
visitPAPICounter
(
c
:
PAPICounter
)
{
override
fun
visitPAPICounter
(
c
:
PAPICounter
)
{
// If the counter is de-activated we skip it
// If the counter is de-activated we skip it
if
(!
c
.
isSupported
())
{
if
(!
c
.
isSupported
())
{
...
...
core/src/main/kotlin/se/lth/cs/papicounters/PapiBenchmarkAnalyzer.kt
View file @
c7e894de
...
@@ -11,10 +11,10 @@ interface PapiBenchmarkAnalyzer {
...
@@ -11,10 +11,10 @@ interface PapiBenchmarkAnalyzer {
val
features
:
FeatureSet
,
val
features
:
FeatureSet
,
val
syntheticBenchmark
:
BCBenchmarkPackage
<
*
>)
{
val
syntheticBenchmark
:
BCBenchmarkPackage
<
*
>)
{
val
eventSetBuilder
=
EventSetBuilder
(
features
)
fun
eventSet
():
EventSet
{
fun
eventSet
():
EventSet
{
val
eb
=
EventSetBuilder
()
return
eventSetBuilder
.
getEventSet
()
features
.
accept
(
eb
)
return
eb
.
getEventSet
()
}
}
/**
/**
...
@@ -26,9 +26,7 @@ interface PapiBenchmarkAnalyzer {
...
@@ -26,9 +26,7 @@ interface PapiBenchmarkAnalyzer {
}
}
fun
counters
()
:
List
<
PAPICounter
>
{
fun
counters
()
:
List
<
PAPICounter
>
{
val
eb
=
EventSetBuilder
()
return
eventSetBuilder
.
getCounterSet
().
toList
()
features
.
accept
(
eb
)
return
eb
.
getCounterSet
().
toList
()
}
}
}
}
...
...
core/src/main/kotlin/se/lth/cs/papicounters/PapiRunner.kt
View file @
c7e894de
...
@@ -27,8 +27,7 @@ open class PapiRunner() : PapiBenchmarkAnalyzer {
...
@@ -27,8 +27,7 @@ open class PapiRunner() : PapiBenchmarkAnalyzer {
// For each counter,
// For each counter,
// we store the values for each run (10 runs)
// we store the values for each run (10 runs)
var
data
:
MutableMap
<
PAPICounter
,
List
<
Long
>>
=
mutableMapOf
()
var
data
:
MutableMap
<
PAPICounter
,
List
<
Long
>>
=
mutableMapOf
()
val
eb
=
EventSetBuilder
()
val
eb
=
EventSetBuilder
(
counters
)
counters
.
accept
(
eb
)
for
(
counter
in
eb
.
getCounterSet
())
{
for
(
counter
in
eb
.
getCounterSet
())
{
val
evset
=
eb
.
getEventSet
()
val
evset
=
eb
.
getEventSet
()
...
...
core/src/test/kotlin/EventSetBuilderTest.kt
View file @
c7e894de
...
@@ -37,8 +37,7 @@ class EventSetBuilderTest {
...
@@ -37,8 +37,7 @@ class EventSetBuilderTest {
val
spec
=
FeatureSet
(*
counters
.
toTypedArray
())
val
spec
=
FeatureSet
(*
counters
.
toTypedArray
())
val
builder
=
EventSetBuilder
()
val
builder
=
EventSetBuilder
(
spec
)
spec
.
accept
(
builder
)
Assertions
.
assertEquals
(
counters
.
toSet
(),
builder
.
getCounterSet
())
Assertions
.
assertEquals
(
counters
.
toSet
(),
builder
.
getCounterSet
())
}
}
...
@@ -52,8 +51,7 @@ class EventSetBuilderTest {
...
@@ -52,8 +51,7 @@ class EventSetBuilderTest {
val
spec
=
FeatureSet
(*
features
)
val
spec
=
FeatureSet
(*
features
)
val
builder
=
EventSetBuilder
()
val
builder
=
EventSetBuilder
(
spec
)
spec
.
accept
(
builder
)
val
expected
=
setOf
(
val
expected
=
setOf
(
PAPICounter
(
"PAPI_TOT_CYC"
),
// For Costs!
PAPICounter
(
"PAPI_TOT_CYC"
),
// For Costs!
...
@@ -80,8 +78,7 @@ class EventSetBuilderTest {
...
@@ -80,8 +78,7 @@ class EventSetBuilderTest {
val
spec
=
FeatureSet
(*
features
)
val
spec
=
FeatureSet
(*
features
)
val
builder
=
EventSetBuilder
()
val
builder
=
EventSetBuilder
(
spec
)
spec
.
accept
(
builder
)
val
expected
=
listOf
(
val
expected
=
listOf
(
PAPICounter
(
"PAPI_L2_DCM"
),
PAPICounter
(
"PAPI_L2_DCM"
),
...
@@ -95,14 +92,9 @@ class EventSetBuilderTest {
...
@@ -95,14 +92,9 @@ class EventSetBuilderTest {
// @Disabled("PAPI_L1_DCA is not available on the machine")
// @Disabled("PAPI_L1_DCA is not available on the machine")
@Test
@Test
fun
testEventBuildInvalidEvents
()
{
fun
testEventBuildInvalidEvents
()
{
val
features
=
listOf
(
val
spec
=
FeatureSet
()
PAPICounter
(
"PAPI_L1_DCM"
),
PAPICounter
(
"PAPI_L1_DCA"
)).
toTypedArray
()
val
spec
=
FeatureSet
(*
features
)
// Oh no! empty list of PAPI events!
// Oh no! empty list of PAPI events!
val
builder
=
EventSetBuilder
()
val
builder
=
EventSetBuilder
(
spec
)
Assertions
.
assertThrows
(
RuntimeException
::
class
.
java
)
{
spec
.
accept
(
builder
)
}
Assertions
.
assertThrows
(
RuntimeException
::
class
.
java
)
{
spec
.
accept
(
builder
)
}
}
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment