I am running a SAX parser and DOM parser application, I want to calculate the CPU utilization in MIPS for this java application. Can anyone please help me in this regard.
It looks like rubbish to me (even disregarding the fact that you didn't post it in code tags so it looks ugly because of that). However, the best strategy to find out why somebody wrote some particular code is to ask them. Why not try that?
This is something that is not possible from within a thread, or even within a process. This is something that has to be done by the hardware or done by the kernal. And it is usually done by measuring the amount of "ticks" counted for an application. The count of the times an application stack frame is the current frame when a timer interrupt occurs.
The Java process must get it from the kernal. For example, with unix, you can call "ps", or even look at the procfs stats file for the java application's pid. For windows, you can call "typeperf".
Henry
This message was edited 2 times. Last update was at by Henry Wong
Paul Clapham wrote:It looks like rubbish to me (even disregarding the fact that you didn't post it in code tags so it looks ugly because of that). However, the best strategy to find out why somebody wrote some particular code is to ask them. Why not try that?
It looks like it was probably done by Statistics / Curve Fitting. Meaning take a bunch of computers, with different speeds. Measure how long they take to finish a known job. Measure the CPU utilization during those jobs. And curve fit all of those points to get a formula that will extrapolate the utilization based on the measured data.
Of course, I could be wrong, and the programmer could have just pulled the formula out of thin air.
Paul Clapham wrote:It looks like rubbish to me (even disregarding the fact that you didn't post it in code tags so it looks ugly because of that). However, the best strategy to find out why somebody wrote some particular code is to ask them. Why not try that?
It looks like it was probably done by Statistics / Curve Fitting. Meaning take a bunch of computers, with different speeds. Measure how long they take to finish a known job. Measure the CPU utilization during those jobs. And curve fit all of those points to get a formula that will extrapolate the utilization based on the measured data.
Of course, I could be wrong, and the programmer could have just pulled the formula out of thin air.
It looks to me like the whole mess is intended to end up with "total * fl" being close to some predetermined constant, so as to get a standardized test. But I would have done that with one line of division to come as close as possible to that constant, rather than a whole bunch of if-statements which sort of come close to it.
Sometimes I think this forum should be renamed "Questions about XML Parser performance". There seems to be a lot of people obsessing over that.