You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2012/06/14 22:42:20 UTC

git commit: TS-1301 Add new API, TSHttpTxnMilestoneGet(), to get various txn timers

Updated Branches:
  refs/heads/master bc13c5e08 -> 50f981cec


TS-1301 Add new API, TSHttpTxnMilestoneGet(), to get various txn timers


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/50f981ce
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/50f981ce
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/50f981ce

Branch: refs/heads/master
Commit: 50f981cec24bcba79ddd1ea9974192185817bf9d
Parents: bc13c5e
Author: Leif Hedstrom <zw...@apache.org>
Authored: Thu Jun 14 14:41:14 2012 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Thu Jun 14 14:41:14 2012 -0600

----------------------------------------------------------------------
 CHANGES                     |    3 +
 iocore/net/P_UDPNet.h       |    2 +-
 proxy/InkAPI.cc             |   89 +++++++++++++++++++++++++++++--------
 proxy/StatSystem.cc         |   23 ----------
 proxy/StatSystem.h          |   58 +++++++-----------------
 proxy/api/ts/experimental.h |    6 ---
 proxy/api/ts/ts.h.in        |   45 +++++++++++++++++++
 proxy/http/HttpSM.cc        |   14 +++---
 8 files changed, 142 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index ca97af3..579964e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 3.3.0
+  *) [TS-1301] Add a new API, TSHttpTxnMilestoneGet(), which can be used
+   to retrieve the various internal milestone timers from a plugin.
+
   *) [TS-1295] Don't assume root privileges during make install.
    Author: Jan-Frode Myklebust
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/iocore/net/P_UDPNet.h
----------------------------------------------------------------------
diff --git a/iocore/net/P_UDPNet.h b/iocore/net/P_UDPNet.h
index 04a21a0..403152d 100644
--- a/iocore/net/P_UDPNet.h
+++ b/iocore/net/P_UDPNet.h
@@ -194,7 +194,7 @@ public:
     ink_assert(nPackets >= 0);
     return nPackets;
   };
-  void invariant();
+
   bool IsCancelledPacket(UDPPacketInternal * p)
   {
     // discard packets that'll never get sent...

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index f6fc033..55aca3f 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -5909,32 +5909,81 @@ TSHttpTxnPushedRespBodyBytesGet(TSHttpTxn txnp)
   return sm->pushed_response_body_bytes;
 }
 
+// Get a particular milestone hrtime'r. Note that this can return 0, which means it has not
+// been set yet.
 TSReturnCode
-TSHttpTxnStartTimeGet(TSHttpTxn txnp, ink_hrtime *start_time)
+TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, ink_hrtime *time)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
-
+  sdk_assert(sdk_sanity_check_null_ptr(time) == TS_SUCCESS);
   HttpSM *sm = (HttpSM *) txnp;
+  TSReturnCode ret = TS_SUCCESS;
 
