Community
cancel
Showing results for 
Search instead for 
Did you mean: 
kadirgoktas
Beginner
136 Views

Function instrumentation doesn't work !!!

i just want to test how the function instrumentation works.
i have a simple single file as below to test but it does not work.

test.cpp
********************************************************************
#include
#include
#include
#include
#include
#include
using namespace std;

#define __NON_INSTRUMENT_FUNCTION__ __attribute__((__no_instrument_function__))

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_enter(void *this_fn, void *call_site)
{
printf("entry: %p\\n", this_fn);
(void)call_site;
}

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_exit(void *this_fn, void *call_site)
{
printf("exit: %p\\n", this_fn);
(void)call_site;
}

void asd2(void)
{
printf("asd2\\n");
}

int main()
{
bool i = 1;

asd2();

return 0;
}
********************************************************************
and i am compiling the file as below

> icc -g -finstrument-functions test.cpp -o main

but it doesn't work. it only prints "asd2" when i executed ./main



when i splitt the file into two pieces as below, function instrumentation works

> icc -g -finstrument-functions ftest.cpp trace.c -o main2 // compiling with this command

and it works.

how can it be happening ?

ftest.cpp
*************
#include
using namespace std;

void asd1(void)
{
printf("asd1\\n");
}

int main()
{
bool i = 1;

asd1();
return 0;
}
*************

and

trace.c
*************
#include
#include
#include
#include
#include

#define __NON_INSTRUMENT_FUNCTION__ __attribute__((__no_instrument_function__))

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_enter(void *this_fn, void *call_site)
{
printf("entry: %p\\n", this_fn);
(void)call_site;
}

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_exit(void *this_fn, void *call_site)
{
printf("exit : %p\\n", this_fn);
(void)call_site;
}
***********
0 Kudos
1 Reply
Brandon_H_Intel
Employee
136 Views

I'm still looking into this a bit, but what I tried first that seemed to work was to declare the two instrumented functions as extern "C". So do:

[cpp]test.cpp
********************************************************************
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

extern "C" {
#define __NON_INSTRUMENT_FUNCTION__    __attribute__((__no_instrument_function__))

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_enter(void *this_fn, void *call_site)
{
    printf("entry: %pn", this_fn);
    (void)call_site;
}

void
__NON_INSTRUMENT_FUNCTION__
__cyg_profile_func_exit(void *this_fn, void *call_site)
{
    printf("exit: %pn", this_fn);
    (void)call_site;
}
} // end extern "C"
void asd2(void)
{
  printf("asd2n");
}

int main()
{
    bool i = 1;
    
    asd2();
    
    return 0;
}
********************************************************************
[/cpp]
Reply