Library for measuring execution time in Linux C applications

Recently, I often embed the performance measurement log and disable it every time, so I decided to make a library. I made it so much, so a memorandum.

2017/4/23 Corrected because there was a difference in type definition && configure

What is it like?

If you use it with a printf image, it will save a log with the time. The log is not output immediately when the function is executed, but is saved in the reserved memory and then discharged at the end.

Since the log is not spit out each time the process is executed, the log is spit out with memcpy, so I think that the effect on speed is less than simply inserting the log. I think that it can be used enough if it is an application level of middleware.

How to use

The basics are as follows.

  1. Execute the initialization function timetestlog_init
  2. Add the function timetestlog_store_printf instead of printf to the place where you want to put the log.
  3. Execute the end function timetestlog_exit and output the log

timetestlog.h


void * timetestlog_init(char *delimiter, size_t maxloglen, unsigned long maxstoresize);
int timetestlog_store_printf(void * handle, const char *format, ...);
void timetestlog_exit(void * handle);

timetestlog_init: initialization function - input --delimiter [in] It is possible to specify the delimiter between timestamp logs. If NULL, "". --maxloglen [in] Maximum length of one output log line. Logs longer than this length will be truncated. --maxstoresize [in] Maximum number of logs to store. More logs than this number will be truncated. - return --Hand to be used in the subsequent API. NULL is an error

timetestlog_store_printf: Log save function. Just specify the handle obtained by timetestlog_init in the first argument of printf.

timetestlog_exit: Exit function. Specify the handle obtained by timetestlog_init.

code

It is listed on github below. https://github.com/developer-kikikaikai/speedtest

After cloning or downloading the code


cd speedtest/lib
make

Build with. Libtimelog.so and libtimelog.a will be created in the same folder.

Operating environment

Confirmed to work on Ubuntu 14.04 Desktop 64bit I think it will work on Linux OS.

Other

-Although I am careful to have a small overhead such as allocate only at init, I do not care about the overhead for ordinary functions such as va_start and memcpy.

Recommended Posts

Library for measuring execution time in Linux C applications
Get own process name at runtime in C / C ++ (for Linux)
Windows → linux Tips for bringing in data
MongoDB for the first time in Python
Tips for building large applications in Flask
Real Time Clock (RTC) Drivers for Linux
Let's try Linux for the first time
Communicate with I2C devices in Linux C
Template for creating command line applications in Python
How to use the C library in Python
Linux C / C ++ Build your own library creation environment
[Linux] [C] Get CPU time per process / thread
Created a header-only library management tool for C / C ++
Boost.NumPy Tutorial for Extending Python in C ++ (Practice)
How to limit the API to be published in the C language shared library of Linux