Cpu usage info for java app Expert help needed - Chicagoland Sportbikes
Chicagoland Sportbikes
 
Geek Squad to the rescue! fucken computer crashing on you again? another porn site infected your computer? tierd of your wife seeing your anal fisting videos and want to lock her out of the external HD? get the answers you need from our local computer experts.

 
LinkBack Thread Tools Display Modes
post #1 of 22 (permalink) Old 11-03-2007, 10:13 PM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
Cpu usage info for java app Expert help needed

Hi,

I spent the past 72 hours trying to figure out how to get cpuload (of ALL processes) to my java app, to further work with the numbers.

I need 3 pieces of information: OS, memory usage, and cpuload(1, 5, and 15 minutes) on win and linux. (not java VM usage)

Runtime and Properties classes give me the OS (so i can determine which command to use to gather other info)

i can exec systeminfo and get Total Physical Memory, Available Physical Memory, Virtual Memory Size, Virtual Memory: Available, Virtual Memory: In Use


apparently, there is no way to do this from java on windows (my app has to be portable to at least win and linux) and one has to use C libs and javah to create header files etc.
so, i found this awesome library, and after spending all day building it and getting it to run, it shows the cpu only of the current process.

can anyone help me either modify the existing library or do you have any idea how to get the info done. my homework goes wayyyyy beyond this, but I am stuck right here and see no way out.

thanks,

very frustrated SG
Supergirl is offline  
Sponsored Links
Advertisement
 
post #2 of 22 (permalink) Old 11-03-2007, 10:30 PM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
can you exec vmstat on linux? :>

I know there exist utilities (and probably even the same command) under the cygwin package for windows (gives a unix-like API and commands to windows boxes through a very functional DLL system) but that does require it to be installed on the client machines unfortunately.. let me see if I can dig something up that's more native....

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #3 of 22 (permalink) Old 11-03-2007, 10:40 PM
[Online]
 
Fracker's Avatar
 
Join Date: Mar 2005
Location: Chicago
Posts: 3,695
Location: Chicago
Sportbike: Multistrada 1100S; CBR600RR
Years Riding: Since 2004
How you found us: CRR
           
Not a Java expert (.NET guy here, know just a little bit of Java to be dangerous) - but the obvious solution is to give up portability and either build two versions (Win/Linux) or dynamically load a library with the OS-specific implementation.

EDIT: I guess you have to use JNI to access OS specific implementation... But I can't be sure.

BTW, have you tried googling it? Java "java get cpu load" produces some results.

- Stas

Thou shalt not disfigure the soul.

Last edited by Fracker; 11-03-2007 at 10:43 PM.
Fracker is offline  
Sponsored Links
Advertisement
 
post #4 of 22 (permalink) Old 11-03-2007, 10:45 PM
The Benchwarmer
 
Village Idiot's Avatar
 
Join Date: Jun 2007
Location: Chicago
Posts: 14,580
Location: Chicago
Sportbike: Ninja
Years Riding: Long
How you found us: Dong
           
Java MIGHT be a good example of what a programming language should be like. But Java applications are good examples of what applications SHOULDN'T be like.

Men will never be free until the last king is strangled with the entrails of the last priest - Denis Diderot
Village Idiot is offline  
post #5 of 22 (permalink) Old 11-03-2007, 11:03 PM
[Online]
 
Fracker's Avatar
 
Join Date: Mar 2005
Location: Chicago
Posts: 3,695
Location: Chicago
Sportbike: Multistrada 1100S; CBR600RR
Years Riding: Since 2004
How you found us: CRR
           
Quote:
Originally Posted by burntash View Post
Java MIGHT be a good example of what a programming language should be like. But Java applications are good examples of what applications SHOULDN'T be like.
It all actually reminds me of what somebody said about Java once:

Quote:
Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders

- Stas

Thou shalt not disfigure the soul.
Fracker is offline  
post #6 of 22 (permalink) Old 11-03-2007, 11:09 PM
The Benchwarmer
 
Village Idiot's Avatar
 
Join Date: Jun 2007
Location: Chicago
Posts: 14,580
Location: Chicago
Sportbike: Ninja
Years Riding: Long
How you found us: Dong
           
