postfix_status_line 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +83 -0
- data/ext/postfix_status_line_core.c +66 -18
- data/ext/postfix_status_line_core.h +5 -0
- data/lib/postfix_status_line.rb +2 -1
- data/lib/postfix_status_line/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df9ab0374f13af0d782be989d057f95a6aa474ed
|
4
|
+
data.tar.gz: 768d579c879a6b5209405143775bc7f0ad79e027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980943454a02e5151a986a2795d834bdb095018b876856951ec474d1db7d0dcfd3c8e59e816240737331b9d3fff502a3678bc369a2f3aa02bfca22a02259af04
|
7
|
+
data.tar.gz: b7153669aa950d74f1c0bb3e7ad4fd5874d974a98810beeeed41dd3840a882150bde2c5d1559a0b96b626f518a52e931fe88da8b1f19c1182faf05d2961d2e1f
|
data/README.md
CHANGED
@@ -50,3 +50,86 @@ PostfixStatusLine.parse(status_line)
|
|
50
50
|
```ruby
|
51
51
|
PostfixStatusLine.parse(status_line, hash: true)
|
52
52
|
```
|
53
|
+
|
54
|
+
### Parse time
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
PostfixStatusLine.parse(status_line, parse_time: true)
|
58
|
+
```
|
59
|
+
|
60
|
+
## Benchmark (on EC2/t2.micro)
|
61
|
+
|
62
|
+
### Script
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
#!/usr/bin/env ruby
|
66
|
+
require 'benchmark'
|
67
|
+
require 'postfix_status_line'
|
68
|
+
|
69
|
+
it = 5
|
70
|
+
n = 500000
|
71
|
+
|
72
|
+
status_lines = "Feb 27 09:02:37 MyHOSTNAME postfix/smtp[26490]: D53A72713E5: to=<myemail@bellsouth.net>, relay=gateway-f1.isp.att.net[204.127.217.16]:25, delay=0.57, delays=0.11/0.03/0.23/0.19, dsn=2.0.0, status=sent (250 ok ; id=20120227140036M0700qer4ne)"
|
73
|
+
|
74
|
+
{
|
75
|
+
psl: {mask: false},
|
76
|
+
psl_m: {},
|
77
|
+
psl_h: {hash: true},
|
78
|
+
psl_t: {parse_time: true},
|
79
|
+
}.each do |name, options|
|
80
|
+
Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x|
|
81
|
+
rs = []
|
82
|
+
|
83
|
+
it.times do |i|
|
84
|
+
i += 1
|
85
|
+
|
86
|
+
rs << x.report("#{Time.now.strftime('%X')} #{name}(#{i}):") do
|
87
|
+
for i in 1..n
|
88
|
+
PostfixStatusLine.parse(status_lines, options)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
pps = rs.inject(&:+) / it / n
|
94
|
+
tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real)
|
95
|
+
[pps, tp]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
### Result
|
101
|
+
|
102
|
+
```
|
103
|
+
user system total real
|
104
|
+
02:26:06 psl(1): 2.810000 0.000000 2.810000 ( 2.807900)
|
105
|
+
02:26:09 psl(2): 2.820000 0.000000 2.820000 ( 2.819920)
|
106
|
+
02:26:12 psl(3): 2.810000 0.000000 2.810000 ( 2.809408)
|
107
|
+
02:26:14 psl(4): 2.810000 0.000000 2.810000 ( 2.810345)
|
108
|
+
02:26:17 psl(5): 2.800000 0.000000 2.800000 ( 2.802439)
|
109
|
+
>sec/prs: 0.000006 0.000000 0.000006 ( 0.000006)
|
110
|
+
>prs/sec: 177935.943060 Inf Inf (177935.783843)
|
111
|
+
user system total real
|
112
|
+
02:26:20 psl_m(1): 2.940000 0.000000 2.940000 ( 2.942580)
|
113
|
+
02:26:23 psl_m(2): 2.880000 0.000000 2.880000 ( 2.879812)
|
114
|
+
02:26:26 psl_m(3): 2.900000 0.000000 2.900000 ( 2.900414)
|
115
|
+
02:26:29 psl_m(4): 2.840000 0.000000 2.840000 ( 2.836515)
|
116
|
+
02:26:32 psl_m(5): 2.790000 0.000000 2.790000 ( 2.792500)
|
117
|
+
>sec/prs: 0.000006 0.000000 0.000006 ( 0.000006)
|
118
|
+
>prs/sec: 174216.027875 Inf Inf (174193.923151)
|
119
|
+
user system total real
|
120
|
+
02:26:34 psl_h(1): 4.990000 0.000000 4.990000 ( 4.987470)
|
121
|
+
02:26:39 psl_h(2): 5.000000 0.000000 5.000000 ( 4.999526)
|
122
|
+
02:26:44 psl_h(3): 4.950000 0.000000 4.950000 ( 4.944881)
|
123
|
+
02:26:49 psl_h(4): 5.030000 0.000000 5.030000 ( 5.033834)
|
124
|
+
02:26:54 psl_h(5): 5.010000 0.000000 5.010000 ( 5.031988)
|
125
|
+
>sec/prs: 0.000010 0.000000 0.000010 ( 0.000010)
|
126
|
+
>prs/sec: 100080.064051 Inf Inf (100009.204039)
|
127
|
+
user system total real
|
128
|
+
02:26:59 psl_t(1): 4.060000 0.340000 4.400000 ( 4.397266)
|
129
|
+
02:27:04 psl_t(2): 3.900000 0.320000 4.220000 ( 4.226741)
|
130
|
+
02:27:08 psl_t(3): 3.750000 0.380000 4.130000 ( 4.125684)
|
131
|
+
02:27:12 psl_t(4): 3.830000 0.280000 4.110000 ( 4.097343)
|
132
|
+
02:27:16 psl_t(5): 3.770000 0.320000 4.090000 ( 4.097630)
|
133
|
+
>sec/prs: 0.000008 0.000001 0.000008 ( 0.000008)
|
134
|
+
>prs/sec: 129466.597618 1524390.243902 Inf (119362.140704)
|
135
|
+
```
|
@@ -37,6 +37,16 @@ static bool digest_sha512(char *str, char *salt, size_t salt_len, char buf[]) {
|
|
37
37
|
}
|
38
38
|
#endif // HAVE_OPENSSL_SHA_H
|
39
39
|
|
40
|
+
static bool rb_value_to_bool(VALUE v_value) {
|
41
|
+
switch (TYPE(v_value)) {
|
42
|
+
case T_FALSE:
|
43
|
+
case T_NIL:
|
44
|
+
return false;
|
45
|
+
default:
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
40
50
|
static char *split(char **orig_str, const char *delim, size_t delim_len) {
|
41
51
|
char *str = *orig_str;
|
42
52
|
char *ptr = strstr((const char *) str, delim);
|
@@ -283,22 +293,66 @@ static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, cha
|
|
283
293
|
}
|
284
294
|
}
|
285
295
|
|
286
|
-
static
|
296
|
+
static int get_year() {
|
297
|
+
time_t now = time(NULL);
|
298
|
+
|
299
|
+
if (now == -1) {
|
300
|
+
return -1;
|
301
|
+
}
|
302
|
+
|
303
|
+
struct tm *t = localtime(&now);
|
304
|
+
|
305
|
+
if (t == NULL) {
|
306
|
+
return -1;
|
307
|
+
}
|
308
|
+
|
309
|
+
return t->tm_year;
|
310
|
+
}
|
311
|
+
|
312
|
+
static void put_epoch(char *time_str, VALUE hash) {
|
313
|
+
time_t ts;
|
314
|
+
struct tm parsed;
|
315
|
+
|
316
|
+
if (strptime(time_str, "%b %d %H:%M:%S", &parsed) == NULL) {
|
317
|
+
return;
|
318
|
+
}
|
319
|
+
|
320
|
+
int this_year = get_year();
|
321
|
+
|
322
|
+
if (this_year == -1) {
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
|
326
|
+
parsed.tm_year = this_year;
|
327
|
+
parsed.tm_isdst = 0;
|
328
|
+
|
329
|
+
ts = mktime(&parsed);
|
330
|
+
|
331
|
+
if (ts == -1) {
|
332
|
+
return;
|
333
|
+
}
|
334
|
+
|
335
|
+
rb_hash_aset(hash, rb_str_new2("epoch"), LONG2NUM(ts));
|
336
|
+
}
|
337
|
+
|
338
|
+
static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time) {
|
287
339
|
Check_Type(v_str, T_STRING);
|
288
340
|
|
289
341
|
char *str = RSTRING_PTR(v_str);
|
290
342
|
size_t len = RSTRING_LEN(v_str);
|
291
|
-
|
343
|
+
|
344
|
+
if (len < 1) {
|
345
|
+
return Qnil;
|
346
|
+
}
|
347
|
+
|
348
|
+
bool mask = rb_value_to_bool(v_mask);
|
349
|
+
bool parse_time = rb_value_to_bool(v_parse_time);
|
292
350
|
|
293
351
|
bool include_hash = false;
|
294
352
|
char *salt = NULL;
|
295
353
|
size_t salt_len = -1;
|
296
354
|
|
297
|
-
|
298
|
-
case T_FALSE:
|
299
|
-
case T_NIL:
|
300
|
-
break;
|
301
|
-
default:
|
355
|
+
if (rb_value_to_bool(v_hash)) {
|
302
356
|
#ifdef HAVE_OPENSSL_SHA_H
|
303
357
|
include_hash = true;
|
304
358
|
|
@@ -312,16 +366,6 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
|
|
312
366
|
#endif // HAVE_OPENSSL_SHA_H
|
313
367
|
}
|
314
368
|
|
315
|
-
switch (TYPE(v_mask)) {
|
316
|
-
case T_FALSE:
|
317
|
-
case T_NIL:
|
318
|
-
mask = false;
|
319
|
-
}
|
320
|
-
|
321
|
-
if (len < 1) {
|
322
|
-
return Qnil;
|
323
|
-
}
|
324
|
-
|
325
369
|
char buf[len + 1];
|
326
370
|
strncpy(buf, str, len);
|
327
371
|
buf[len] = '\0';
|
@@ -338,6 +382,10 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
|
|
338
382
|
rb_hash_aset(hash, rb_str_new2("process"), rb_str_new2(process));
|
339
383
|
rb_hash_aset(hash, rb_str_new2("queue_id"), rb_str_new2(queue_id));
|
340
384
|
|
385
|
+
if (parse_time) {
|
386
|
+
put_epoch(tm, hash);
|
387
|
+
}
|
388
|
+
|
341
389
|
split_line2(attrs, mask, hash, include_hash, salt, salt_len);
|
342
390
|
|
343
391
|
return hash;
|
@@ -346,5 +394,5 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
|
|
346
394
|
void Init_postfix_status_line_core() {
|
347
395
|
VALUE rb_mPostfixStatusLine = rb_define_module("PostfixStatusLine");
|
348
396
|
VALUE rb_mPostfixStatusLineCore = rb_define_module_under(rb_mPostfixStatusLine, "Core");
|
349
|
-
rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse,
|
397
|
+
rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse, 5);
|
350
398
|
}
|
data/lib/postfix_status_line.rb
CHANGED
@@ -6,7 +6,8 @@ module PostfixStatusLine
|
|
6
6
|
mask = options.has_key?(:mask) ? options[:mask] : true
|
7
7
|
hash = options[:hash]
|
8
8
|
salt = options[:salt]
|
9
|
-
|
9
|
+
parse_time = options[:parse_time]
|
10
|
+
PostfixStatusLine::Core.parse(str, mask, hash, salt, parse_time)
|
10
11
|
end
|
11
12
|
module_function :parse
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postfix_status_line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|