JoshG
10-18-2005, 05:02 PM
I have a new (just a few months old) iMac G5 running OS 10.4.2. I'm trying to profile a C application and I cannot get gprof to work! It's driving me nuts! NOTHING I have done works!
Basically, gprof is telling me that all my applications don't take any time to run. Here's sample output:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
0.0 0.00 0.00 11455 0.00 0.00 _is_empty [25]
0.0 0.00 0.00 8250 0.00 0.00 _make_nonempty [26]
0.0 0.00 0.00 1600 0.00 0.00 _insert_list [27]
0.0 0.00 0.00 4 0.00 0.00 _make_empty [28]
0.0 0.00 0.00 3 0.00 0.00 _get_num [29]
0.0 0.00 0.00 2 0.00 0.00 ___stub_getrealaddr [30]
0.0 0.00 0.00 2 0.00 0.00 _append_lists [31]
0.0 0.00 0.00 2 0.00 0.00 _make_list [32]
0.0 0.00 0.00 2 0.00 0.00 _make_list_helper [33]
0.0 0.00 0.00 2 0.00 0.00 _print_data [34]
0.0 0.00 0.00 2 0.00 0.00 _print_list [35]
0.0 0.00 0.00 1 0.00 0.00 _get_data [36]
0.0 0.00 0.00 1 0.00 0.00 _main [37]
0.0 0.00 0.00 1 0.00 0.00 _sort_data [38]
0.0 0.00 0.00 1 0.00 0.00 _sort_list [39]
I've tried this with several apps... nothing works... I have no idea what's going on. Here's the code that I'm trying to profile (just sample code to see if I can use gprof):
/* Example program for time profiling. */
#include <stdio.h>
#include <stdlib.h>
struct AList {
int first;
struct AList * rest;
};
typedef struct AList * List;
List data;
List make_empty()
{
return NULL;
}
List make_nonempty(int first, List rest)
{
List list = (List) malloc(sizeof(struct AList));
if (list == NULL) {
fprintf(stderr,"Couldn't allocate cons-cell.\n");
exit(1);
}
list->first = first;
list->rest = rest;
return list;
}
/* Returning an int, instead of bool, so that we can use the
* non-C99 compliant cc. */
int is_empty(List list)
{
return (list == NULL);
}
List make_list_helper(unsigned int size, List accum)
{
if (size == 1)
return make_nonempty(size,accum);
else
return make_list_helper(size-1,make_nonempty(size,accum));
}
List make_list(unsigned int size)
{
return make_list_helper(size,make_empty());
}
List append_lists(List list1, List list2)
{
List return_list;
if (is_empty(list1))
return list2;
else {
return_list = make_nonempty(list1->first,
append_lists(list1->rest,list2));
free(list1);
return return_list;
}
}
unsigned int get_num()
{
unsigned int n;
scanf("%u",&n);
return n;
}
/* Do interesting stuff to get some data. */
void get_data()
{
unsigned int size;
data = make_empty();
printf("To create some data, enter a sequence of positive numbers.\n");
printf("Terminate the list with a zero.\n");
printf("Use at least moderately large numbers to create enough data for good profiling.\n");
while ((size=get_num()) != 0)
data = append_lists(data,make_list(size));
}
List insert_list(int n, List list)
{
List return_list;
if (is_empty(list))
return make_nonempty(n,make_empty());
else if (n <= list->first)
return make_nonempty(n,list);
else {
return_list = make_nonempty(list->first,insert_list(n,list->rest));
free(list);
return return_list;
}
}
List sort_list(List list)
{
List return_list;
if (is_empty(list))
return list;
else {
return_list = insert_list(list->first,sort_list(list->rest));
free(list);
return return_list;
}
}
void sort_data()
{
data = sort_list(data);
}
void print_list(List list)
{
if (is_empty(list))
printf("\n");
else {
printf("%d ",list->first);
print_list(list->rest);
}
}
/* Print out whatever data we have. */
void print_data()
{
printf("The data:\n");
print_list(data);
}
int main()
{
get_data();
print_data();
/* Do something interesting on the data. */
sort_data();
print_data();
return 0;
}
Here's what I do to test gprof:
$ gcc -pg sample.c
$ ./a.out
(results of program)
$ gprof a.out gmon.out
I have tried setting the output of gcc to "sample", that doesn't work. I've tried using CC, that doesn't work. I would try to reinstall gprof but I can't find the source. I'm really lost here. :(
Thanks,
Josh
Basically, gprof is telling me that all my applications don't take any time to run. Here's sample output:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
0.0 0.00 0.00 11455 0.00 0.00 _is_empty [25]
0.0 0.00 0.00 8250 0.00 0.00 _make_nonempty [26]
0.0 0.00 0.00 1600 0.00 0.00 _insert_list [27]
0.0 0.00 0.00 4 0.00 0.00 _make_empty [28]
0.0 0.00 0.00 3 0.00 0.00 _get_num [29]
0.0 0.00 0.00 2 0.00 0.00 ___stub_getrealaddr [30]
0.0 0.00 0.00 2 0.00 0.00 _append_lists [31]
0.0 0.00 0.00 2 0.00 0.00 _make_list [32]
0.0 0.00 0.00 2 0.00 0.00 _make_list_helper [33]
0.0 0.00 0.00 2 0.00 0.00 _print_data [34]
0.0 0.00 0.00 2 0.00 0.00 _print_list [35]
0.0 0.00 0.00 1 0.00 0.00 _get_data [36]
0.0 0.00 0.00 1 0.00 0.00 _main [37]
0.0 0.00 0.00 1 0.00 0.00 _sort_data [38]
0.0 0.00 0.00 1 0.00 0.00 _sort_list [39]
I've tried this with several apps... nothing works... I have no idea what's going on. Here's the code that I'm trying to profile (just sample code to see if I can use gprof):
/* Example program for time profiling. */
#include <stdio.h>
#include <stdlib.h>
struct AList {
int first;
struct AList * rest;
};
typedef struct AList * List;
List data;
List make_empty()
{
return NULL;
}
List make_nonempty(int first, List rest)
{
List list = (List) malloc(sizeof(struct AList));
if (list == NULL) {
fprintf(stderr,"Couldn't allocate cons-cell.\n");
exit(1);
}
list->first = first;
list->rest = rest;
return list;
}
/* Returning an int, instead of bool, so that we can use the
* non-C99 compliant cc. */
int is_empty(List list)
{
return (list == NULL);
}
List make_list_helper(unsigned int size, List accum)
{
if (size == 1)
return make_nonempty(size,accum);
else
return make_list_helper(size-1,make_nonempty(size,accum));
}
List make_list(unsigned int size)
{
return make_list_helper(size,make_empty());
}
List append_lists(List list1, List list2)
{
List return_list;
if (is_empty(list1))
return list2;
else {
return_list = make_nonempty(list1->first,
append_lists(list1->rest,list2));
free(list1);
return return_list;
}
}
unsigned int get_num()
{
unsigned int n;
scanf("%u",&n);
return n;
}
/* Do interesting stuff to get some data. */
void get_data()
{
unsigned int size;
data = make_empty();
printf("To create some data, enter a sequence of positive numbers.\n");
printf("Terminate the list with a zero.\n");
printf("Use at least moderately large numbers to create enough data for good profiling.\n");
while ((size=get_num()) != 0)
data = append_lists(data,make_list(size));
}
List insert_list(int n, List list)
{
List return_list;
if (is_empty(list))
return make_nonempty(n,make_empty());
else if (n <= list->first)
return make_nonempty(n,list);
else {
return_list = make_nonempty(list->first,insert_list(n,list->rest));
free(list);
return return_list;
}
}
List sort_list(List list)
{
List return_list;
if (is_empty(list))
return list;
else {
return_list = insert_list(list->first,sort_list(list->rest));
free(list);
return return_list;
}
}
void sort_data()
{
data = sort_list(data);
}
void print_list(List list)
{
if (is_empty(list))
printf("\n");
else {
printf("%d ",list->first);
print_list(list->rest);
}
}
/* Print out whatever data we have. */
void print_data()
{
printf("The data:\n");
print_list(data);
}
int main()
{
get_data();
print_data();
/* Do something interesting on the data. */
sort_data();
print_data();
return 0;
}
Here's what I do to test gprof:
$ gcc -pg sample.c
$ ./a.out
(results of program)
$ gprof a.out gmon.out
I have tried setting the output of gcc to "sample", that doesn't work. I've tried using CC, that doesn't work. I would try to reinstall gprof but I can't find the source. I'm really lost here. :(
Thanks,
Josh