From 1febfcc16daa57428405cda9f68aa5d829a9a28c Mon Sep 17 00:00:00 2001 From: Jelle Foks Date: Fri, 16 Aug 2024 12:35:58 -0700 Subject: [PATCH] Log thread and process CPU time --- .../http_stream_factory_job_controller.cc | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/net/http/http_stream_factory_job_controller.cc b/net/http/http_stream_factory_job_controller.cc index 3a5d2635b586..33e9df70032a 100644 --- a/net/http/http_stream_factory_job_controller.cc +++ b/net/http/http_stream_factory_job_controller.cc @@ -4,6 +4,7 @@ #include "net/http/http_stream_factory_job_controller.h" +#include #include #include @@ -23,6 +24,7 @@ #include "net/log/net_log_source.h" #include "net/log/net_log_with_source.h" #include "net/spdy/spdy_session.h" +#include "starboard/common/string.h" #include "url/url_constants.h" namespace net { @@ -61,6 +63,25 @@ std::unique_ptr NetLogJobControllerCallback( return std::move(dict); } +namespace { +static clockid_t clockid = 0; +std::string print_clock(const char* msg, clockid_t cid) { + struct timespec ts; + if (clock_gettime(cid, &ts) != -1) + return starboard::FormatString(" %s %ld.%06ld", msg, ts.tv_sec, + ts.tv_nsec / 1000); + return std::string(); +} + +std::string print_clocks() { + if (clockid == 0) { + pthread_getcpuclockid(pthread_self(), &clockid); + } + return print_clock("thread", clockid) + + print_clock("process", CLOCK_PROCESS_CPUTIME_ID); +} +} // namespace + HttpStreamFactory::JobController::JobController( HttpStreamFactory* factory, HttpStreamRequest::Delegate* delegate, @@ -256,9 +277,9 @@ void HttpStreamFactory::JobController::OnStreamReady( DCHECK(stream); { - const char* jobtypename[] = {"main", "alternative", "dns_alpn_h3", "preconnect", - "preconnect_dns_alpn_h3"}; - LOG(INFO) << __FUNCTION__ << " negotiated_protocol = " + const char* jobtypename[] = {"main", "alternative", "dns_alpn_h3", + "preconnect", "preconnect_dns_alpn_h3"}; + LOG(INFO) << __FUNCTION__ << print_clocks() << " negotiated_protocol = " << NextProtoToString(job->negotiated_protocol()) << " was_alpn_negotiated=" << job->was_alpn_negotiated() << " using_spdy=" << job->using_spdy() @@ -509,7 +530,6 @@ void HttpStreamFactory::JobController::OnNewSpdySessionReady( // Notify |request_|. if (!is_preconnect_ && !is_job_orphaned) { - DCHECK(request_); // The first case is the usual case.