0

I am having an issue with "gprof" while using WSL1 and "gcc" in Ubuntu. The only information it displays is the "calls" and anything else is set as 0.00. I do not think that is because the program is running too fast because when typing time ./go it returns:

real = 0.569s; user = 0.547s; sys = 0.000s.

The main program (go.c) is:

#include <stdio.h>
#include "functions.h"

#define maxloop 1e7

int main(int argc, char*argv[]) {
    int i;
    double x;
    double xsum = 0.0;
    for (i = 1; i < maxloop; i++) {
        x = myFun1(i) + myFun2(i) + myFun3(i);
        xsum += x;
    }
    printf("xsum = %.6f\n", xsum);
    return 0;
}

The file with the functions (functions.c) is:

#include <math.h>

double myFun1(double x) {
    double a = sin(x);
    return a;
}

double myFun2(double x){
    double a = pow(x,3);
    return a;
}

double myFun3(double x){
    double a = sqrt(x);
    return a;
}

The header (functions.h) is:

double myFun1(double x);
double myFun2(double x);
double myFun3(double x);

I am compiling in the terminal as:

gcc -pg -o go go.c functions.c -lm

Running the gprof as:

gprof ./go -p -b

What is happening with gprof

the busybee
  • 10,755
  • 3
  • 13
  • 30
Felipe_SC
  • 1
  • 3
  • I cannot reproduce this on debian, so maybe it's a WSL1 issue? Suggest you add a suitable tag. It's a good idea to include data as text here instead of external images. You are making it harder than necessarily to help by giving us 2 .c and .h file instead of just a single .c file. – Allan Wind Sep 08 '22 at 22:21
  • 1
    https://stackoverflow.com/questions/66227779/wsl-gprof-reporting-zero-times has a comment says WSL 2 supports profiling. – Allan Wind Sep 08 '22 at 22:28
  • @AllanWind This is my first post here, thanks for the suggestions! I have read this answer, but I would like to keep my codes on Windows and I saw that WSL1 is better for this. In any case I will try to upgrade and test using the WSL2. – Felipe_SC Sep 09 '22 at 11:47
  • Updating to WSL2 worked just fine and I could still run the programs from Windows folder. Just leaving an update here in case someone appears with the same doubt. – Felipe_SC Sep 09 '22 at 12:41

1 Answers1

0

Upgrade to WSL2 for support of the profiling features required by gprof.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38