Quote:
Originally Posted by Fracker View Post
It all actually reminds me of what somebody said about Java once:
haha hell ya man, not a fan of c++ or java.

but put php and sql in front of me and i pop a chubby

perl is nice too if i feel like programming something that looks like the code of the matrix.

Men will never be free until the last king is strangled with the entrails of the last priest - Denis Diderot
Village Idiot is offline  
post #7 of 22 (permalink) Old 11-03-2007, 11:25 PM
Registered User
 
DieselBoy's Avatar
 
Join Date: Aug 2004
Location: Naperville IL
Posts: 701
Location: Naperville IL
Sportbike: 08 R6 , CRF250R
Years Riding: 1
How you found us: chicagorussionriders
           
Linux does not report such thing as CPU load. What you can find out though is % of CPU time spent in varuous states : user code,kernel code, waiting for IO , sleeping

Generally the "load" is defined as number of processes ready to run sampled over fixed time span . Linux uptime gives you that information. You can exec and parse output of that command. On Windows, you can peridocically query process tree for ready to run processes and build avarage yourself.

BTW: take advantage of "information hiding" technique not to get stuck on this particular topic of your homework. Build a stub and move on. You can alway "false" simulate the results when time comes

CCS 787(ex). 08r6

Last edited by DieselBoy; 11-03-2007 at 11:28 PM. Reason: BTW
DieselBoy is offline  
post #8 of 22 (permalink) Old 11-03-2007, 11:29 PM
The Benchwarmer
 
Village Idiot's Avatar
 
Join Date: Jun 2007
Location: Chicago
Posts: 14,580
Location: Chicago
Sportbike: Ninja
Years Riding: Long
How you found us: Dong
           
Quote:
Originally Posted by DieselBoy View Post
Generally the "load" is defined as number of processes ready to run sampled over fixed time span . Linux uptime gives you that information. You can exec and parse output of that command. On Windows, you can peridocically query process tree for ready to run. Build avarage yourself.

BTW: take advantage of "information hiding" technique not to get stuck on this particular topic of your homework. Build a stub and move on. You can alway "false" simulate the results when time comes
+1

i would run the uptime command and parse the information to get the cpu load. just hard code the results

Men will never be free until the last king is strangled with the entrails of the last priest - Denis Diderot
Village Idiot is offline  
post #9 of 22 (permalink) Old 11-03-2007, 11:58 PM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
wow answers!!!!!

shouldn't /proc/meminfo /proc/cpuinfo work on linux? don't have a second to try it, still stuck on windows.

obviously I will have different versions, BUT

i found a scaled down c++ lib for my "problem" but i'm too stoopid to compile it from the console and include all the java JNI include paths.

please help. i can deal with c++ OR with java, but not with both LOL and tomorrow comes c# part for it, don't ask.

so CURRENT problem (and this is modified from the previous c lib, i copied java inlcudes into c:\temp)

C:\MinGW\bin>cpp -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -I C:/temp/include -I C:/T
emp/include/win32 -shared C:/temp/Resource_monitor.cpp C:/MinGW/lib/libpsapi.a
cpp: --kill-at: linker input file unused because linking not done

Please help me to fix this, so I can finally move on!!

Thanks to all for good ideas!

EDIT

when i run the app, i get the linking error

java.lang.UnsatisfiedLinkError: C:\WINDOWS\system32\pr_res.dll: %1 is not a valid Win32 application
Supergirl is offline  
post #10 of 22 (permalink) Old 11-04-2007, 12:09 AM
The Benchwarmer
 
Village Idiot's Avatar
 
Join Date: Jun 2007
Location: Chicago
Posts: 14,580
Location: Chicago
Sportbike: Ninja
Years Riding: Long
How you found us: Dong
           
Quote:
Originally Posted by Supergirl View Post
wow answers!!!!!

shouldn't /proc/meminfo /proc/cpuinfo work on linux? don't have a second to try it, still stuck on windows.

obviously I will have different versions, BUT

i found a scaled down c++ lib for my "problem" but i'm too stoopid to compile it from the console and include all the java JNI include paths.

