gprof shows every fonction (even summary) at 0%

77 Views Asked by At

I have a well working sort programm which I want to analyse with gprof.

Here is the code. It create random list of integers and sort it. It does the job :

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

int comparer_entier(const void* a, const void* b);
void trier_tableau_radix(int* t2, int size, int R);
void trier_tableau_pigeonnier(int* T, int n, int exp);

int * generer_donnees(int, int, int);
int * creer_tableau(int);
void copier_tableau(int *, int *, int);
void afficher_tableau(int *, int);
void remplir_tableau_aleatoire(int *, int, int);
void creer_tableau_indices(int *, int);

/*****************************************************************************************************/
/******************************************** MAIN ***************************************************/
/*****************************************************************************************************/

int main()
{
    int N = 10000, R = 1e4, D = 70;
    int *T1, *T2 = NULL;

    // générer les données dans T1
    T1 = generer_donnees(N, R, D);

    // créer une copie du tableau T1 dans T2
    T2 = creer_tableau(N);
    copier_tableau(T2, T1, N);

    // trier T2 avec l'algorithme Radix (tri par base)
    trier_tableau_radix(T2, N, R);

    // afficher le tableau T1 et T2
    afficher_tableau(T1, N);
    afficher_tableau(T2, N);

    return 0;
}

void trier_tableau_radix(int* T, int N, int R)
{
    int exp;
    if (N > 0)
    {

        for (exp = 1; R / exp > 0; exp *= 10)
            trier_tableau_pigeonnier(T, N, exp);
    }
    else
        printf("Erreur! Tableau vide!!!");

}

void trier_tableau_pigeonnier(int* T, int N, int exp)
{
    int* output = (int*) malloc(N * sizeof(int));

    int i, count[10] =
    { 0 };

    for (i = 0; i < N; i++)
        count[(T[i] / exp) % 10]++;

    for (i = 1; i < 10; i++)
        count[i] += count[i - 1];

    for (i = N - 1; i >= 0; i--)
    {
        output[count[(T[i] / exp) % 10] - 1] = T[i];
        count[(T[i] / exp) % 10]--;
    }

    for (i = 0; i < N; i++)
        T[i] = output[i];
}

int * generer_donnees(int N, int R, int D)
{
    int *T;
    int i, swaptemp;
    int m, k, L;
    int M;
    int *Tp;

    T = creer_tableau(N);

    srand(time(NULL));
    remplir_tableau_aleatoire(T, N, R);

    qsort(T, N, sizeof(int), comparer_entier);

    M = N / 2;
    Tp = (int *) malloc(M * sizeof(int));

    creer_tableau_indices(Tp, M);

    m = M;
    for (i = 0; i < M * D / 100; i++)
    {
        k = rand() % m;
        L = Tp[k];
        Tp[k] = Tp[m - 1];
        m--;

        swaptemp = T[M - L - 1];
        T[M - L - 1] = T[M + L];
        T[M + L] = swaptemp;
    }

    return T;
}

void remplir_tableau_aleatoire(int *T, int N, int R)
{
    /* `remplir_tableau_aleatoire` remplit un tableau `T` avec des valeurs aléatoires en fonction de `N` et `R`
     `T`: tableau à remplir
     `N`: taille du tableau
     `R`: rang des valeurs aléatoires
     */
    int i;
    for (i = 0; i < N; i++)
        T[i] = rand() % R;
}

void creer_tableau_indices(int *T, int N)
{
    int i;
    for (i = 0; i < N; i++)
        T[i] = i;
}


int comparer_entier(const void* a, const void* b)
{
    return (*(int*) a - *(int*) b);
}

int * creer_tableau(int N)
{
    return (int *) malloc(N * sizeof(int));
}

void copier_tableau(int * destination, int * source, int taille)
{
    int i;
    for (i = 0; i < taille; i++)
        destination[i] = source[i];
}

void afficher_tableau(int *T, int N)
{
    int i;
    printf("\n");
    for (i = 0; i < N; i++)
        printf("%d ", T[i]);
    printf("\n ************* \n");
}

In eclipse, when I build and execute the code, the gmon.out file appear, I choose the correct binary file in "Debug", but then I have all my fonctions at 0% despite there are calls for them :

enter image description here

Thanks for your help

0

There are 0 best solutions below