Skip to content

Commit 8bcef41

Browse files
michaelgranzow-aviFelipe Zimmerle
authored andcommitted
Improve benchmark tool
Benchmark tool: proper initialization of intervention, get number of iterations from cmd-line, add help message.
1 parent e98be6d commit 8bcef41

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

test/benchmark/benchmark.cc

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,38 @@ char ip[] = "200.249.12.31";
6565

6666
char rules_file[] = "basic_rules.conf";
6767

68+
const char* const help_message = "Usage: benchmark [num_iterations|-h|-?|--help]";
6869

69-
#define NUM_REQUESTS 10000
70+
int main(int argc, char *argv[]) {
7071

72+
unsigned long long NUM_REQUESTS(10000);
7173

72-
int main(int argc, char *argv[]) {
73-
int i = 0;
74+
if (argc > 1) {
75+
if (0 == strcmp(argv[1], "-h") ||
76+
0 == strcmp(argv[1], "-?") ||
77+
0 == strcmp(argv[1], "--help")) {
78+
std::cout << help_message << std::endl;
79+
return 0;
80+
}
81+
errno = 0;
82+
unsigned long long upper = strtoull(argv[1], 0, 10);
83+
if (!errno && upper) {
84+
NUM_REQUESTS = upper;
85+
} else {
86+
if (errno) {
87+
perror("Invalid number of iterations");
88+
} else {
89+
std::cerr << "Failed to convert '" << argv[1] << "' to integer value" << std::endl
90+
<< help_message << std::endl;
91+
return -1;
92+
}
93+
}
94+
}
95+
std::cout << "Doing " << NUM_REQUESTS << " transactions...\n";
7496
modsecurity::ModSecurity *modsec;
7597
modsecurity::Rules *rules;
7698
modsecurity::ModSecurityIntervention it;
77-
99+
modsecurity::intervention::reset(&it);
78100
modsec = new modsecurity::ModSecurity();
79101
modsec->setConnectorInformation("ModSecurity-benchmark v0.0.1-alpha" \
80102
" (ModSecurity benchmark utility)");
@@ -86,8 +108,8 @@ int main(int argc, char *argv[]) {
86108
return -1;
87109
}
88110

89-
for (i = 0; i < NUM_REQUESTS; i++) {
90-
std::cout << "Proceeding with request " << i << std::endl;
111+
for (unsigned long long i = 0; i < NUM_REQUESTS; i++) {
112+
//std::cout << "Proceeding with request " << i << std::endl;
91113

92114
Transaction *modsecTransaction = new Transaction(modsec, rules, NULL);
93115
modsecTransaction->processConnection(ip, 12345, "127.0.0.1", 80);

0 commit comments

Comments
 (0)