please help. i can deal with c++ OR with java, but not with both LOL and tomorrow comes c# part for it, don't ask.

so CURRENT problem (and this is modified from the previous c lib, i copied java inlcudes into c:\temp)

C:\MinGW\bin>cpp -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -I C:/temp/include -I C:/T
emp/include/win32 -shared C:/temp/Resource_monitor.cpp C:/MinGW/lib/libpsapi.a
cpp: --kill-at: linker input file unused because linking not done

Please help me to fix this, so I can finally move on!!

Thanks to all for good ideas!

EDIT

when i run the app, i get the linking error

java.lang.UnsatisfiedLinkError: C:\WINDOWS\system32\pr_res.dll: %1 is not a valid Win32 application
/proc/cpuinfo is just going to show you information on the processor like family, model, cache size, etc n shit it wont show you its load. so you cant really 'grep' that and expect to get the info you're looking for

Men will never be free until the last king is strangled with the entrails of the last priest - Denis Diderot
Village Idiot is offline  
post #11 of 22 (permalink) Old 11-04-2007, 12:31 AM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
k, thanks for the info. still problem with linking.
Supergirl is offline  
post #12 of 22 (permalink) Old 11-04-2007, 12:39 AM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
Quote:
Originally Posted by DieselBoy View Post
Linux does not report such thing as CPU load. What you can find out though is % of CPU time spent in varuous states : user code,kernel code, waiting for IO , sleeping

Generally the "load" is defined as number of processes ready to run sampled over fixed time span . Linux uptime gives you that information. You can exec and parse output of that command. On Windows, you can peridocically query process tree for ready to run processes and build avarage yourself.

BTW: take advantage of "information hiding" technique not to get stuck on this particular topic of your homework. Build a stub and move on. You can alway "false" simulate the results when time comes
Since he asked for 'cpu load' I thought vmstat could be read and then subtract the CPU idle column from 100 to give you the percentage of 'cpu usage'. Not really caring if it was spent in system land, user land or waiting on disk I/O :> I've always looked at the 'load' from uptime as being too subjective to really even care about because it's easy to have a system where the 'load' might be 15-20 and have it be much peppier than a system with a 'load' of 5 depending on exactly what applications are running. Reading the 'idle' time will give you a better machine feel of how much the cpu is actually working versus just giving you a process count.

It really depends on what he's ultimately trying to find out to report on/display....

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #13 of 22 (permalink) Old 11-04-2007, 12:52 AM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
I so hope some of you stay around tomorrow when I get to that part


EDIT:

nope doesn't work

Last edited by Supergirl; 11-04-2007 at 01:01 AM.
Supergirl is offline  
post #14 of 22 (permalink) Old 11-04-2007, 07:33 AM
Registered User
 
DieselBoy's Avatar
 
Join Date: Aug 2004
Location: Naperville IL
Posts: 701
Location: Naperville IL
Sportbike: 08 R6 , CRF250R
Years Riding: 1
How you found us: chicagorussionriders
           
Quote:
Originally Posted by Supergirl View Post
C:\MinGW\bin>cpp -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -I C:/temp/include -I C:/T
emp/include/win32 -shared C:/temp/Resource_monitor.cpp C:/MinGW/lib/libpsapi.a
cpp: --kill-at: linker input file unused because linking not done
On linux that's C++ preprocessor , not linker , and not compiler.

The way to build shared lib is :

Compile source :
c++ -D_JNI_IMPLEMENTATION_ -I C:/temp/include -I C:/Temp/include/win32 -o Resource_monitor.o -c Resource_monitor.cpp

Link library libmylibname.so
c++ -shared -o ./libmylibname.so ./Resource_monitor.o [other .o or .a files]

However, if you use shared library or JNI you automatically make your application non portable.

CCS 787(ex). 08r6

Last edited by DieselBoy; 11-04-2007 at 07:38 AM. Reason: .o .a files
DieselBoy is offline  
post #15 of 22 (permalink) Old 11-04-2007, 11:52 AM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
Thank you Diesel boy!

now, but if I in my logic make use of the library only in case my OS is let's say "win", and don't make any use of it in other case, I should be fine, right?

