Tuesday, March 8, 2016

Performance Monitoring And System Memory Usage While Running Selenium Test Scripts



import java.lang.management.ManagementFactory;

import java.lang.management.OperatingSystemMXBean;

import java.lang.reflect.Method;

import java.lang.reflect.Modifier;


public class PerfomanceMontior {
private static void getSystemUsage() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {

method.setAccessible(true);
if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
Object value;
try {
value = method.invoke(operatingSystemMXBean);
} catch (Exception e) {
value = e;
}
System.out.println(method.getName() + " = " + value);

}
}
}

}

No comments:

Post a Comment