Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

received_parser_bench.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 gint total_valid = 0;
  23. static gint total_real_ip = 0;
  24. static gint total_real_host = 0;
  25. static gint total_known_proto = 0;
  26. static gint total_known_ts = 0;
  27. static gint total_known_for = 0;
  28. static void
  29. rspamd_process_file (const gchar *fname)
  30. {
  31. struct rspamd_task *task;
  32. GIOChannel *f;
  33. GError *err = NULL;
  34. GString *buf;
  35. struct received_header rh;
  36. gdouble t1, t2;
  37. f = g_io_channel_new_file (fname, "r", &err);
  38. if (!f) {
  39. rspamd_fprintf (stderr, "cannot open %s: %e\n", fname, err);
  40. g_error_free (err);
  41. return;
  42. }
  43. g_io_channel_set_encoding (f, NULL, NULL);
  44. buf = g_string_sized_new (8192);
  45. task = g_malloc0 (sizeof (*task));
  46. task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "test");
  47. while (g_io_channel_read_line_string (f, buf, NULL, &err)
  48. == G_IO_STATUS_NORMAL) {
  49. while (buf->len > 0 && g_ascii_isspace (buf->str[buf->len - 1])) {
  50. buf->len --;
  51. }
  52. t1 = rspamd_get_virtual_ticks ();
  53. rspamd_smtp_received_parse (task, buf->str, buf->len, &rh);
  54. t2 = rspamd_get_virtual_ticks ();
  55. total_time += t2 - t1;
  56. total_parsed ++;
  57. if (rh.addr) {
  58. total_real_ip ++;
  59. }
  60. if (rh.real_hostname) {
  61. total_real_host ++;
  62. }
  63. if (rh.type != RSPAMD_RECEIVED_UNKNOWN) {
  64. total_known_proto ++;
  65. }
  66. if (rh.by_hostname || rh.timestamp > 0) {
  67. total_valid ++;
  68. }
  69. if (rh.timestamp != 0) {
  70. total_known_ts ++;
  71. }
  72. if (rh.for_mbox) {
  73. total_known_for ++;
  74. }
  75. }
  76. if (err) {
  77. rspamd_fprintf (stderr, "cannot read %s: %e\n", fname, err);
  78. g_error_free (err);
  79. }
  80. g_io_channel_unref (f);
  81. g_string_free (buf, TRUE);
  82. rspamd_mempool_delete (task->task_pool);
  83. g_free (task);
  84. }
  85. int
  86. main (int argc, char **argv)
  87. {
  88. gint i;
  89. for (i = 1; i < argc; i ++) {
  90. if (argv[i]) {
  91. rspamd_process_file (argv[i]);
  92. }
  93. }
  94. rspamd_printf ("Parsed %d received headers in %.3f seconds\n"
  95. "Total valid (has by part): %d\n"
  96. "Total real ip: %d\n"
  97. "Total real host: %d\n"
  98. "Total known proto: %d\n"
  99. "Total known timestamp: %d\n"
  100. "Total known for: %d\n",
  101. total_parsed, total_time,
  102. total_valid, total_real_ip,
  103. total_real_host, total_known_proto,
  104. total_known_ts,
  105. total_known_for);
  106. return 0;
  107. }