add functions insturmentation example
This commit is contained in:
@@ -3,8 +3,12 @@
|
|||||||
This folder contains examples in C++ from second chapter.
|
This folder contains examples in C++ from second chapter.
|
||||||
|
|
||||||
The folder contains following examples:
|
The folder contains following examples:
|
||||||
|
- instrument_functions.cpp
|
||||||
- vector_dyn_mem.cpp
|
- vector_dyn_mem.cpp
|
||||||
- vector_dyn_mem_reserve.cpp
|
- vector_dyn_mem_reserve.cpp
|
||||||
- vector_pmr.cpp
|
- vector_pmr.cpp
|
||||||
- terminate_handler.cpp
|
- terminate_handler.cpp
|
||||||
- new_deleted.cpp
|
- new_deleted.cpp
|
||||||
|
|
||||||
|
## Functions instrumentation in GCC
|
||||||
|
Compile instrument_functions.cpp example using compiler flag -finstrument-functions
|
||||||
|
|||||||
32
Chapter02/instrument_functions.cpp
Normal file
32
Chapter02/instrument_functions.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
// Stub DWT_CYCCNT register
|
||||||
|
#define DWT_CYCCNT 100
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
__attribute__((no_instrument_function)) void __cyg_profile_func_enter(void *this_fn, void *call_site)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("entry, %p, %d\n", this_fn, DWT_CYCCNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((no_instrument_function)) void __cyg_profile_func_exit(void *this_fn, void *call_site)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("entry, %p, %d\n", this_fn, DWT_CYCCNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fun()
|
||||||
|
{
|
||||||
|
printf("Hi from fun!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
fun();
|
||||||
|
printf("Hi from main!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user