-  if (sm->milestones.ua_begin == 0)
-    return TS_ERROR;
-
-  *start_time = sm->milestones.ua_begin;
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSHttpTxnEndTimeGet(TSHttpTxn txnp, ink_hrtime *end_time)
-{
-  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
-
-  HttpSM *sm = (HttpSM *) txnp;
-
-  if (sm->milestones.ua_close == 0)
-    return TS_ERROR;
+  switch(milestone) {
+  case TS_MILESTONE_UA_BEGIN:
+    *time = sm->milestones.ua_begin;
+    break;
+  case TS_MILESTONE_UA_READ_HEADER_DONE:
+    *time = sm->milestones.ua_read_header_done;
+    break;
+  case TS_MILESTONE_UA_BEGIN_WRITE:
+    *time = sm->milestones.ua_begin_write;
+    break;
+  case TS_MILESTONE_UA_CLOSE:
+    *time = sm->milestones.ua_close;
+    break;
+  case TS_MILESTONE_SERVER_FIRST_CONNECT:
+    *time = sm->milestones.server_first_connect;
+    break;
+  case TS_MILESTONE_SERVER_CONNECT:
+    *time = sm->milestones.server_connect;
+    break;
+  case TS_MILESTONE_SERVER_CONNECT_END:
+    *time = sm->milestones.server_connect_end;
+    break;
+  case TS_MILESTONE_SERVER_BEGIN_WRITE:
+    *time = sm->milestones.server_begin_write;
+    break;
+  case TS_MILESTONE_SERVER_FIRST_READ:
+    *time = sm->milestones.server_first_read;
+    break;
+  case TS_MILESTONE_SERVER_READ_HEADER_DONE:
+    *time = sm->milestones.server_read_header_done;
+    break;
+  case TS_MILESTONE_SERVER_CLOSE:
+    *time = sm->milestones.server_close;
+    break;
+  case TS_MILESTONE_CACHE_OPEN_READ_BEGIN:
+    *time = sm->milestones.cache_open_read_begin;
+    break;
+  case TS_MILESTONE_CACHE_OPEN_READ_END:
+    *time = sm->milestones.cache_open_read_end;
+    break;
+  case TS_MILESTONE_CACHE_OPEN_WRITE_BEGIN:
+    *time = sm->milestones.cache_open_write_begin;
+    break;
+  case TS_MILESTONE_CACHE_OPEN_WRITE_END:
+    *time = sm->milestones.cache_open_write_end;
+    break;
+  case TS_MILESTONE_DNS_LOOKUP_BEGIN:
+    *time = sm->milestones.dns_lookup_begin;
+    break;
+  case TS_MILESTONE_DNS_LOOKUP_END:
+    *time = sm->milestones.dns_lookup_end;
+    break;
+  case TS_MILESTONE_SM_START:
+    *time = sm->milestones.sm_start;
+    break;
+  case TS_MILESTONE_SM_FINISH:
+    *time = sm->milestones.sm_finish;
+    break;
+  default:
+    *time = -1;
+    ret = TS_ERROR;
+    break;
+  }
 
-  *end_time = sm->milestones.ua_close;
-  return TS_SUCCESS;
+  return ret;
 }
 
 TSReturnCode

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/StatSystem.cc
----------------------------------------------------------------------
diff --git a/proxy/StatSystem.cc b/proxy/StatSystem.cc
index fd46917..e643edc 100644
--- a/proxy/StatSystem.cc
+++ b/proxy/StatSystem.cc
@@ -800,26 +800,3 @@ http_trans_stats_time_useconds_cb(void *data, void *res)
   *(float *) res = r;
   return res;
 }
