]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add a simple received parser benchmark routine
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jun 2016 21:40:31 +0000 (22:40 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 14 Jun 2016 21:40:31 +0000 (22:40 +0100)
FindRagel.cmake
src/CMakeLists.txt
utils/CMakeLists.txt
utils/received_parser_bench.c [new file with mode: 0644]

index b6f7fc2e18ad87a53d72bed9a3cb28f3047d46bc..a058b7fb1936f433988aa9d834f213117a88968d 100644 (file)
@@ -74,7 +74,7 @@ ${RAGEL_version_error}")
                "INPUTS;DEPENDS;COMPILE_FLAGS" ${ARGN})
     add_custom_command(OUTPUT ${RAGEL_OUTPUT}
       COMMAND ${RAGEL_EXECUTABLE}
-      ARGS    ${RAGEL_EXECUTABLE_opts} -o${RAGEL_OUTPUT} ${RAGEL_INPUTS}
+      ARGS    ${RAGEL_COMPILE_FLAGS} -o${RAGEL_OUTPUT} ${RAGEL_INPUTS}
       DEPENDS ${RAGEL_INPUTS} ${RAGEL_DEPENDS}
       COMMENT
           "[RAGEL][${Name}] Compiling state machine with Ragel ${RAGEL_VERSION}"
@@ -83,7 +83,7 @@ ${RAGEL_version_error}")
     set(RAGEL_${Name}_DEFINED       TRUE)
     set(RAGEL_${Name}_OUTPUTS       ${RAGEL_OUTPUT})
     set(RAGEL_${Name}_INPUT         ${RAGEL_INPUTS})
-    set(RAGEL_${Name}_COMPILE_FLAGS ${RAGEL_EXECUTABLE_opts})
+    set(RAGEL_${Name}_COMPILE_FLAGS ${RAGEL_COMPILE_FLAGS})
   endmacro()
 
 endif()
index b9accae3026ead1be1da84413ec448ee8834ce0f..55e76fcfa6faf772bdadb5842f8d2b26f6d8ff62 100644 (file)
@@ -110,10 +110,12 @@ SET(RAGEL_DEPENDS "${CMAKE_SOURCE_DIR}/src/ragel/smtp_address.rl"
 RAGEL_TARGET(ragel_smtp_addr
        INPUTS ragel/smtp_addr_parser.rl
        DEPENDS ${RAGEL_DEPENDS}
+       COMPILE_FLAGS -T1
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/smtp_addr_parser.rl.c)
 RAGEL_TARGET(ragel_smtp_received
        INPUTS ragel/smtp_received_parser.rl
        DEPENDS ${RAGEL_DEPENDS}
+       COMPILE_FLAGS -T1
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/smtp_received_parser.rl.c)
 ######################### LINK SECTION ###############################
 
index 672325924e8756a4151eedff623ed0f3d4f95a1e..e0bb5c88636e789d94b87f5b93e42f7b971803db 100644 (file)
@@ -1,5 +1,6 @@
 SET(UTILSERVERSRC rspamd_http_server.c)
 SET(UTILBENCHSRC rspamd_http_bench.c)
+SET(RECVBENCHSRC received_parser_bench.c)
 
 ADD_EXECUTABLE(rspamd-http-server ${UTILSERVERSRC})
 SET_TARGET_PROPERTIES(rspamd-http-server PROPERTIES LINKER_LANGUAGE C)
@@ -9,13 +10,25 @@ TARGET_LINK_LIBRARIES(rspamd-http-server ${RSPAMD_REQUIRED_LIBRARIES})
 
 ADD_EXECUTABLE(rspamd-http-bench ${UTILBENCHSRC})
 SET_TARGET_PROPERTIES(rspamd-http-bench PROPERTIES LINKER_LANGUAGE C)
-TARGET_LINK_LIBRARIES(rspamd-http-bench rspamd-server)
 TARGET_LINK_LIBRARIES(rspamd-http-bench rspamd-http-parser)
+TARGET_LINK_LIBRARIES(rspamd-http-bench rspamd-server)
 TARGET_LINK_LIBRARIES(rspamd-http-bench ${RSPAMD_REQUIRED_LIBRARIES})
 
+ADD_EXECUTABLE(rspamd-received-bench ${RECVBENCHSRC})
+SET_TARGET_PROPERTIES(rspamd-received-bench PROPERTIES LINKER_LANGUAGE C)
+TARGET_LINK_LIBRARIES(rspamd-received-bench rspamd-server)
+IF (ENABLE_SNOWBALL MATCHES "ON")
+       TARGET_LINK_LIBRARIES(rspamd-received-bench stemmer)
+ENDIF()
+IF(ENABLE_HIREDIS MATCHES "ON")
+       TARGET_LINK_LIBRARIES(rspamd-received-bench rspamd-hiredis)
+ENDIF()
+TARGET_LINK_LIBRARIES(rspamd-received-bench ${RSPAMD_REQUIRED_LIBRARIES})
+
 IF (ENABLE_HYPERSCAN MATCHES "ON")
        SET_TARGET_PROPERTIES(rspamd-http-bench PROPERTIES LINKER_LANGUAGE CXX)
        SET_TARGET_PROPERTIES(rspamd-http-server PROPERTIES LINKER_LANGUAGE CXX)
+       SET_TARGET_PROPERTIES(rspamd-received-bench PROPERTIES LINKER_LANGUAGE CXX)
 ENDIF()
 
 # Redirector
diff --git a/utils/received_parser_bench.c b/utils/received_parser_bench.c
new file mode 100644 (file)
index 0000000..65c6567
--- /dev/null
@@ -0,0 +1,90 @@
+/*-
+ * Copyright 2016 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "config.h"
+#include "printf.h"
+#include "message.h"
+#include "smtp_parsers.h"
+
+static gdouble total_time = 0;
+static gint total_parsed = 0;
+
+static void
+rspamd_process_file (const gchar *fname)
+{
+       struct rspamd_task *task;
+       GIOChannel *f;
+       GError *err = NULL;
+       GString *buf;
+       struct received_header rh;
+       gdouble t1, t2;
+
+       f = g_io_channel_new_file (fname, "r", &err);
+
+       if (!f) {
+               rspamd_fprintf (stderr, "cannot open %s: %e\n", fname, err);
+               g_error_free (err);
+
+               return;
+       }
+
+       g_io_channel_set_encoding (f, NULL, NULL);
+       buf = g_string_sized_new (8192);
+       task = g_malloc0 (sizeof (task));
+       task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "test");
+
+       while (g_io_channel_read_line_string (f, buf, NULL, &err)
+                       == G_IO_STATUS_NORMAL) {
+
+               while (buf->len > 0 && g_ascii_isspace (buf->str[buf->len - 1])) {
+                       buf->len --;
+               }
+
+               t1 = rspamd_get_virtual_ticks ();
+               rspamd_smtp_recieved_parse (task, buf->str, buf->len, &rh);
+               t2 = rspamd_get_virtual_ticks ();
+
+               total_time += t2 - t1;
+               total_parsed ++;
+       }
+
+       if (err) {
+               rspamd_fprintf (stderr, "cannot read %s: %e\n", fname, err);
+               g_error_free (err);
+       }
+
+       g_io_channel_unref (f);
+       g_string_free (buf, TRUE);
+       rspamd_mempool_delete (task->task_pool);
+       g_free (task);
+}
+
+int
+main (int argc, char **argv)
+{
+       gint i;
+
+       for (i = 1; i < argc; i ++) {
+               if (argv[i]) {
+                       rspamd_process_file (argv[i]);
+               }
+       }
+
+       rspamd_printf ("Parsed %d received headers in %.3f seconds\n",
+                       total_parsed, total_time);
+
+       return 0;
+}