add PdhLookupPerfNameByIndex wrapper
This commit is contained in:
		
							parent
							
								
									36bd793822
								
							
						
					
					
						commit
						9dae5e1ab1
					
				@ -401,6 +401,23 @@ JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetObjects)
 | 
				
			|||||||
    return array;
 | 
					    return array;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhLookupPerfName)
 | 
				
			||||||
 | 
					(JNIEnv *env, jclass cur, jint index)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    TCHAR path[8192];
 | 
				
			||||||
 | 
					    DWORD len = sizeof(path);
 | 
				
			||||||
 | 
					    PDH_STATUS status =
 | 
				
			||||||
 | 
					        PdhLookupPerfNameByIndex(NULL, index, path, &len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (status == ERROR_SUCCESS) {
 | 
				
			||||||
 | 
					        return JENV->NewStringUTF(env, path);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        win32_throw_exception(env, get_error_message(status));
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -101,6 +101,12 @@ public class Pdh extends Win32 {
 | 
				
			|||||||
        return counters.map;
 | 
					        return counters.map;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static String getCounterName(int index)
 | 
				
			||||||
 | 
					        throws Win32Exception {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return pdhLookupPerfName(index);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @deprecated
 | 
					     * @deprecated
 | 
				
			||||||
     * @see #getRawValue(String path)
 | 
					     * @see #getRawValue(String path)
 | 
				
			||||||
@ -163,6 +169,8 @@ public class Pdh extends Win32 {
 | 
				
			|||||||
        throws Win32Exception;
 | 
					        throws Win32Exception;
 | 
				
			||||||
    private static final native String[] pdhGetObjects()
 | 
					    private static final native String[] pdhGetObjects()
 | 
				
			||||||
        throws Win32Exception;
 | 
					        throws Win32Exception;
 | 
				
			||||||
 | 
					    private static final native String pdhLookupPerfName(int index)
 | 
				
			||||||
 | 
					        throws Win32Exception;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Main method for dumping the entire PDH
 | 
					     * Main method for dumping the entire PDH
 | 
				
			||||||
 | 
				
			|||||||
@ -68,10 +68,14 @@ public class TestPdh extends SigarTestCase {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        String last = null;
 | 
					        String last = null;
 | 
				
			||||||
        for (int i=0; i<keys.length; i++) {
 | 
					        for (int i=0; i<keys.length; i++) {
 | 
				
			||||||
            String index = (String)counters.get(keys[i]);
 | 
					            String name = keys[i];
 | 
				
			||||||
 | 
					            String index = (String)counters.get(name);
 | 
				
			||||||
            assertFalse(index.equals(last));
 | 
					            assertFalse(index.equals(last));
 | 
				
			||||||
            traceln(keys[i] + "=" + index);
 | 
					            traceln(name + "=" + index);
 | 
				
			||||||
            last = index;
 | 
					            last = index;
 | 
				
			||||||
 | 
					            String lookupName =
 | 
				
			||||||
 | 
					                Pdh.getCounterName(Integer.parseInt(index));
 | 
				
			||||||
 | 
					            traceln(name + "=" + lookupName);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user