(cherry picked from commit 1e10dbe5c565a621eab050c1c0d44a499318e34c) # Conflicts: # CMakeLists.txt # src/modules/service_sign.c
162 lines
No EOL
4.6 KiB
C
162 lines
No EOL
4.6 KiB
C
#include "timer.h"
|
|
#include "logger.h"
|
|
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
|
|
#define ENV_SIGN_LOG_TIME "SIGN_LOG_TIME"
|
|
|
|
void
|
|
init_timers(timer_context_t *ctx)
|
|
{
|
|
const char* slt = getenv(ENV_SIGN_LOG_TIME);
|
|
if (slt != NULL) {
|
|
LOG_INFO("environment variable '" ENV_SIGN_LOG_TIME "'='%s' -> timings logging: ON", slt);
|
|
ctx->is_timer_on = true;
|
|
} else {
|
|
LOG_INFO("environment variable '" ENV_SIGN_LOG_TIME "' does not exist "
|
|
"-> timings logging: OFF");
|
|
ctx->is_timer_on = false;
|
|
}
|
|
}
|
|
|
|
static inline void
|
|
set_timer(bool is_timer_on, struct timeval *timer, const char *timer_name)
|
|
{
|
|
if (!is_timer_on) {
|
|
return;
|
|
}
|
|
|
|
if (gettimeofday(timer, NULL)) {
|
|
LOG_WARN("gettimeofday(%s) failed. Desc: %s", timer_name, strerror(errno));
|
|
}
|
|
}
|
|
|
|
static inline time_t
|
|
get_diff(const struct timeval *tv_start, const struct timeval *tv_end)
|
|
{
|
|
return (tv_end->tv_sec - tv_start->tv_sec) * 1000
|
|
+ (tv_end->tv_usec - tv_start->tv_usec) / 1000;
|
|
}
|
|
|
|
void
|
|
timer_on_fcgi_sign_handler_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_handler_start, "sign_handler_start");
|
|
}
|
|
|
|
void
|
|
timer_on_fcgi_sign_handler_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_handler_end, "sign_handler_end");
|
|
}
|
|
|
|
void
|
|
timer_on_sign_content_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_content_start, "sign_content_start");
|
|
}
|
|
|
|
void
|
|
timer_on_sign_content_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_content_end, "sign_content_end");
|
|
}
|
|
|
|
void
|
|
timer_on_verify_cert_chain_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->verify_cert_chain_start, "verify_cert_chain_start");
|
|
}
|
|
|
|
void
|
|
timer_on_verify_cert_chain_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->verify_cert_chain_end, "verify_cert_chain_end");
|
|
}
|
|
|
|
void
|
|
timer_on_acquire_private_key_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->acquire_private_key_start, "acquire_private_key_start");
|
|
}
|
|
|
|
void
|
|
timer_on_acquire_private_key_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->acquire_private_key_end, "acquire_private_key_end");
|
|
}
|
|
|
|
void timer_on_sign_hash_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_hash_start, "sign_hash_start");
|
|
}
|
|
|
|
void timer_on_sign_hash_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->sign_hash_end, "sign_hash_end");
|
|
}
|
|
|
|
void
|
|
timer_on_get_cert_chain_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->get_cert_chain_start, "get_cert_chain_start");
|
|
}
|
|
|
|
void
|
|
timer_on_get_cert_chain_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->get_cert_chain_end, "get_cert_chain_end");
|
|
}
|
|
|
|
void timer_on_cryptopro_verify_enter(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->cryptopro_verify_start, "cryptopro_verify_start");
|
|
}
|
|
|
|
void timer_on_cryptopro_verify_exit(timer_context_t *ctx)
|
|
{
|
|
set_timer(ctx->is_timer_on, &ctx->cryptopro_verify_end, "cryptopro_verify_end");
|
|
}
|
|
|
|
void
|
|
timer_log_sign(const timer_context_t *ctx)
|
|
{
|
|
if (!ctx->is_timer_on) {
|
|
return;
|
|
}
|
|
|
|
time_t diff_sign_handler = get_diff(&ctx->sign_handler_start, &ctx->sign_handler_end);
|
|
time_t diff_sign_content = get_diff(&ctx->sign_content_start, &ctx->sign_content_end);
|
|
time_t diff_verify_cert_chain = get_diff(&ctx->verify_cert_chain_start,
|
|
&ctx->verify_cert_chain_end);
|
|
time_t diff_get_cert_chain = get_diff(&ctx->get_cert_chain_start, &ctx->get_cert_chain_end);
|
|
time_t diff_acquire_private_key = get_diff(&ctx->acquire_private_key_start,
|
|
&ctx->acquire_private_key_end);
|
|
time_t diff_sign_hash = get_diff(&ctx->sign_hash_start, &ctx->sign_hash_end);
|
|
|
|
LOG_INFO("sign_handler: %ld sign_content: %ld verify_cert_chain: %ld "
|
|
"get_cert_chain: %ld acquire_private_key: %ld sign_hash: %ld",
|
|
diff_sign_handler,
|
|
diff_sign_content,
|
|
diff_verify_cert_chain,
|
|
diff_get_cert_chain,
|
|
diff_acquire_private_key,
|
|
diff_sign_hash);
|
|
}
|
|
|
|
void
|
|
timer_log_verify(const timer_context_t *ctx)
|
|
{
|
|
if (!ctx->is_timer_on) {
|
|
return;
|
|
}
|
|
|
|
time_t diff_verify_handler = get_diff(&ctx->cryptopro_verify_start, &ctx->cryptopro_verify_end);
|
|
time_t diff_verify_cert_chain = get_diff(&ctx->verify_cert_chain_start,
|
|
&ctx->verify_cert_chain_end);
|
|
|
|
LOG_INFO("verify_handler: %ld verify_cert_chain: %ld",
|
|
diff_verify_handler,
|
|
diff_verify_cert_chain);
|
|
} |