From 853aa65cc4cf4e8ee08b275d7e6f03c63ae560f0 Mon Sep 17 00:00:00 2001 From: Zhen Tang Date: Mon, 15 Jul 2013 15:06:56 +0800 Subject: [PATCH] windows monitor completed. --- .gitignore | 2 +- WindowsMonitor/Native/Native.vcxproj | 2 + WindowsMonitor/Native/Native.vcxproj.filters | 6 + WindowsMonitor/Native/ProcessorMonitor.cpp | 158 +++++++++++++++++++ WindowsMonitor/Native/ProcessorMonitor.h | 149 +++++++++++++++++ src/main/java/org/bench4q/monitor/Main.java | 20 ++- 6 files changed, 333 insertions(+), 4 deletions(-) create mode 100644 WindowsMonitor/Native/ProcessorMonitor.cpp create mode 100644 WindowsMonitor/Native/ProcessorMonitor.h diff --git a/.gitignore b/.gitignore index 2d8d1743..49f3cbee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -.settings .project .classpath +/.settings /target /WindowsMonitor/Debug /WindowsMonitor/Release diff --git a/WindowsMonitor/Native/Native.vcxproj b/WindowsMonitor/Native/Native.vcxproj index d2c40438..77f5094a 100644 --- a/WindowsMonitor/Native/Native.vcxproj +++ b/WindowsMonitor/Native/Native.vcxproj @@ -155,6 +155,7 @@ + @@ -183,6 +184,7 @@ + Create Create diff --git a/WindowsMonitor/Native/Native.vcxproj.filters b/WindowsMonitor/Native/Native.vcxproj.filters index ac8f44e3..3f4a1575 100644 --- a/WindowsMonitor/Native/Native.vcxproj.filters +++ b/WindowsMonitor/Native/Native.vcxproj.filters @@ -57,6 +57,9 @@ 头文件 + + 头文件 + @@ -98,5 +101,8 @@ 源文件 + + 源文件 + \ No newline at end of file diff --git a/WindowsMonitor/Native/ProcessorMonitor.cpp b/WindowsMonitor/Native/ProcessorMonitor.cpp new file mode 100644 index 00000000..621c323d --- /dev/null +++ b/WindowsMonitor/Native/ProcessorMonitor.cpp @@ -0,0 +1,158 @@ +#include "stdafx.h" +#include "ProcessorMonitor.h" +#include "Common.h" + +JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInstances + (JNIEnv * environment, jobject object) +{ + list instances=Processor::GetInstances(); + list::iterator iter; + long count=(long)instances.size(); + jobjectArray array=environment->NewObjectArray( + count,environment->FindClass("java/lang/String"),environment->NewStringUTF("")); + int i=0; + for(iter=instances.begin();iter!=instances.end();iter++) + { + environment->SetObjectArrayElement(array,i + ,environment->NewStringUTF(GetUTF8String((*iter).c_str()))); + i++; + } + return array; +} + +JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getCounterList + (JNIEnv * environment, jobject object) +{ + list counterList=Processor::GetCounterList(); + list::iterator iter; + long count=(long)counterList.size(); + jobjectArray array=environment->NewObjectArray( + count,environment->FindClass("java/lang/String"),environment->NewStringUTF("")); + int i=0; + for(iter=counterList.begin();iter!=counterList.end();iter++) + { + environment->SetObjectArrayElement(array,i + ,environment->NewStringUTF(GetUTF8String((*iter).c_str()))); + i++; + } + return array; +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getProcessorTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetProcessorTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getUserTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetUserTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getPrivilegedTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetPrivilegedTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInterruptsPerSecond + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetInterruptsPerSecond( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetDpcTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInterruptTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetInterruptTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcsQueuedPerSecond + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetDpcsQueuedPerSecond( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcRate + (JNIEnv * environment, jobject object, jstring instanceName) +{ + return Processor::GetDpcRate( + Common::StringToWideString(GetJString(environment,instanceName)).c_str()); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getIdleTimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetIdleTimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC1TimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC1TimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC2TimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC2TimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC3TimePercent + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC3TimePercent( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC1TransitionsPerSecond + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC1TransitionsPerSecond( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC2TransitionsPerSecond + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC2TransitionsPerSecond( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} + +JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC3TransitionsPerSecond + (JNIEnv * environment, jobject object, jstring instanceName, jint idleTime) +{ + return Processor::GetC3TransitionsPerSecond( + Common::StringToWideString(GetJString(environment,instanceName)).c_str() + ,idleTime); +} \ No newline at end of file diff --git a/WindowsMonitor/Native/ProcessorMonitor.h b/WindowsMonitor/Native/ProcessorMonitor.h new file mode 100644 index 00000000..57886074 --- /dev/null +++ b/WindowsMonitor/Native/ProcessorMonitor.h @@ -0,0 +1,149 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_bench4q_monitor_performance_windows_ProcessorMonitor */ + +#ifndef _Included_org_bench4q_monitor_performance_windows_ProcessorMonitor +#define _Included_org_bench4q_monitor_performance_windows_ProcessorMonitor +#ifdef __cplusplus +extern "C" { +#endif + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getInstances + * Signature: ()[Ljava/lang/String; + */ + JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInstances + (JNIEnv *, jobject); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getCounterList + * Signature: ()[Ljava/lang/String; + */ + JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getCounterList + (JNIEnv *, jobject); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getProcessorTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getProcessorTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getUserTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getUserTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getPrivilegedTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getPrivilegedTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getInterruptsPerSecond + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInterruptsPerSecond + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getDpcTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getInterruptTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getInterruptTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getDpcsQueuedPerSecond + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcsQueuedPerSecond + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getDpcRate + * Signature: (Ljava/lang/String;)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getDpcRate + (JNIEnv *, jobject, jstring); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getIdleTimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getIdleTimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC1TimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC1TimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC2TimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC2TimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC3TimePercent + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC3TimePercent + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC1TransitionsPerSecond + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC1TransitionsPerSecond + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC2TransitionsPerSecond + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC2TransitionsPerSecond + (JNIEnv *, jobject, jstring, jint); + + /* + * Class: org_bench4q_monitor_performance_windows_ProcessorMonitor + * Method: getC3TransitionsPerSecond + * Signature: (Ljava/lang/String;I)D + */ + JNIEXPORT jdouble JNICALL Java_org_bench4q_monitor_performance_windows_ProcessorMonitor_getC3TransitionsPerSecond + (JNIEnv *, jobject, jstring, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/main/java/org/bench4q/monitor/Main.java b/src/main/java/org/bench4q/monitor/Main.java index 3c35b77d..86298811 100644 --- a/src/main/java/org/bench4q/monitor/Main.java +++ b/src/main/java/org/bench4q/monitor/Main.java @@ -8,6 +8,7 @@ import org.bench4q.monitor.performance.windows.NetworkInterfaceMonitor; import org.bench4q.monitor.performance.windows.PhysicalDiskMonitor; import org.bench4q.monitor.performance.windows.ProcessMonitor; import org.bench4q.monitor.performance.windows.ProcessorInformationMonitor; +import org.bench4q.monitor.performance.windows.ProcessorMonitor; import org.bench4q.monitor.performance.windows.TCPv4Monitor; import org.bench4q.monitor.performance.windows.TCPv6Monitor; import org.bench4q.monitor.performance.windows.UDPv4Monitor; @@ -113,18 +114,31 @@ public class Main { for (String elem : processCounter) { System.out.println(elem); } - + ProcessorInformationMonitor processorInformationMonitor = new ProcessorInformationMonitor(); - String[] processorInformationInstances = processorInformationMonitor.getInstances(); + String[] processorInformationInstances = processorInformationMonitor + .getInstances(); for (String elem : processorInformationInstances) { System.out.println(elem); } - String[] processorInformationCounter = processorInformationMonitor.getCounterList(); + String[] processorInformationCounter = processorInformationMonitor + .getCounterList(); for (String elem : processorInformationCounter) { System.out.println(elem); } + ProcessorMonitor processorMonitor = new ProcessorMonitor(); + String[] processorInstances = processorMonitor.getInstances(); + for (String elem : processorInstances) { + System.out.println(elem); + } + + String[] processorCounter = processorMonitor.getCounterList(); + for (String elem : processorCounter) { + System.out.println(elem); + } + TCPv4Monitor tcpv4Monitor = new TCPv4Monitor(); String[] tcpv4Counter = tcpv4Monitor.getCounterList(); for (String elem : tcpv4Counter) {