-
-//////////////////////////////////////////////////////////////////////////////
-//
-//  TransactionMilestones::TransactionMilestones()
-//
-//////////////////////////////////////////////////////////////////////////////
-TransactionMilestones::TransactionMilestones()
-:
-ua_begin(0), ua_read_header_done(0), ua_begin_write(0), ua_close(0), server_first_connect(0), server_connect(0),
-  // server_connect_end(0),
-  // server_begin_write(0),
-  server_first_read(0), server_read_header_done(0), server_close(0), cache_open_read_begin(0), cache_open_read_end(0),
-  // cache_read_begin(0),
-  // cache_read_end(0),
-  // cache_open_write_begin(0),
-  // cache_open_write_end(0),
-  // cache_write_begin(0),
-  // cache_write_end(0),
-  dns_lookup_begin(0), dns_lookup_end(0), sm_start(0),  // init
-  sm_finish(0)                  // kill_this
-{
-  return;
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/StatSystem.h
----------------------------------------------------------------------
diff --git a/proxy/StatSystem.h b/proxy/StatSystem.h
index 5275e45..ccfff96 100644
--- a/proxy/StatSystem.h
+++ b/proxy/StatSystem.h
@@ -49,6 +49,14 @@
 class TransactionMilestones
 {
 public:
+  TransactionMilestones()
+    : ua_begin(0), ua_read_header_done(0), ua_begin_write(0), ua_close(0), server_first_connect(0), server_connect(0),
+      server_connect_end(0), server_begin_write(0), server_first_read(0), server_read_header_done(0), server_close(0),
+      cache_open_read_begin(0), cache_open_read_end(0), cache_open_write_begin(0), cache_open_write_end(0),
+      dns_lookup_begin(0), dns_lookup_end(0), sm_start(0), sm_finish(0)
+      { }
+
+
   ////////////////////////////////////////////////////////
   // user agent:                                        //
   // user_agent_begin represents the time this          //
@@ -67,25 +75,16 @@ public:
   ////////////////////////////////////////////////////////
   ink_hrtime server_first_connect;
   ink_hrtime server_connect;
-  // ink_hrtime  server_connect_end;
-  // ink_hrtime  server_begin_write;            //  http only
+  ink_hrtime server_connect_end;
+  ink_hrtime server_begin_write;            //  http only
   ink_hrtime server_first_read; //  http only
   ink_hrtime server_read_header_done;   //  http only
   ink_hrtime server_close;
 
-  /////////////////////////////////////////////
-  // cache:                                  //
-  // all or some variables may not be set in //
-  // certain conditions                      //
-  /////////////////////////////////////////////
   ink_hrtime cache_open_read_begin;
   ink_hrtime cache_open_read_end;
-  // ink_hrtime  cache_read_begin;
-  // ink_hrtime  cache_read_end;
-  // ink_hrtime  cache_open_write_begin;
-  // ink_hrtime  cache_open_write_end;
-  // ink_hrtime  cache_write_begin;
-  // ink_hrtime  cache_write_end;
+  ink_hrtime cache_open_write_begin;
+  ink_hrtime cache_open_write_end;
 
   ink_hrtime dns_lookup_begin;
   ink_hrtime dns_lookup_end;
@@ -96,36 +95,13 @@ public:
   ink_hrtime sm_start;
   ink_hrtime sm_finish;
 
-    TransactionMilestones();
-#ifdef DEBUG
-  bool invariant();
-#endif
+  // TODO: Should we instrument these at some point?
+  // ink_hrtime  cache_read_begin;
+  // ink_hrtime  cache_read_end;
+  // ink_hrtime  cache_write_begin;
+  // ink_hrtime  cache_write_end;
 };
 
-typedef enum
-{
-  NO_HTTP_TRANSACTION_MILESTONES = 0,
-  client_accept_time,           // u_a_accept - u_a_begin
-  client_header_read_time,      // u_a_read_header_done - u_a_begin_read
-  client_response_write_time,   // u_a_close - u_a_begin_write
-  //
-  cache_lookup_time,            // cache_lookup_end - cache_lookup_begin
-  cache_update_time,            // cache_update_end - cache_update_begin
-  cache_open_read_time,         // cache_open_read_end - cache_open_read_begin
-  cache_read_time,              // cache_read_end - cache_read_begin
-  cache_open_write_time,        // cache_open_write_end - cache_open_write_begin
-  cache_write_time,             // cache_write_end - cache_write_begin
-  //
-  server_open_time,             // o_s_open_end - o_s_open_begin
-  server_response_time,         // o_s_begin_read - o_s_begin_write
-  server_read_time,             // o_s_read_header_done - o_s_begin_read
-  //
-  TOTAL_HTTP_TRANSACTION_MILESTONES
-} HttpTransactionMilestone_t;
-
-extern ink_hrtime GlobalHttpMilestones[TOTAL_HTTP_TRANSACTION_MILESTONES];
-extern ink_hrtime TenSecondHttpMilestones[TOTAL_HTTP_TRANSACTION_MILESTONES];
-
 
 // Modularization Project: Build w/o thread-local-dyn-stats
 // temporarily until we switch over to librecords.  Revert to old

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/api/ts/experimental.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index 08622f8..7263bce 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -138,12 +138,6 @@ extern "C"
 #define TS_HRTIME_USECONDS(_x) HRTIME_USECONDS(_x)
 #define TS_HRTIME_NSECONDS(_x) HRTIME_NSECONDS(_x)
 
-  /****************************************************************************
-   *  Get time when Http TXN started / ended
-   ****************************************************************************/
-  tsapi TSReturnCode TSHttpTxnStartTimeGet(TSHttpTxn txnp, TSHRTime *start_time);
-  tsapi TSReturnCode TSHttpTxnEndTimeGet(TSHttpTxn txnp, TSHRTime *end_time);
-
   tsapi TSReturnCode TSHttpTxnCachedRespTimeGet(TSHttpTxn txnp, time_t *resp_time);
 
   /* ===== Cache ===== */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/api/ts/ts.h.in
----------------------------------------------------------------------
diff --git a/proxy/api/ts/ts.h.in b/proxy/api/ts/ts.h.in
index 2991fcf..5e13a5d 100644
--- a/proxy/api/ts/ts.h.in
+++ b/proxy/api/ts/ts.h.in
@@ -638,6 +638,34 @@ extern "C"
 
   typedef int64_t TSHRTime;
 
+  /* The TSMilestonesType is an enum defining all the various milestones ("timers") that
+     we track for a request. */
+  typedef enum
+    {
+      TS_MILESTONE_NULL = -1,
+      TS_MILESTONE_UA_BEGIN,
+      TS_MILESTONE_UA_READ_HEADER_DONE,
+      TS_MILESTONE_UA_BEGIN_WRITE,
+      TS_MILESTONE_UA_CLOSE,
+      TS_MILESTONE_SERVER_FIRST_CONNECT,
+      TS_MILESTONE_SERVER_CONNECT,
+      TS_MILESTONE_SERVER_CONNECT_END,
+      TS_MILESTONE_SERVER_BEGIN_WRITE,
+      TS_MILESTONE_SERVER_FIRST_READ,
+      TS_MILESTONE_SERVER_READ_HEADER_DONE,
+      TS_MILESTONE_SERVER_CLOSE,
+      TS_MILESTONE_CACHE_OPEN_READ_BEGIN,
+      TS_MILESTONE_CACHE_OPEN_READ_END,
+      TS_MILESTONE_CACHE_OPEN_WRITE_BEGIN,
+      TS_MILESTONE_CACHE_OPEN_WRITE_END,
+      TS_MILESTONE_DNS_LOOKUP_BEGIN,
+      TS_MILESTONE_DNS_LOOKUP_END,
+      TS_MILESTONE_SM_START,
+      TS_MILESTONE_SM_FINISH,
+      TS_MILESTONE_LAST_ENTRY
+    } TSMilestonesType;
+
+
   /* These typedefs are used with the corresponding TSMgmt*Get functions
      for storing the values retrieved by those functions. For example,
      TSMgmtCounterGet() retrieves an TSMgmtCounter. */
@@ -3207,6 +3235,23 @@ extern "C"
   tsapi TSReturnCode TSBase64Decode(const char *str, size_t str_len, unsigned char *dst, size_t dst_size, size_t *length);
   tsapi TSReturnCode TSBase64Encode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length);
 
