• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

CPU utilization

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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.

Thanks
Pavan.
 
Venkata Pavan Kumar vemuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the following code snippet but I am not able to understand what they are trying to do can anyone elaborate on this

I have put the part of code in bold

import java.io.*;

import org.xml.sax.*;

import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.SAXParserFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.parsers.SAXParser;



public class benchmarkSAX
{

public static void main(String argv[])

{

long a;

try
{

// Set up output stream

//out = new OutputStreamWriter(System.out, "UTF8");

SAXParserFactory factory = SAXParserFactory.newInstance();

factory.setNamespaceAware(true);

File f= new File(argv[0]);

FileInputStream fi = null;

byte[] bt;

fi = new FileInputStream(f);

System.out.println(" file size "+(int)f.length());

bt = new byte[(int)f.length()];

fi.read(bt);

SAXParser saxParser = factory.newSAXParser();

int total;

int fl = (int) f.length();

if (fl <6000)

total = 2000;

else if (fl <15000)

total = 800;

if (fl<30000)

total = 500;

else if (fl < 60000)

total = 300;

else if (fl < 120000)

total = 150;

else if (fl <500000)

total = 50;

else if (fl < 2000000)

total = 20;

else

total = 5;;

long lt = 0;

a = System.currentTimeMillis();

ByteArrayInputStream bais =
new ByteArrayInputStream(bt);

while(System.currentTimeMillis()-a <30000)

{

bais.reset();

saxParser.parse( bais, (DefaultHandler) null );

//saxParser.parse( new File(argv[0]), handler );

}


// Parse the input

//saxParser = factory.newSAXParser();

for (int j = 0;j<10;j++){

a = System.currentTimeMillis();

for(int i=0;i<total;i++)

{

bais.reset();

saxParser.parse( bais, (DefaultHandler) null );

//saxParser.parse( new File(argv[0]), handler );

}

long l2 = System.currentTimeMillis();

lt = lt + (l2 -a);

}

System.out.println(" average parsing time ==> "+
((float)(lt)/total/10));

System.out.println(" performance ==> "+
( ((double)fl *1000 * total)/((lt/10)*(1<<20))));

}
catch (SAXException e)

{

System.out.println( e);

}

catch (Throwable t)
{

t.printStackTrace();

}


}

}

Thanks in advance
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Venkata Pavan Kumar vemuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you answer the first question please
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Henry

 
Paul Clapham
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic