-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
244 lines (220 loc) · 6.79 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* client.c
*
* 2006-2007 Copyright (c)
* Robert Iakobashvili, <coroberti@gmail.com>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// must be the first include
#include "fdsetsize.h"
#include "client.h"
#include "batch.h"
/*
Accessors to the flags-counters of headers.
Incrementing counters for the flags-counters of headers.
*/
int first_hdr_req (client_context* cctx)
{
return cctx->first_hdr_req;
}
void first_hdr_req_inc (client_context* cctx)
{
cctx->first_hdr_req++;
}
int first_hdr_1xx (client_context* cctx)
{
return cctx->first_hdr_1xx;
}
void first_hdr_1xx_inc (client_context* cctx)
{
cctx->first_hdr_1xx++;
}
int first_hdr_2xx (client_context* cctx)
{
return cctx->first_hdr_2xx;
}
void first_hdr_2xx_inc (client_context* cctx)
{
cctx->first_hdr_2xx++;
}
int first_hdr_3xx (client_context* cctx)
{
return cctx->first_hdr_3xx++;
}
void first_hdr_3xx_inc (client_context* cctx)
{
cctx->first_hdr_3xx++;
}
int first_hdr_4xx (client_context* cctx)
{
return cctx->first_hdr_4xx;
}
void first_hdr_4xx_inc (client_context* cctx)
{
cctx->first_hdr_4xx++;
}
int first_hdr_5xx (client_context* cctx)
{
return cctx->first_hdr_5xx;
}
void first_hdr_5xx_inc (client_context* cctx)
{
cctx->first_hdr_5xx++;
}
/*
Reseting to zero counters for the flags-counters of headers.
*/
void first_hdrs_clear_all (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_1xx = cctx->first_hdr_2xx =
cctx->first_hdr_3xx = cctx->first_hdr_4xx = cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_req (client_context* cctx)
{
cctx->first_hdr_1xx = cctx->first_hdr_2xx = cctx->first_hdr_3xx =
cctx->first_hdr_4xx = cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_1xx (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_2xx = cctx->first_hdr_3xx =
cctx->first_hdr_4xx = cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_2xx (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_3xx = cctx->first_hdr_4xx =
cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_3xx (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_2xx = cctx->first_hdr_4xx = cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_4xx (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_2xx = cctx->first_hdr_3xx = cctx->first_hdr_5xx = 0;
}
void first_hdrs_clear_non_5xx (client_context* cctx)
{
cctx->first_hdr_req = cctx->first_hdr_2xx = cctx->first_hdr_4xx = cctx->first_hdr_3xx = 0;
}
void stat_data_out_add (client_context* cctx, unsigned long bytes)
{
cctx->st.data_out += bytes;
cctx->is_https ? (cctx->bctx->https_delta.data_out += bytes) :
(cctx->bctx->http_delta.data_out += bytes);
}
void stat_data_in_add (client_context* cctx, unsigned long bytes)
{
cctx->st.data_in += bytes;
cctx->is_https ? (cctx->bctx->https_delta.data_in += bytes) :
(cctx->bctx->http_delta.data_in += bytes);
}
void stat_err_inc (client_context* cctx)
{
cctx->st.other_errs++;
cctx->is_https ? cctx->bctx->https_delta.other_errs++ :
cctx->bctx->http_delta.other_errs++;
}
void stat_url_timeout_err_inc (client_context* cctx)
{
cctx->st.url_timeout_errs++;
cctx->is_https ? cctx->bctx->https_delta.url_timeout_errs++ :
cctx->bctx->http_delta.url_timeout_errs++;
}
void stat_req_inc (client_context* cctx)
{
cctx->st.requests++;
cctx->is_https ? cctx->bctx->https_delta.requests++ :
cctx->bctx->http_delta.requests++;
}
void stat_1xx_inc (client_context* cctx)
{
cctx->st.resp_1xx++;
cctx->is_https ? cctx->bctx->https_delta.resp_1xx++ :
cctx->bctx->http_delta.resp_1xx++;
}
void stat_2xx_inc (client_context* cctx)
{
cctx->st.resp_2xx++;
cctx->is_https ? cctx->bctx->https_delta.resp_2xx++ :
cctx->bctx->http_delta.resp_2xx++;
}
void stat_3xx_inc (client_context* cctx)
{
cctx->st.resp_3xx++;
cctx->is_https ? cctx->bctx->https_delta.resp_3xx++ :
cctx->bctx->http_delta.resp_3xx++;
}
void stat_4xx_inc (client_context* cctx)
{
cctx->st.resp_4xx++;
cctx->is_https ? cctx->bctx->https_delta.resp_4xx++ :
cctx->bctx->http_delta.resp_4xx++;
}
void stat_5xx_inc (client_context* cctx)
{
cctx->st.resp_5xx++;
cctx->is_https ? cctx->bctx->https_delta.resp_5xx++ :
cctx->bctx->http_delta.resp_5xx++;
}
void stat_appl_delay_add (client_context* cctx, unsigned long resp_timestamp)
{
if (resp_timestamp > cctx->req_sent_timestamp)
{
if (cctx->is_https)
{
cctx->bctx->https_delta.appl_delay =
(cctx->bctx->https_delta.appl_delay * cctx->bctx->https_delta.appl_delay_points +
resp_timestamp - cctx->req_sent_timestamp) / ++cctx->bctx->https_delta.appl_delay_points;
}
else
{
cctx->bctx->http_delta.appl_delay =
(cctx->bctx->http_delta.appl_delay * cctx->bctx->http_delta.appl_delay_points +
resp_timestamp - cctx->req_sent_timestamp) / ++cctx->bctx->http_delta.appl_delay_points;
}
}
}
void stat_appl_delay_2xx_add (client_context* cctx, unsigned long resp_timestamp)
{
if (resp_timestamp > cctx->req_sent_timestamp)
{
if (cctx->is_https)
{
cctx->bctx->https_delta.appl_delay_2xx =
(cctx->bctx->https_delta.appl_delay_2xx * cctx->bctx->https_delta.appl_delay_2xx_points +
resp_timestamp - cctx->req_sent_timestamp) / ++cctx->bctx->https_delta.appl_delay_2xx_points;
}
else
{
cctx->bctx->http_delta.appl_delay_2xx =
(cctx->bctx->http_delta.appl_delay_2xx * cctx->bctx->http_delta.appl_delay_2xx_points +
resp_timestamp - cctx->req_sent_timestamp) / ++cctx->bctx->http_delta.appl_delay_2xx_points;
}
}
}
void dump_client (FILE* file, client_context* cctx)
{
if (!file || !cctx)
return;
fprintf (file,
"%s,cycles:%ld,state:%d,b-in:%lld,b-out:%lld,req:%ld,1xx:%ld,2xx:%ld,3xx:%ld,4xx:%ld,5xx:%ld,err:%ld,T-err:%ld\n",
cctx->client_name, cctx->cycle_num, cctx->client_state,
cctx->st.data_in, cctx->st.data_out, cctx->st.requests,
cctx->st.resp_1xx, cctx->st.resp_2xx, cctx->st.resp_3xx, cctx->st.resp_4xx, cctx->st.resp_5xx,
cctx->st.other_errs, cctx->st.url_timeout_errs);
fflush (file);
}