JNIEXPORT jobject JNICALL Java_org_krakenapps_winapi_PerformanceCounter_getCounters(JNIEnv *env, jobject obj, jstring category, jstring machine, jint detail) { jclass clzHashMap = (*env)->FindClass(env, "java/util/HashMap"); jmethodID hashMapInit = (*env)->GetMethodID(env, clzHashMap, "<init>", "()V"); jmethodID hashMapPut = (*env)->GetMethodID(env, clzHashMap, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); jobject counter = NULL; LPTSTR categoryName = (LPTSTR)(*env)->GetStringChars(env, category, JNI_FALSE); LPTSTR machineName = machine ? (LPTSTR)(*env)->GetStringChars(env, machine, JNI_FALSE) : NULL; jobjectArray counters = NULL; jobjectArray instances = NULL; LPTSTR lpCounterList = NULL; DWORD dwCounterListLength = 0; LPTSTR lpInstanceList = NULL; DWORD dwInstanceListLength = 0; DWORD stat = 0; if(machineName) { stat = PdhConnectMachine(machineName); if(stat != ERROR_SUCCESS) { fprintf(stderr, "Error in PdhConnectMachine:, 0x%x\n", stat); if(machineName) (*env)->ReleaseStringChars(env, machine, machineName); return NULL; } } PdhEnumObjectItems(NULL, machineName, categoryName, NULL, &dwCounterListLength, NULL, &dwInstanceListLength, detail, 0); lpCounterList = (LPTSTR)malloc(sizeof(TCHAR)*dwCounterListLength); lpInstanceList = (LPTSTR)malloc(sizeof(TCHAR)*dwInstanceListLength); stat = PdhEnumObjectItems(NULL, machineName, categoryName, lpCounterList, &dwCounterListLength, lpInstanceList, &dwInstanceListLength, detail, 0); (*env)->ReleaseStringChars(env, category, categoryName); if(machineName) (*env)->ReleaseStringChars(env, machine, machineName); if(stat != ERROR_SUCCESS) { fprintf(stderr, "Error in PdhEnumObjectItems\n"); return NULL; } counter = counter = (*env)->NewObject(env, clzHashMap, hashMapInit); counters = convertStringArray(env, lpCounterList, dwCounterListLength); instances = convertStringArray(env, lpInstanceList, dwInstanceListLength); free(lpCounterList); free(lpInstanceList); (*env)->CallObjectMethod(env, counter, hashMapPut, (*env)->NewStringUTF(env, "counters"), counters); (*env)->CallObjectMethod(env, counter, hashMapPut, (*env)->NewStringUTF(env, "instances"), instances); return counter; }
JNIEXPORT jobjectArray JNICALL Java_org_krakenapps_winapi_PerformanceCounter_getMachines(JNIEnv *env, jobject obj) { jobjectArray machineList = NULL; LPTSTR lpMachineNameList = NULL; DWORD dwBufferLength = 0; PDH_STATUS stat = 0; PdhEnumMachines(NULL, NULL, &dwBufferLength); if(dwBufferLength == 0) { fprintf(stderr, "Error in PdhEnumMachines\n"); return NULL; } lpMachineNameList = (LPTSTR)malloc(sizeof(TCHAR)*dwBufferLength); stat = PdhEnumMachines(NULL, lpMachineNameList, &dwBufferLength); if(stat != ERROR_SUCCESS) { fprintf(stderr, "Error in PdhEnumMachines: 0x%x\n", stat); return NULL; } machineList = convertStringArray(env, lpMachineNameList, dwBufferLength); free(lpMachineNameList); return machineList; }
/* * static String[] getVmFeatureList() * * Return a set of strings describing available VM features (this is chiefly * of interest to DDMS). Some features may be controlled by compile-time * or command-line flags. */ static void Dalvik_dalvik_system_VMDebug_getVmFeatureList(const u4* args, JValue* pResult) { static const int MAX_FEATURE_COUNT = 10; char* features[MAX_FEATURE_COUNT]; int idx = 0; /* VM responds to DDMS method profiling requests */ features[idx++] = "method-trace-profiling"; features[idx++] = "method-trace-profiling-streaming"; #ifdef WITH_HPROF /* VM responds to DDMS heap dump requests */ features[idx++] = "hprof-heap-dump"; features[idx++] = "hprof-heap-dump-streaming"; #endif assert(idx <= MAX_FEATURE_COUNT); LOGV("+++ sending up %d features\n", idx); ArrayObject* arrayObj = convertStringArray(features, idx); RETURN_PTR(arrayObj); /* will be null on OOM */ }
JNIEXPORT jobjectArray JNICALL Java_org_krakenapps_winapi_PerformanceCounter_getCategories(JNIEnv *env, jobject obj, jstring machine, jint detail) { jobjectArray categoryList = NULL; LPTSTR machineName = machine ? (LPTSTR)(*env)->GetStringChars(env, machine, JNI_FALSE) : NULL; LPTSTR lpCategoryNameList = NULL; DWORD dwBufferLength = 0; PDH_STATUS stat = 0; if(machineName) { stat = PdhConnectMachine(machineName); if(stat != ERROR_SUCCESS) { fprintf(stderr, "Error in PdhConnectMachine:, 0x%x\n", stat); if(machineName) (*env)->ReleaseStringChars(env, machine, machineName); return NULL; } } PdhEnumObjects(NULL, machineName, NULL, &dwBufferLength, detail, TRUE); if(dwBufferLength == 0) { fprintf(stderr, "Error in PdhEnumObjects\n"); return NULL; } lpCategoryNameList = (LPTSTR)malloc(sizeof(TCHAR)*dwBufferLength); stat = PdhEnumObjects(NULL, machineName, lpCategoryNameList, &dwBufferLength, detail, TRUE); if(stat != ERROR_SUCCESS) { fprintf(stderr, "Error in PdhEnumObjects: 0x%x\n", stat); return NULL; } if(machineName) (*env)->ReleaseStringChars(env, machine, machineName); categoryList = convertStringArray(env, lpCategoryNameList, dwBufferLength); free(lpCategoryNameList); return categoryList; }