You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

received_parser_bench.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "config.h"
  17. #include "printf.h"
  18. #include "message.h"
  19. #include "smtp_parsers.h"
  20. static gdouble total_time = 0;
  21. static gint total_parsed = 0;
  22. static void
  23. rspamd_process_file (const gchar *fname)
  24. {
  25. struct rspamd_task *task;
  26. GIOChannel *f;
  27. GError *err = NULL;
  28. GString *buf;
  29. struct received_header rh;
  30. gdouble t1, t2;
  31. f = g_io_channel_new_file (fname, "r", &err);
  32. if (!f) {
  33. rspamd_fprintf (stderr, "cannot open %s: %e\n", fname, err);
  34. g_error_free (err);
  35. return;
  36. }
  37. g_io_channel_set_encoding (f, NULL, NULL);
  38. buf = g_string_sized_new (8192);
  39. task = g_malloc0 (sizeof (task));
  40. task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "test");
  41. while (g_io_channel_read_line_string (f, buf, NULL, &err)
  42. == G_IO_STATUS_NORMAL) {
  43. while (buf->len > 0 && g_ascii_isspace (buf->str[buf->len - 1])) {
  44. buf->len --;
  45. }
  46. t1 = rspamd_get_virtual_ticks ();
  47. rspamd_smtp_recieved_parse (task, buf->str, buf->len, &rh);
  48. t2 = rspamd_get_virtual_ticks ();
  49. total_time += t2 - t1;
  50. total_parsed ++;
  51. }
  52. if (err) {
  53. rspamd_fprintf (stderr, "cannot read %s: %e\n", fname, err);
  54. g_error_free (err);
  55. }
  56. g_io_channel_unref (f);
  57. g_string_free (buf, TRUE);
  58. rspamd_mempool_delete (task->task_pool);
  59. g_free (task);
  60. }
  61. int
  62. main (int argc, char **argv)
  63. {
  64. gint i;
  65. for (i = 1; i < argc; i ++) {
  66. if (argv[i]) {
  67. rspamd_process_file (argv[i]);
  68. }
  69. }
  70. rspamd_printf ("Parsed %d received headers in %.3f seconds\n",
  71. total_parsed, total_time);
  72. return 0;
  73. }