Questions tagged [getrusage]

getrusage() is a Unix function that measures resources used by the current process

47 questions
22
votes
6 answers

UNIX Programming. struct timeval how to print it (C-programming)

I am trying to print a value of type timeval. Actually I am able to print it, but I get the following warning: Multiple markers at this line format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘struct timeval’ The program compiles and it…
user69514
  • 26,935
  • 59
  • 154
  • 188
19
votes
2 answers

What's the unit of `ru_maxrss` on Linux?

This is from man getrusage struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral…
Tianyang Li
  • 1,755
  • 5
  • 26
  • 42
16
votes
3 answers

Getting getrusage() to measure system time in C

I would like to measure the system time it takes to execute some code. To do this I know I would sandwich said code between two calls to getrusage(), but I get some unexpected results... #include #include #include…
Stout Joe
  • 324
  • 2
  • 4
  • 14
8
votes
1 answer

Is getrusage broken in Linux (2.6.30)

This code void print_usage(char * msg) { struct rusage usage; getrusage(RUSAGE_SELF, &usage); printf("Limits: %s\n", msg); printf(" %s, %li\n", " maximum resident set size " , usage.ru_maxrss ); printf(" %s, %li\n", "…
osgx
  • 90,338
  • 53
  • 357
  • 513
5
votes
1 answer

getrusage vs. clock_gettime()

I am trying to obtain the CPU time consumed by a process on Ubuntu. As far as I know, there are two functions can do this job: getrusage() and clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp). In my code, calling getrusage() immediately after…
Dillon Geo
  • 271
  • 1
  • 2
  • 6
5
votes
1 answer

Are two successive calls to getrusage guaranteed to produce increasing results?

In a program that calls getrusage() twice in order to obtain the time of a task by subtraction, I have once seen an assertion, saying that the time of the task should be nonnegative, fail. This, of course, cannot easily be reproduced, although I…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
4
votes
0 answers

Portable equivalent to getrusage() in C++?

We're using getrusage() when compiling on Linux to gain some insights into how much CPU-time some operations take in each thread: getrusage(RUSAGE_THREAD, &before); .... do work .... getrusage(RUSAGE_THREAD, &after); However, because the call is…
Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
4
votes
2 answers

Linux getrusage() maxrss maximum resident set size not increasing with allocation (C++)

I am trying to use getrusage(.) and maximum resident set size (maxrss) to check for memory leaks. However, when i purposely try to create a leak, maxrss does not change. Maybe i am not understanding maxrss deeply enough. Here is the code: #include…
4
votes
1 answer

what does "ru_maxrss" means in getrusage

I compiled and run the following c++ code test.cpp on my macOS Sierra. #include #include using namespace std; int main() { int a = 1; struct rusage r_usage; getrusage(RUSAGE_SELF, &r_usage); cout <<…
sirius
  • 567
  • 6
  • 26
3
votes
1 answer

getrusage function on embedded linux

I have one bench marking application in which I am evaluating a C++ framework. I am looking for the time and memory consumption. On linux, to get the memory occupied by the current program, I am using getrusage function. It works perfectly on my…
Nadeem
  • 75
  • 2
  • 11
3
votes
1 answer

Resource Allocation of a C executable on two different Linux Computers

I am compiling and running the following c file on two different linux computers (Arch on Huawei Laptop 8GB RAM, Ubuntu on iMac 2017 32GB RAM). #include #include long get_mem_usage() { struct rusage myusage; …
Shahin
  • 1,196
  • 1
  • 8
  • 15
3
votes
1 answer

Does compilation of a program store some data in cache before execution?? (C, Linux)

Does compilation of a program store some data in cache before execution? I wrote a C program in Linux that starts Sublime Text in one thread and makes manual system calls in another thread. (I'll explain why I do this at the end as this is not…
Leonard
  • 2,978
  • 6
  • 21
  • 42
3
votes
1 answer

How getrusage works and What is really inside the rusage struct?

I'm trying to understand how int getrusage(int who, struct rusage* usage) works in order to calculate the running time of one my program. I red the man page, 10 times maybe, and still can't get it. Tried to find something on the web, but nothing…
Root149
  • 389
  • 1
  • 3
  • 11
3
votes
1 answer

Benchmark code - dividing by the number of iterations or not?

I had an interesting discussion with my friend about benchmarking a C/C++ code (or code, in general). We wrote a simple function which uses getrusage to measure cpu time for a given piece of code. (It measures how much time of cpu it took to run a…
mazix
  • 2,540
  • 8
  • 39
  • 56
2
votes
2 answers

How can adding a header increase portability? (sys/time.h)

I just noticed this line in the getrusage man page: Including is not required these days, but increases portability. (Indeed, struct timeval is defined in ) What? Since struct rusage contains struct timeval as a member,…
spraff
  • 32,570
  • 22
  • 121
  • 229
1
2 3 4