I am trying to call the PCM library version 1.7 from java using JNI. The idea is simply as following:
1. Call the PCM to get BaiscCounterType(CoreCounter, Socketcounter,SystemCounter)
2. Run some Java Code
3. Call the PCM again to get the BasicCounter
4. Call the PCM to measure the diffrence. (getCyclesLostDueL2CacheMisses,getCyclesLostDueL3CacheMisses)
Now, the problem is that I get the same BasicCounterType in step 1 and 3 which causes invalid results in step 4.
The JNI C++ code methods are as following:
1. Here is the method I use to get the BasicCounterType (CoreCounter). This method calls the getSystemCounterState() in cpucounters.cpp. Please note that I return the pointer address of the counter only.
JNIEXPORT jlong JNICALL Java_org_jpcm_JpcmJNI_getSystemCounterState
(JNIEnv *, jobject)
2. Then after executing some java code, the same method is invoked again to get the counter reading after that.
3. The two long values (Pointers for Before & After) are passed to the following method to get the L3 cach miss
JNIEXPORT jdouble JNICALL Java_org_jpcm_JpcmJNI_getCyclesLostDueL3CacheMisses
(JNIEnv *, jobject, jlong before, jlong after)
stateAfter = (BasicCounterState*)after;
The problem is that I get the same CoreCounter each time I call the PCM. By the wrod Same, I mean that I get the same Pointer Address Value (long) each time.
Any ideas how to solve that.