program resource usege

C

Carramba

Hello!
Is there a way in standard C to get information on resource program is
using? What I would like to know given program A, can A get how much
memory it have allocated, how much of CPU it using, how many
instructions have been fetched.
Or this is strictly platform depended?
If so what design approach is best to implement multiplatform? working
through #DEFINE and just insert code depending on platform?

Thank you in advance!
Have a nice day :)
 
C

Chris Dollin

Carramba said:
Hello!
Hello!!

Is there a way in standard C to get information on resource program is
using?
No.

What I would like to know given program A, can A get how much
memory it have allocated, how much of CPU it using, how many
instructions have been fetched.
Or this is strictly platform depended?
Yes.

If so what design approach is best to implement multiplatform? working
through #DEFINE and just insert code depending on platform?

IMAO, no.

Design the API for how your program wants to fetch the information,
encode the API as a C header file, and provide a separate implementation
for each different platform.

I presume you don't have the choice to not care.
 
E

Eric Sosman

Carramba wrote On 06/28/07 08:34,:
Hello!
Is there a way in standard C to get information on resource program is
using? What I would like to know given program A, can A get how much
memory it have allocated, how much of CPU it using, how many
instructions have been fetched.
Or this is strictly platform depended?
If so what design approach is best to implement multiplatform? working
through #DEFINE and just insert code depending on platform?

The only thing C itself provides is the clock()
function, which you can use to measure the amount of
CPU time consumed between two calls to clock(). The
precision of the count varies from system to system
but is published as the value of CLOCKS_PER_SEC, a
macro defined in <time.h>. The accuracy of the count
(not necessarily the same as the precision) also varies,
and is not available. (For that matter, the definition
of "CPU time" varies and is also not available ...)

The other things you mention are strictly platform-
dependent; not all of them are always available.

The choice of a design approach depends a good deal
on what you intend to do with the information (assuming
you can get it). If you just want to display whatever
is available, I'd suggest putting everything in one
self-contained function that you re-implement for each
platform; your program just calls display_resource_info()
and that's that. If your program needs to make decisions
based on these values, things will be harder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top