this C++ lib is made for win, the other, first one I found was generic, but it gave me just the cpu usage of the current process.

if I can get my info by exec command on linux, I won't need the library.

Thanks for the syntax! Highly appreciate it!!
Supergirl is offline  
post #16 of 22 (permalink) Old 11-04-2007, 04:51 PM
Registered User
 
DieselBoy's Avatar
 
Join Date: Aug 2004
Location: Naperville IL
Posts: 701
Location: Naperville IL
Sportbike: 08 R6 , CRF250R
Years Riding: 1
How you found us: chicagorussionriders
           
Quote:
Originally Posted by Supergirl View Post
Thank you Diesel boy!
now, but if I in my logic make use of the library only in case my OS is let's say "win", and don't make any use of it in other case, I should be fine, right?
Yes , you should be fine. You just can't use the same library code for two different OS.

CCS 787(ex). 08r6
DieselBoy is offline  
post #17 of 22 (permalink) Old 11-05-2007, 03:51 AM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
I never made it that far

This homework was bigger than the senior project in my undergrad.

it works for windows so far, but the server won't talk to the gui component and send him information collected from clients

I'll try to get that to work in the morning (gui) and hell, the homework is due 4:15pm :cry:

Thank you all for all the help! <3

SG
Supergirl is offline  
post #18 of 22 (permalink) Old 11-05-2007, 07:29 AM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
Heh, run a package like sysstat on the server and have it dump an XML or CSV file on a periodic basis, then have the java ap just grab the file

Hell, that works w/ any web browser too

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #19 of 22 (permalink) Old 11-05-2007, 12:01 PM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
Quote:
Originally Posted by Arch View Post
Heh, run a package like sysstat on the server and have it dump an XML or CSV file on a periodic basis, then have the java ap just grab the file

Hell, that works w/ any web browser too
you know, that's a really good idea.

I thought of excel, bc that way i thought i could even pull the graph, but figured i won't have excel on linux.

xml or csv would have been way to go!

i still have 3 hours time

Thanks!
Supergirl is offline  
post #20 of 22 (permalink) Old 11-05-2007, 12:08 PM
Irony helps us play!
 
Arch's Avatar
 
Join Date: Jan 2006
Location: N'ville
Posts: 29,508
Location: N'ville
Sportbike: 2000 F4
Years Riding: Long enough to know better
How you found us: some hot MILF whispered it in my ear
           
Quote:
Originally Posted by Supergirl View Post
you know, that's a really good idea.

I thought of excel, bc that way i thought i could even pull the graph, but figured i won't have excel on linux.

xml or csv would have been way to go!

i still have 3 hours time

Thanks!
Dude.. http://www.openoffice.org

Cross platform, open source, MS Office compatible and free.


...as for the sysstat idea, that will only dump the server's information, not the client's, just FYI....

Everyone Exaggerates

We're being taken for a ride... agaaaaaaain.....


Best Auto/Moto Insurance | Motorcycle Protection Today | FREE Trade-In Quote
Arch is offline  
post #21 of 22 (permalink) Old 11-05-2007, 12:21 PM
The Benchwarmer
 
Village Idiot's Avatar
 
Join Date: Jun 2007
Location: Chicago
Posts: 14,580
Location: Chicago
Sportbike: Ninja
Years Riding: Long
How you found us: Dong
           
<3 openoffice

i use it all the time and dump out any information from php and sql into a CSV file.

Men will never be free until the last king is strangled with the entrails of the last priest - Denis Diderot
Village Idiot is offline  
post #22 of 22 (permalink) Old 11-05-2007, 10:01 PM Thread Starter
Defender of the Innocent
 
Supergirl's Avatar
 
Join Date: Oct 2007
Location: Woodstock, IL
Posts: 2,918
Location: Woodstock, IL
Sportbike: Simon and Garfunkel
Years Riding: over a decade
How you found us: YZFRob
           
sure, i know about it, but i would have to install it on every single client i need to run the app at. so that wouldn't make the app as portable as if i was using csv or xml

but thanks anyway

i demonstrated that it worked, and a couple of us got an extension to work on gui. that's good news!!!
Supergirl is offline  
Reply

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the Chicagoland Sportbikes forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome