Поделиться через


/callcap - Enable callcap profiling (Windows Embedded CE 6.0)

1/5/2010

The /callcap option causes the compiler to insert calls to profiling hooks at the beginning and end of each function.

You must compile profiling hooks without the callcap switch. If you compile the profiling hook functions with the callcap switch, the functions will perform infinite recursive calls to themselves.

The following code example, Callcaphooks.c, shows a profiling hook function, _CAP_Enter_Function, for compilation without callcap.

// File: callcaphooks.c

#include <stdio.h>
int main();

void _CAP_Enter_Function(void *p) 
{
    if (p != main) 
        printf("Enter function   (at address %p) at %d\n", 
            p, GetTickCount());
        return;
}
void _CAP_Exit_Function(void *p) 
{
    if (p != main) 
        printf("Leaving function (at address %p) at %d\n", 
            p, GetTickCount());
    return;
}

The next example shows how callcap inserts calls to profiling hooks. To enable this, compile main with the callcap switch and link with the object file that contains the callcap hooks that compiled without callcap.

// File: main.c
#include <stdio.h>
double mul(double a, double b, int count)
{
    // The profiling hook, _CAP_Enter_Function() function, 
    // is called here with the address of this function.

    double r;

    // Simulate a long operation
    while (count-- > 0) 
        r = a * b;

    return a * b;

    // The profiling hook, _CAP_Exit_Function() function,
    // is called here with the address of this function.
}

The callcap switch inserts calls to the profiling hooks for all functions compiled with the callcap compiler switch.

int main()
{
    double d0 = 2.0, d1 = 4.0, result;

    // No profiling for printf, because the library function is not compiled with /callcap.
    printf("\n");     
    result = mul(d0, d1, 10000);
    return 0;
}

Callcap profiling hooks are called after the function is entered and before leaving it. In contrast, the fastcap switch inserts calls to profiling hooks before calling the function and after returning the call.

This form of profiling has lower overhead than fastcap but will not provide profiling information for external functions that have not been compiled with profiling enabled.

See Also

Concepts

Unique Build Options

Other Resources

Differences Between Desktop and Device Compilers