Monday, 15 September 2014

osx - SIGAR For Java in Mac OS X Seems to be Locking Up -



osx - SIGAR For Java in Mac OS X Seems to be Locking Up -

i have been trying write simple cpu utilization monitor proof of concept larger project. writing in eclipse juno. when press "run", application works expected- cpu utilization displayed percent updates 1 time every second. however, when export executable jar, application seems lock up- never displays percentage, , never updates. have determined gui fine, inexplicable reason, cpuutilization method never returns percentage without ever throwing exception. odder, problem happens when programme exported. sigar's documentation pretty atrocious, think using correctly. rest of programme seems work, i'll include cpureader class. constructed when cpumonitorgui class constructed, , cpuutilization called 1 time per sec cpumonitorgui. additional notes: have imported sigar.jar not log4j.jar. doing makes no difference. also, in eclipse, have selected "package required libraries generated jar" when export.

package cpuperc; import org.hyperic.sigar.cpuperc; import org.hyperic.sigar.sigarexception; import org.hyperic.sigar.humidor; import org.hyperic.sigar.sigarproxy; public class cpureader { static humidor h; public cpureader() { h = humidor.getinstance(); } public double cpuutilization() throws sigarexception { //returns cpu utilization truncated two-decimal percent sigarproxy sp = h.getsigar(); cpuperc cp = sp.getcpuperc(); double combined; double total; double idle; double percentused; int truncate = 0; //get cpu times combined = cp.getcombined(); idle = cp.getidle(); total = idle + combined; //determine percent , truncate percentused = ((double)combined/total)*100; truncate = (int)(percentused*100.0); percentused = (double)truncate/100; return(percentused); } }

thanks!

after more experimentation, found out programme freezing because looking sigar libraries specific operating scheme , architecture. in case, wanted 64-bit universal mac os x drivers. however, sigar provided these .dylib files, eclipse refused load. .dylib files had packaged in .zip archive, added eclipse build path.

java osx compilation freeze sigar

No comments:

Post a Comment