(SIGAR-207) Add Pdh.getCounterType method
This commit is contained in:
		
							parent
							
								
									7905904cb6
								
							
						
					
					
						commit
						2dc981dfa8
					
				@ -254,6 +254,23 @@ JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhGetDescription)
 | 
			
		||||
    return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jlong SIGAR_JNI(win32_Pdh_pdhGetCounterType)
 | 
			
		||||
(JNIEnv *env, jclass cur, jlong counter)
 | 
			
		||||
{
 | 
			
		||||
    HCOUNTER h_counter = (HCOUNTER)counter;
 | 
			
		||||
    PDH_COUNTER_INFO info;
 | 
			
		||||
    DWORD size = sizeof(info);
 | 
			
		||||
    PDH_STATUS status;
 | 
			
		||||
 | 
			
		||||
    status = PdhGetCounterInfo(h_counter, FALSE, &size, &info);
 | 
			
		||||
    if (status != ERROR_SUCCESS) {
 | 
			
		||||
        win32_throw_exception(env, get_error_message(status));
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return info.dwType;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetInstances)
 | 
			
		||||
(JNIEnv *env, jclass cur, jstring cp)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -63,6 +63,15 @@ public class Pdh extends Win32 {
 | 
			
		||||
    public static final String PERFLIB_KEY =
 | 
			
		||||
        "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib";
 | 
			
		||||
 | 
			
		||||
    //see winperf.h
 | 
			
		||||
    public static final long PERF_TYPE_NUMBER  = 0x00000000; // a number (not a counter)
 | 
			
		||||
 | 
			
		||||
    public static final long PERF_TYPE_COUNTER = 0x00000400; // an increasing numeric value
 | 
			
		||||
 | 
			
		||||
    public static final long PERF_TYPE_TEXT    = 0x00000800; // a text field
 | 
			
		||||
 | 
			
		||||
    public static final long PERF_TYPE_ZERO    = 0x00000C00; // displays a zero
 | 
			
		||||
 | 
			
		||||
    private long   query = -1l; // Handle to the query
 | 
			
		||||
    private String hostname = null;
 | 
			
		||||
    private static Map counters = null;
 | 
			
		||||
@ -303,6 +312,16 @@ public class Pdh extends Win32 {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getCounterType(String path) throws Win32Exception {
 | 
			
		||||
        long counter =
 | 
			
		||||
            pdhAddCounter(this.query, translate(path));
 | 
			
		||||
        try {
 | 
			
		||||
            return pdhGetCounterType(counter);
 | 
			
		||||
        } finally {
 | 
			
		||||
            pdhRemoveCounter(counter);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String[] getInstances(String path) throws Win32Exception {
 | 
			
		||||
        return pdhGetInstances(getCounterName(path));
 | 
			
		||||
    }
 | 
			
		||||
@ -332,6 +351,8 @@ public class Pdh extends Win32 {
 | 
			
		||||
        throws Win32Exception;
 | 
			
		||||
    private static final native String pdhGetDescription(long counter)
 | 
			
		||||
        throws Win32Exception;
 | 
			
		||||
    private static final native long pdhGetCounterType(long counter)
 | 
			
		||||
        throws Win32Exception;
 | 
			
		||||
    private static final native String[] pdhGetInstances(String path)
 | 
			
		||||
        throws Win32Exception;
 | 
			
		||||
    private static final native String[] pdhGetKeys(String path)
 | 
			
		||||
 | 
			
		||||
@ -30,10 +30,15 @@ public class TestPdh extends SigarTestCase {
 | 
			
		||||
        super(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static boolean isCounter(long type) {
 | 
			
		||||
        return (type & Pdh.PERF_TYPE_COUNTER) == Pdh.PERF_TYPE_COUNTER;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void getValue(String key) throws Exception {
 | 
			
		||||
        Pdh pdh = new Pdh();
 | 
			
		||||
 | 
			
		||||
        traceln(key + ": " + pdh.getDescription(key));
 | 
			
		||||
        traceln("counter=" + isCounter(pdh.getCounterType(key)));
 | 
			
		||||
        assertGtEqZeroTrace("raw",
 | 
			
		||||
                            (long)pdh.getRawValue(key));
 | 
			
		||||
        assertGtEqZeroTrace("fmt",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user