Skip to content

Commit

Permalink
add long query log for curl_exec
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Sadokhov committed Jul 6, 2023
1 parent ac23b3e commit 549f7f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion runtime/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "common/macos-ports.h"
#include "common/smart_ptrs/singleton.h"
#include "common/wrappers/to_array.h"
#include "common/dl-utils-lite.h"
#include "net/net-events.h"
#include "net/net-reactor.h"
#include "server/curl-adaptor.h"
Expand Down Expand Up @@ -661,6 +662,7 @@ bool f$curl_setopt_array(curl_easy easy_id, const array<mixed> &options) noexcep
}

mixed f$curl_exec(curl_easy easy_id) noexcept {
constexpr double long_curl_query = 2 * 10e-2; // 0.2 sec
auto *easy_context = get_context<EasyContext>(easy_id);
if (!easy_context) {
return false;
Expand All @@ -672,8 +674,13 @@ mixed f$curl_exec(curl_easy easy_id) noexcept {
}

easy_context->cleanup_for_next_request();
double request_start_time = dl_time();
easy_context->error_num = dl::critical_section_call(curl_easy_perform, easy_context->easy_handle);

double request_finish_time = dl_time();
if (request_finish_time - request_start_time >= long_curl_query) {
kprintf("LONG curl query : %f. Curl id = %d, url = %s\n", request_finish_time - request_start_time,
easy_context->uniq_id, easy_context->get_info(CURLINFO_EFFECTIVE_URL).as_string().c_str());
}
if (easy_context->error_num != CURLE_OK && easy_context->error_num != CURLE_PARTIAL_FILE) {
if (kphp_tracing::is_turned_on()) {
kphp_tracing::on_curl_exec_fail(easy_context->uniq_id, -easy_context->error_num); // error_num > 0, pass negative
Expand Down

0 comments on commit 549f7f2

Please sign in to comment.