Thursday, September 10, 2009

Can't get getrusage working

We are trying to measure the amount of resources needed to run our program, written in C. Looking here and there, I found getrusage (2). So, yesterday I tried to write a simple code:


#include <stdio.h>
#include <errno.h>
#include <sys/resource.h>

int main(){
int y[100][100];
struct rusage *resource;
int x;

x = getrusage(0, resource);
printf("x = %d\n", x);
printf("errno = %d\n", errno);
return(0);
}


The result was not great. getrusage returned -1. According to the man page, non zero return value means it fails. The value of errno is 14.

What went wrong? Anybody?

Is there a better way to measure the amount of resources (memory, CPU, time) needed for a program? [Right now, I am looking at dtrace. Would it help?]

1 comment:

Budi Mulyawan said...

struct rusage *resource;
resource still NULL?

shouldn't it be?

struct rusage resource;