+  /* Get milestone timers, useful for measuring where we are spending time in the transaction processing */
+  /**
+     Return the particular milestone timer for the transaction. If 0 is returned, it means
+     the transaction has not yet reached that milestone. Asking for an "unknown" milestone is
+     an error.
+
+     @param txnp the transaction pointer
+     @param milestone the requested milstone timer
+     was created.
+     @param time a pointer to a TSHRTime where we will store the timer
+
+     @return @c TS_SUCCESS if the milestone is supported, TS_ERROR otherwise
+
+  */
+  tsapi TSReturnCode TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, TSHRTime *time);
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/50f981ce/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 1545de8..81cc10d 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -1055,7 +1055,7 @@ HttpSM::state_raw_http_server_open(int event, void *data)
 {
   STATE_ENTER(&HttpSM::state_raw_http_server_open, event);
   ink_assert(server_entry == NULL);
-  // milestones.server_connect_end = ink_get_hrtime();
+  milestones.server_connect_end = ink_get_hrtime();
   NetVConnection *netvc = NULL;
 
   pending_action = NULL;
@@ -1606,7 +1606,7 @@ HttpSM::state_http_server_open(int event, void *data)
   // TODO decide whether to uncomment after finish testing redirect
   // ink_assert(server_entry == NULL);
   pending_action = NULL;
-  // milestones.server_connect_end = ink_get_hrtime();
+  milestones.server_connect_end = ink_get_hrtime();
   HttpServerSession *session;
 
   switch (event) {
@@ -2274,8 +2274,8 @@ HttpSM::state_icp_lookup(int event, void *data)
 int
 HttpSM::state_cache_open_write(int event, void *data)
 {
-STATE_ENTER(&HttpSM:state_cache_open_write, event);
-  // milestones.cache_open_write_end = ink_get_hrtime();
+  STATE_ENTER(&HttpSM:state_cache_open_write, event);
+  milestones.cache_open_write_end = ink_get_hrtime();
   pending_action = NULL;
 
   switch (event) {
@@ -4200,6 +4200,7 @@ HttpSM::do_cache_prepare_write()
 {
   // statistically no need to retry when we are trying to lock
   // LOCK_URL_SECOND url because the server's behavior is unlikely to change
+  milestones.cache_open_write_begin = ink_get_hrtime();
   bool retry = (t_state.api_lock_url == HttpTransact::LOCK_URL_FIRST);
   do_cache_prepare_action(&cache_sm, t_state.cache_info.object_read, retry);
 }
@@ -5451,7 +5452,7 @@ HttpSM::setup_server_send_request()
   /*if (server_session->www_auth_content && t_state.www_auth_content == HttpTransact::CACHE_AUTH_NONE) {
     t_state.www_auth_content = HttpTransact::CACHE_AUTH_TRUE;
   }*/
-  // milestones.server_begin_write = ink_get_hrtime();
+  milestones.server_begin_write = ink_get_hrtime();
   server_entry->write_vio = server_entry->vc->do_io_write(this, hdr_length, buf_start);
 }
 
@@ -6143,8 +6144,7 @@ HttpSM::setup_blind_tunnel(bool send_response_hdr)
   IOBufferReader *r_from = from_ua_buf->alloc_reader();
   IOBufferReader *r_to = to_ua_buf->alloc_reader();
 
-  // milestones.server_begin_write = ink_get_hrtime();
-
+  milestones.server_begin_write = ink_get_hrtime();
   if (send_response_hdr) {
     client_response_hdr_bytes = write_response_header_into_buffer(&t_state.hdr_info.client_response, to_ua_buf);
   } else {