Skip to content

Commit a9405ac

Browse files
Extend milestone api time tracking to remap. (#8520)
1 parent 2149f0a commit a9405ac

5 files changed

Lines changed: 61 additions & 39 deletions

File tree

proxy/http/HttpSM.cc

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,41 +98,6 @@ using lbw = ts::LocalBufferWriter<256>;
9898

9999
namespace
100100
{
101-
/// Update the milestone state given the milestones and timer.
102-
inline void
103-
milestone_update_api_time(TransactionMilestones &milestones, ink_hrtime &api_timer)
104-
{
105-
// Bit of funkiness - we set @a api_timer to be the negative value when we're tracking
106-
// non-active API time. In that case we need to make a note of it and flip the value back
107-
// to positive.
108-
if (api_timer) {
109-
ink_hrtime delta;
110-
bool active = api_timer >= 0;
111-
if (!active) {
112-
api_timer = -api_timer;
113-
}
114-
delta = Thread::get_hrtime_updated() - api_timer;
115-
api_timer = 0;
116-
// Zero or negative time is a problem because we want to signal *something* happened
117-
// vs. no API activity at all. This can happen due to graininess or real time
118-
// clock adjustment.
119-
if (delta <= 0) {
120-
delta = 1;
121-
}
122-
123-
if (0 == milestones[TS_MILESTONE_PLUGIN_TOTAL]) {
124-
milestones[TS_MILESTONE_PLUGIN_TOTAL] = milestones[TS_MILESTONE_SM_START];
125-
}
126-
milestones[TS_MILESTONE_PLUGIN_TOTAL] += delta;
127-
if (active) {
128-
if (0 == milestones[TS_MILESTONE_PLUGIN_ACTIVE]) {
129-
milestones[TS_MILESTONE_PLUGIN_ACTIVE] = milestones[TS_MILESTONE_SM_START];
130-
}
131-
milestones[TS_MILESTONE_PLUGIN_ACTIVE] += delta;
132-
}
133-
}
134-
}
135-
136101
// Unique state machine identifier
137102
std::atomic<int64_t> next_sm_id(0);
138103

@@ -1449,7 +1414,7 @@ HttpSM::state_common_wait_for_transform_read(HttpTransformInfo *t_info, HttpSMHa
14491414
// with setting and changing the default_handler
14501415
// function. As such, this is an entry point
14511416
// and needs to handle the reentrancy counter and
1452-
// deallocation the state machine if necessary
1417+
// deallocation of the state machine if necessary
14531418
//
14541419
int
14551420
HttpSM::state_api_callback(int event, void *data)
@@ -1459,7 +1424,7 @@ HttpSM::state_api_callback(int event, void *data)
14591424
ink_assert(reentrancy_count >= 0);
14601425
reentrancy_count++;
14611426

1462-
milestone_update_api_time(milestones, api_timer);
1427+
this->milestone_update_api_time();
14631428

14641429
STATE_ENTER(&HttpSM::state_api_callback, event);
14651430

@@ -1509,7 +1474,7 @@ HttpSM::state_api_callout(int event, void *data)
15091474
// the transaction got an event without the plugin calling TsHttpTxnReenable().
15101475
// The call chain does not recurse here if @a api_timer < 0 which means this call
15111476
// is the first from an event dispatch in this case.
1512-
milestone_update_api_time(milestones, api_timer);
1477+
this->milestone_update_api_time();
15131478
}
15141479

15151480
switch (event) {
@@ -1586,7 +1551,7 @@ plugins required to work with sni_routing.
15861551

15871552
hook->invoke(TS_EVENT_HTTP_READ_REQUEST_HDR + cur_hook_id, this);
15881553
if (api_timer > 0) { // true if the hook did not call TxnReenable()
1589-
milestone_update_api_time(milestones, api_timer);
1554+
this->milestone_update_api_time();
15901555
api_timer = -Thread::get_hrtime(); // set in order to track non-active callout duration
15911556
// which means that if we get back from the invoke with api_timer < 0 we're already
15921557
// tracking a non-complete callout from a chain so just let it ride. It will get cleaned
@@ -8514,3 +8479,38 @@ HttpSM::get_server_version(HTTPHdr &hdr) const
85148479
{
85158480
return this->server_txn->get_proxy_ssn()->get_version(hdr);
85168481
}
8482+
8483+
/// Update the milestone state given the milestones and timer.
8484+
void
8485+
HttpSM::milestone_update_api_time()
8486+
{
8487+
// Bit of funkiness - we set @a api_timer to be the negative value when we're tracking
8488+
// non-active API time. In that case we need to make a note of it and flip the value back
8489+
// to positive.
8490+
if (api_timer) {
8491+
ink_hrtime delta;
8492+
bool active = api_timer >= 0;
8493+
if (!active) {
8494+
api_timer = -api_timer;
8495+
}
8496+
delta = Thread::get_hrtime_updated() - api_timer;
8497+
api_timer = 0;
8498+
// Zero or negative time is a problem because we want to signal *something* happened
8499+
// vs. no API activity at all. This can happen due to graininess or real time
8500+
// clock adjustment.
8501+
if (delta <= 0) {
8502+
delta = 1;
8503+
}
8504+
8505+
if (0 == milestones[TS_MILESTONE_PLUGIN_TOTAL]) {
8506+
milestones[TS_MILESTONE_PLUGIN_TOTAL] = milestones[TS_MILESTONE_SM_START];
8507+
}
8508+
milestones[TS_MILESTONE_PLUGIN_TOTAL] += delta;
8509+
if (active) {
8510+
if (0 == milestones[TS_MILESTONE_PLUGIN_ACTIVE]) {
8511+
milestones[TS_MILESTONE_PLUGIN_ACTIVE] = milestones[TS_MILESTONE_SM_START];
8512+
}
8513+
milestones[TS_MILESTONE_PLUGIN_ACTIVE] += delta;
8514+
}
8515+
}
8516+
}

proxy/http/HttpSM.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class PostDataBuffers
204204
class HttpSM : public Continuation, public PluginUserArgs<TS_USER_ARGS_TXN>
205205
{
206206
friend class HttpPagesHandler;
207+
friend class HttpTransact;
207208

208209
public:
209210
HttpSM();
@@ -522,6 +523,9 @@ class HttpSM : public Continuation, public PluginUserArgs<TS_USER_ARGS_TXN>
522523
int find_http_resp_buffer_size(int64_t cl);
523524
int64_t server_transfer_init(MIOBuffer *buf, int hdr_size);
524525

526+
/// Update the milestones to track time spent in the plugin API.
527+
void milestone_update_api_time();
528+
525529
public:
526530
// TODO: Now that bodies can be empty, should the body counters be set to -1 ? TS-2213
527531
// Stats & Logging Info

proxy/http/HttpTransact.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8355,6 +8355,19 @@ ink_local_time()
83558355
//
83568356
// The stat functions
83578357
//
8358+
8359+
void
8360+
HttpTransact::milestone_start_api_time(State *s)
8361+
{
8362+
s->state_machine->api_timer = Thread::get_hrtime_updated();
8363+
}
8364+
8365+
void
8366+
HttpTransact::milestone_update_api_time(State *s)
8367+
{
8368+
s->state_machine->milestone_update_api_time();
8369+
}
8370+
83588371
void
83598372
HttpTransact::histogram_response_document_size(State *s, int64_t doc_size)
83608373
{

proxy/http/HttpTransact.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,8 @@ class HttpTransact
10711071
int64_t origin_server_request_body_size, int origin_server_response_header_size,
10721072
int64_t origin_server_response_body_size, int pushed_response_header_size,
10731073
int64_t pushed_response_body_size, const TransactionMilestones &milestones);
1074+
static void milestone_start_api_time(State *s);
1075+
static void milestone_update_api_time(State *s);
10741076
static void histogram_request_document_size(State *s, int64_t size);
10751077
static void histogram_response_document_size(State *s, int64_t size);
10761078
static void user_agent_connection_speed(State *s, ink_hrtime transfer_time, int64_t nbytes);

proxy/http/remap/RemapPlugins.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ RemapPlugins::run_plugin(RemapPluginInst *plugin)
5353
_s->os_response_plugin_inst = plugin;
5454
}
5555

56+
HttpTransact::milestone_start_api_time(_s);
5657
plugin_retcode = plugin->doRemap(reinterpret_cast<TSHttpTxn>(_s->state_machine), &rri);
58+
HttpTransact::milestone_update_api_time(_s);
59+
5760
// TODO: Deal with negative return codes here
5861
if (plugin_retcode < 0) {
5962
plugin_retcode = TSREMAP_NO_REMAP;

0 commit comments

Comments
 (0)