github.com/network-quality/goresponsiveness@v0.0.0-20240129151524-343954285090/stats/stats.go (about)

     1  /*
     2   * This file is part of Go Responsiveness.
     3   *
     4   * Go Responsiveness is free software: you can redistribute it and/or modify it under
     5   * the terms of the GNU General Public License as published by the Free Software Foundation,
     6   * either version 2 of the License, or (at your option) any later version.
     7   * Go Responsiveness is distributed in the hope that it will be useful, but WITHOUT ANY
     8   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
     9   * PARTICULAR PURPOSE. See the GNU General Public License for more details.
    10   *
    11   * You should have received a copy of the GNU General Public License along
    12   * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>.
    13   */
    14  
    15  package stats
    16  
    17  import (
    18  	"crypto/tls"
    19  	"fmt"
    20  	"net/http/httptrace"
    21  	"time"
    22  
    23  	"github.com/network-quality/goresponsiveness/utilities"
    24  )
    25  
    26  type TraceStats struct {
    27  	DnsStart               httptrace.DNSStartInfo
    28  	DnsDone                httptrace.DNSDoneInfo
    29  	ConnInfo               httptrace.GotConnInfo
    30  	HttpInfo               httptrace.WroteRequestInfo
    31  	TLSConnInfo            tls.ConnectionState
    32  	ConnectDoneError       error
    33  	DnsStartTime           time.Time
    34  	DnsDoneTime            time.Time
    35  	TLSStartTime           utilities.Optional[time.Time]
    36  	TLSDoneTime            utilities.Optional[time.Time]
    37  	ConnectStartTime       time.Time
    38  	ConnectDoneTime        time.Time
    39  	ConnectionReused       bool
    40  	GetConnectionStartTime time.Time
    41  	GetConnectionDoneTime  time.Time
    42  	HttpWroteRequestTime   time.Time
    43  	HttpResponseReadyTime  time.Time
    44  }
    45  
    46  func NewStats() *TraceStats {
    47  	return &TraceStats{}
    48  }
    49  
    50  func (s *TraceStats) String() string {
    51  	return fmt.Sprintf("DnsStart: %v\n", s.DnsStart) +
    52  		fmt.Sprintf("DnsDone: %v\n", s.DnsDone) +
    53  		fmt.Sprintf("ConnInfo: %v\n", s.ConnInfo) +
    54  		fmt.Sprintf("HttpInfo: %v\n", s.HttpInfo) +
    55  		fmt.Sprintf("TLSConnInfo: %v\n", s.TLSConnInfo) +
    56  		fmt.Sprintf("ConnectDoneError: %v\n", s.ConnectDoneError) +
    57  		fmt.Sprintf("DnsStartTime: %v\n", s.DnsStartTime) +
    58  		fmt.Sprintf("DnsDoneTime: %v\n", s.DnsDoneTime) +
    59  		fmt.Sprintf("TLSDoneTime: %v\n", s.TLSDoneTime) +
    60  		fmt.Sprintf("ConnectStartTime: %v\n", s.ConnectStartTime) +
    61  		fmt.Sprintf("ConnectDoneTime: %v\n", s.ConnectDoneTime) +
    62  		fmt.Sprintf("ConnectionReused: %v\n", s.ConnectionReused) +
    63  		fmt.Sprintf("GetConnectionStartTime: %v\n", s.GetConnectionStartTime) +
    64  		fmt.Sprintf("GetConnectionDoneTime: %v\n", s.GetConnectionDoneTime) +
    65  		fmt.Sprintf("HttpResponseReadyTime: %v\n", s.HttpResponseReadyTime)
    66  }