Skip to content

Instantly share code, notes, and snippets.

@a2gs
Last active March 4, 2019 02:49
Show Gist options
  • Save a2gs/1d97b38f7ceb4c731414eb7bc23b2838 to your computer and use it in GitHub Desktop.
Save a2gs/1d97b38f7ceb4c731414eb7bc23b2838 to your computer and use it in GitHub Desktop.
gprof(1) Usage
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
void f1(void)
{
sleep(2);
}
unsigned int f2(unsigned int x)
{
return(x + 1);
}
void f3(void)
{
unsigned int x = 0;
for(x = 0; x < UINT_MAX; x++)
f2(x);
}
int main(int argc, char *argv[])
{
printf("f1\n");
f1();
printf("f3\n");
f3();
return(0);
}
@a2gs
Copy link
Author

a2gs commented Feb 17, 2019

  1. Compile: cc -pg -o test test.c
  2. Run: ./test
    (file gmon.out created)
  3. Print the result: gprof ./test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment