Get the App
SLTechnology News&Howtos  ›  Servers  › 

The implementation method of performance Statistics of Cpicket + function under AIX

Shulou Source: shulou.com Published: 2022-06-02 06:31:20 09月23日 Update

In AIX, the xlc compiler has an option-qfunctrace, and programs compiled with this option automatically call the following custom function at the entrance and exit of each function.

Extern "C" void

_ _ func_trace_enter (const char * const proc_name

Const char * const file_name

Const int line_no

Void * * const id)

Extern "C" void

_ _ func_trace_exit (const char * const proc_name

Const char * const file_name

Const int line_no

Void * * const id)

Extern "C" void

_ _ func_trace_catch (const char * const proc_name

Const char * const file_name

Const int line_no

Void * * const id)

Execute _ _ func_trace_enter () before the function call, and _ _ func_trace_exit () after the function returns normally. If the function is thrown through a throw exception, execute _ _ func_trace_catch () where the exception is caught by catch, but encounter catch (...). The capture will not be performed. It is worth noting that if throw is thrown, _ _ func_trace_exit () will not be triggered.

Using this function, you can achieve the effect of performance statistics without modifying the source program. The procedure is as follows.

Tr.cpp is a custom function entry and exit program, which passes through each function when it is executed. Compiled into libfunctr.so.

# include

# include

# include

# include

Using std::vector

Using std::string

Using std::clog

Using std::endl

Extern "C" void print_trace ()

Struct Stat

{

Int lvl

String name

Long stm

Long etm

Long oitv

Stat (int l, const string& s, long st): lvl (l), name (s), stm (st), etm (0), oitv (0) {}

}

Static vector tracev

Static int clvl = 0

Extern "C" void

_ _ func_trace_enter (const char * const proc_name

Const char * const file_name

Const int line_no

Void * * const id)

{

/ / printf ("{% s (% s% d)% p% s\ n", proc_name, file_name, line_no, id [0], (char*) * id)

Struct timeval nowtm

Gettimeofday (& nowtm, NULL)

+ + clvl

Tracev.push_back (Stat (clvl, string (proc_name) + "():" + file_name, nowtm.tv_sec * 1000000 + nowtm.tv_usec))

}

Extern "C" void

_ _ func_trace_exit (const char * const proc_name

Const char * const file_name

Const int line_no

Void * * const id)

{

/ / printf ("}% s (% SVA% d)% p% s\ n", proc_name, file_name, line_no, id [0], (char*) * id)

Struct timeval nowtm

Int itv

Gettimeofday (& nowtm, NULL)

Auto iter = tracev.end ()-1

While (iter- > etm! = 0)

-- iter

Iter- > etm = nowtm.tv_sec * 1000000 + nowtm.tv_usec

Itv = iter- > etm-iter- > stm-iter- > oitv

For (auto s = tracev.begin (); swords tracev.end (); slots +)

{

If (s-> etm = = 0)

S-> oitv + = itv

}

-- clvl

If (clvl = = 0)

Print_trace ()

}

Extern "C" void print_trace ()

{

Time_t t

Char buf [30]

For (auto s = tracev.begin (); swords tracev.end (); slots +)

{

Clog

Tags: Functions compilers programs code effects time performance statistics examples entrances entrances exits functions hierarchies files source files source programs compilers exits demos Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Shulou Tech Info Redmi macOS