Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialized fork and added method -X option #539

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
obj/
wrk
wrc
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif

SRC := wrk.c net.c ssl.c aprintf.c stats.c script.c units.c \
ae.c zmalloc.c http_parser.c
BIN := wrk
BIN := wrc
VER ?= $(shell git describe --tags --always --dirty)

ODIR := obj
Expand Down
6 changes: 5 additions & 1 deletion src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static const struct luaL_Reg threadlib[] = {
{ NULL, NULL }
};

lua_State *script_create(char *file, char *url, char **headers) {
lua_State *script_create(char *file, char *url, char *method, char *data, char **headers) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
(void) luaL_dostring(L, "wrk = require \"wrk\"");
Expand Down Expand Up @@ -77,6 +77,10 @@ lua_State *script_create(char *file, char *url, char **headers) {
set_field(L, 4, "scheme", push_url_part(L, url, &parts, UF_SCHEMA));
set_field(L, 4, "host", push_url_part(L, url, &parts, UF_HOST));
set_field(L, 4, "port", push_url_part(L, url, &parts, UF_PORT));
lua_pushstring(L, method);
set_field(L, 4, "method", 0);
lua_pushstring(L, data);
set_field(L, 4, "body", 0);
set_fields(L, 4, fields);

lua_getfield(L, 4, "headers");
Expand Down
2 changes: 1 addition & 1 deletion src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "stats.h"
#include "wrk.h"

lua_State *script_create(char *, char *, char **);
lua_State *script_create(char *, char *, char *, char *, char **);

bool script_resolve(lua_State *, char *, char *);
void script_setup(lua_State *, thread *);
Expand Down
20 changes: 17 additions & 3 deletions src/wrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ static struct config {
bool dynamic;
bool latency;
char *host;
char *method;
char *data;
char *script;
SSL_CTX *ctx;
} cfg;
Expand Down Expand Up @@ -49,7 +51,9 @@ static void usage() {
" -t, --threads <N> Number of threads to use \n"
" \n"
" -s, --script <S> Load Lua script file \n"
" -X, --method <S> HTTP method (default: GET) \n"
" -H, --header <H> Add header to request \n"
" --data <S> Body \n"
" --latency Print latency statistics \n"
" --timeout <T> Socket/request timeout \n"
" -v, --version Print version details \n"
Expand Down Expand Up @@ -92,7 +96,7 @@ int main(int argc, char **argv) {
statistics.requests = stats_alloc(MAX_THREAD_RATE_S);
thread *threads = zcalloc(cfg.threads * sizeof(thread));

lua_State *L = script_create(cfg.script, url, headers);
lua_State *L = script_create(cfg.script, url, cfg.method, cfg.data, headers);
if (!script_resolve(L, host, service)) {
char *msg = strerror(errno);
fprintf(stderr, "unable to connect to %s:%s %s\n", host, service, msg);
Expand All @@ -106,7 +110,7 @@ int main(int argc, char **argv) {
t->loop = aeCreateEventLoop(10 + cfg.connections * 3);
t->connections = cfg.connections / cfg.threads;

t->L = script_create(cfg.script, url, headers);
t->L = script_create(cfg.script, url, cfg.method, cfg.data, headers);
script_init(L, t, argc - optind, &argv[optind]);

if (i == 0) {
Expand Down Expand Up @@ -471,7 +475,9 @@ static struct option longopts[] = {
{ "duration", required_argument, NULL, 'd' },
{ "threads", required_argument, NULL, 't' },
{ "script", required_argument, NULL, 's' },
{ "method", required_argument, NULL, 'X' },
{ "header", required_argument, NULL, 'H' },
{ "data", required_argument, NULL, 'D' },
{ "latency", no_argument, NULL, 'L' },
{ "timeout", required_argument, NULL, 'T' },
{ "help", no_argument, NULL, 'h' },
Expand All @@ -488,8 +494,10 @@ static int parse_args(struct config *cfg, char **url, struct http_parser_url *pa
cfg->connections = 10;
cfg->duration = 10;
cfg->timeout = SOCKET_TIMEOUT_MS;
cfg->method = "GET";
cfg->data = "";

while ((c = getopt_long(argc, argv, "t:c:d:s:H:T:Lrv?", longopts, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "t:c:d:D:s:X:H:T:Lrv?", longopts, NULL)) != -1) {
switch (c) {
case 't':
if (scan_metric(optarg, &cfg->threads)) return -1;
Expand All @@ -503,9 +511,15 @@ static int parse_args(struct config *cfg, char **url, struct http_parser_url *pa
case 's':
cfg->script = optarg;
break;
case 'X':
cfg->method = optarg;
break;
case 'H':
*header++ = optarg;
break;
case 'D':
cfg->data = optarg;
break;
case 'L':
cfg->latency = true;
break;
Expand Down