ultragrep 0.1.0 → 0.10.0
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 +7 -0
- data/bin/ultragrep_build_indexes +45 -0
- data/lib/ultragrep.rb +47 -61
- data/lib/ultragrep/config.rb +6 -0
- data/lib/ultragrep/log_collector.rb +67 -0
- data/lib/ultragrep/version.rb +1 -1
- data/src/Makefile +24 -0
- data/{ext/ultragrep → src}/extconf.rb +0 -0
- data/src/pcre.h +668 -0
- data/src/request.h +13 -0
- data/src/ug_build_index.c +109 -0
- data/src/ug_cat.c +188 -0
- data/src/ug_guts.c +199 -0
- data/src/ug_gzip.c +242 -0
- data/src/ug_gzip.h +8 -0
- data/src/ug_index.c +62 -0
- data/src/ug_index.h +23 -0
- data/src/ug_lua.c +119 -0
- data/src/ug_lua.h +10 -0
- metadata +25 -28
- data/ext/ultragrep/Makefile +0 -39
- data/ext/ultragrep/rails_req.c +0 -102
- data/ext/ultragrep/rails_req.h +0 -6
- data/ext/ultragrep/req_matcher.h +0 -17
- data/ext/ultragrep/request.c +0 -41
- data/ext/ultragrep/request.h +0 -22
- data/ext/ultragrep/ug_build_index.c +0 -99
- data/ext/ultragrep/ug_cat.c +0 -46
- data/ext/ultragrep/ug_guts.c +0 -138
- data/ext/ultragrep/ug_index.c +0 -83
- data/ext/ultragrep/ug_index.h +0 -27
- data/ext/ultragrep/work_req.c +0 -200
- data/ext/ultragrep/work_req.h +0 -6
- data/ext/ultragrep/zran.c +0 -291
data/src/ug_lua.h
ADDED
metadata
CHANGED
@@ -1,67 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultragrep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.10.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- Ben Osheroff
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description:
|
15
|
-
email:
|
14
|
+
email: ben@zendesk.com
|
16
15
|
executables:
|
17
16
|
- ultragrep
|
18
17
|
extensions:
|
19
|
-
-
|
18
|
+
- src/extconf.rb
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- bin/ultragrep
|
23
|
-
-
|
24
|
-
- ext/ultragrep/extconf.rb
|
25
|
-
- ext/ultragrep/rails_req.c
|
26
|
-
- ext/ultragrep/rails_req.h
|
27
|
-
- ext/ultragrep/req_matcher.h
|
28
|
-
- ext/ultragrep/request.c
|
29
|
-
- ext/ultragrep/request.h
|
30
|
-
- ext/ultragrep/ug_build_index.c
|
31
|
-
- ext/ultragrep/ug_cat.c
|
32
|
-
- ext/ultragrep/ug_guts.c
|
33
|
-
- ext/ultragrep/ug_index.c
|
34
|
-
- ext/ultragrep/ug_index.h
|
35
|
-
- ext/ultragrep/work_req.c
|
36
|
-
- ext/ultragrep/work_req.h
|
37
|
-
- ext/ultragrep/zran.c
|
22
|
+
- bin/ultragrep_build_indexes
|
38
23
|
- lib/ultragrep.rb
|
39
24
|
- lib/ultragrep/config.rb
|
25
|
+
- lib/ultragrep/log_collector.rb
|
40
26
|
- lib/ultragrep/version.rb
|
27
|
+
- src/Makefile
|
28
|
+
- src/extconf.rb
|
29
|
+
- src/pcre.h
|
30
|
+
- src/request.h
|
31
|
+
- src/ug_build_index.c
|
32
|
+
- src/ug_cat.c
|
33
|
+
- src/ug_guts.c
|
34
|
+
- src/ug_gzip.c
|
35
|
+
- src/ug_gzip.h
|
36
|
+
- src/ug_index.c
|
37
|
+
- src/ug_index.h
|
38
|
+
- src/ug_lua.c
|
39
|
+
- src/ug_lua.h
|
41
40
|
homepage: https://github.com/zendesk/ultragrep
|
42
41
|
licenses:
|
43
42
|
- Apache License Version 2.0
|
43
|
+
metadata: {}
|
44
44
|
post_install_message:
|
45
45
|
rdoc_options: []
|
46
46
|
require_paths:
|
47
47
|
- lib
|
48
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
49
|
requirements:
|
51
|
-
- -
|
50
|
+
- - ">="
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
54
|
requirements:
|
57
|
-
- -
|
55
|
+
- - ">="
|
58
56
|
- !ruby/object:Gem::Version
|
59
57
|
version: '0'
|
60
58
|
requirements: []
|
61
59
|
rubyforge_project:
|
62
|
-
rubygems_version:
|
60
|
+
rubygems_version: 2.2.2
|
63
61
|
signing_key:
|
64
|
-
specification_version:
|
62
|
+
specification_version: 4
|
65
63
|
summary: Ultragrep
|
66
64
|
test_files: []
|
67
|
-
has_rdoc:
|
data/ext/ultragrep/Makefile
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
CFLAGS=-I/opt/local/include -g
|
2
|
-
all: ug_guts ug_build_index ug_cat
|
3
|
-
install: all
|
4
|
-
|
5
|
-
request.o: request.c request.h
|
6
|
-
gcc ${CFLAGS} -c request.c
|
7
|
-
|
8
|
-
rails_req.o: rails_req.c rails_req.h req_matcher.h
|
9
|
-
gcc ${CFLAGS} -c rails_req.c
|
10
|
-
|
11
|
-
work_req.o: work_req.c work_req.h req_matcher.h
|
12
|
-
gcc ${CFLAGS} -c work_req.c
|
13
|
-
|
14
|
-
ug_guts.o: ug_guts.c req_matcher.h
|
15
|
-
gcc ${CFLAGS} -c ug_guts.c
|
16
|
-
|
17
|
-
ug_guts: ug_guts.o rails_req.o work_req.o request.o Makefile
|
18
|
-
gcc ${CFLAGS} -o ug_guts request.o rails_req.o work_req.o ug_guts.o -lpcre
|
19
|
-
|
20
|
-
ug_index.o: ug_index.h ug_index.c
|
21
|
-
gcc ${CFLAGS} -c ug_index.c
|
22
|
-
|
23
|
-
ug_build_index.o: ug_build_index.c req_matcher.h ug_index.h
|
24
|
-
gcc ${CFLAGS} -c ug_build_index.c
|
25
|
-
|
26
|
-
ug_build_index: ug_build_index.o ug_index.o rails_req.o work_req.o request.o Makefile zran.o
|
27
|
-
gcc ${CFLAGS} -o ug_build_index request.o rails_req.o work_req.o ug_index.o ug_build_index.o zran.o -lpcre -lz
|
28
|
-
|
29
|
-
ug_cat.o: ug_cat.c ug_index.h
|
30
|
-
gcc ${CFLAGS} -c ug_cat.c
|
31
|
-
|
32
|
-
ug_cat: ug_cat.o ug_index.o Makefile
|
33
|
-
gcc ${CFLAGS} -o ug_cat ug_cat.o ug_index.o
|
34
|
-
|
35
|
-
zran.o: zran.c
|
36
|
-
gcc -g -c zran.c
|
37
|
-
|
38
|
-
clean:
|
39
|
-
rm -rf *.o ug_guts
|
data/ext/ultragrep/rails_req.c
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <time.h>
|
3
|
-
#include "pcre.h"
|
4
|
-
#include "request.h"
|
5
|
-
#include "req_matcher.h"
|
6
|
-
|
7
|
-
typedef struct {
|
8
|
-
req_matcher_t base;
|
9
|
-
on_req on_request;
|
10
|
-
on_err on_error;
|
11
|
-
void* arg;
|
12
|
-
int stop_requested;
|
13
|
-
int blank_lines;
|
14
|
-
|
15
|
-
}rails_req_matcher_t;
|
16
|
-
static request_t request;
|
17
|
-
|
18
|
-
|
19
|
-
static void rails_on_request(rails_req_matcher_t* m, request_t* r) {
|
20
|
-
if(r && m->on_request) {
|
21
|
-
if(r->lines > 0) {
|
22
|
-
m->on_request(r, m->arg);
|
23
|
-
}
|
24
|
-
clear_request(r);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
void rails_stop(req_matcher_t* base) {
|
29
|
-
rails_req_matcher_t* m = (rails_req_matcher_t*)base;
|
30
|
-
m->stop_requested = 1;
|
31
|
-
}
|
32
|
-
|
33
|
-
static int parse_req_time(char* line, ssize_t line_size, time_t* time) {
|
34
|
-
int matched = 0;
|
35
|
-
int ovector[30];
|
36
|
-
char *date_buf;
|
37
|
-
struct tm request_tm;
|
38
|
-
time_t tv;
|
39
|
-
const char* error;
|
40
|
-
int erroffset;
|
41
|
-
static pcre* regex = NULL;
|
42
|
-
|
43
|
-
*time = 0;
|
44
|
-
|
45
|
-
if(regex == NULL) {
|
46
|
-
regex = pcre_compile("^(?:Processing|Started).*(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})", 0, &error, &erroffset, NULL);
|
47
|
-
}
|
48
|
-
matched = pcre_exec(regex, NULL, line, line_size,0,0,ovector, 30);
|
49
|
-
if(matched > 0) {
|
50
|
-
pcre_get_substring(line, ovector, matched, 1, (const char **)&date_buf);
|
51
|
-
strptime(date_buf, "%Y-%m-%d %H:%M:%S", &request_tm);
|
52
|
-
free(date_buf);
|
53
|
-
|
54
|
-
*time = timegm(&request_tm);
|
55
|
-
return(1);
|
56
|
-
}
|
57
|
-
return(-1);
|
58
|
-
}
|
59
|
-
|
60
|
-
static int rails_process_line(req_matcher_t* base, char *line, ssize_t line_size, off_t offset) {
|
61
|
-
rails_req_matcher_t* m = (rails_req_matcher_t*)base;
|
62
|
-
|
63
|
-
if((m->stop_requested) || (line_size == -1)) {
|
64
|
-
rails_on_request(m, &request);
|
65
|
-
return((m->stop_requested)?STOP_SIGNAL:EOF_REACHED);
|
66
|
-
}
|
67
|
-
|
68
|
-
if(line_size == 1) { //blank line
|
69
|
-
m->blank_lines += 1;
|
70
|
-
return(0);
|
71
|
-
}
|
72
|
-
|
73
|
-
if(m->blank_lines >= 2) {
|
74
|
-
m->blank_lines = 0;
|
75
|
-
rails_on_request(m, &request);
|
76
|
-
}
|
77
|
-
|
78
|
-
add_to_request(&request, line, offset);
|
79
|
-
|
80
|
-
if(request.time == 0) {
|
81
|
-
parse_req_time(line, line_size, &(request.time));
|
82
|
-
}
|
83
|
-
|
84
|
-
return(0);
|
85
|
-
}
|
86
|
-
|
87
|
-
req_matcher_t* rails_req_matcher(on_req fn1, on_err fn2, void* arg) {
|
88
|
-
rails_req_matcher_t* m = (rails_req_matcher_t*)malloc(sizeof(rails_req_matcher_t));
|
89
|
-
req_matcher_t* base = (req_matcher_t*)m;
|
90
|
-
|
91
|
-
m->on_request = fn1;
|
92
|
-
m->on_error = fn2;
|
93
|
-
m->arg = arg;
|
94
|
-
|
95
|
-
m->stop_requested = 0;
|
96
|
-
m->blank_lines = 0;
|
97
|
-
|
98
|
-
base->process_line = &rails_process_line;
|
99
|
-
base->stop = &rails_stop;
|
100
|
-
clear_request(&request);
|
101
|
-
return base;
|
102
|
-
}
|
data/ext/ultragrep/rails_req.h
DELETED
data/ext/ultragrep/req_matcher.h
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#ifndef __REQ_MATCHER_H__
|
2
|
-
#define __REQ_MATCHER_H__
|
3
|
-
#include "request.h"
|
4
|
-
#include <sys/types.h>
|
5
|
-
|
6
|
-
typedef void (*on_req)(request_t*, void* arg);
|
7
|
-
typedef void (*on_err)(char*, ssize_t, void* arg);
|
8
|
-
|
9
|
-
typedef struct req_matcher_t{
|
10
|
-
int (*process_line)(struct req_matcher_t* base, char* line, ssize_t line_sz, off_t offset);
|
11
|
-
void (*stop)(struct req_matcher_t* base);
|
12
|
-
}req_matcher_t;
|
13
|
-
|
14
|
-
#define EOF_REACHED 1
|
15
|
-
#define STOP_SIGNAL 2
|
16
|
-
|
17
|
-
#endif //__REQ_MATCHER_H__
|
data/ext/ultragrep/request.c
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <stdlib.h>
|
3
|
-
#include <string.h>
|
4
|
-
#include "request.h"
|
5
|
-
|
6
|
-
request_t* alloc_request() {
|
7
|
-
request_t* r = (request_t*)calloc(1, sizeof(request_t));
|
8
|
-
return(r);
|
9
|
-
}
|
10
|
-
|
11
|
-
void init_request(request_t* r) {
|
12
|
-
memset(r, 0, sizeof(request_t));
|
13
|
-
}
|
14
|
-
void clear_request(request_t* r) {
|
15
|
-
int i=0;
|
16
|
-
|
17
|
-
for(i = 0; i < r->lines; i++) {
|
18
|
-
free(r->buf[i]);
|
19
|
-
}
|
20
|
-
if(r->buf) {
|
21
|
-
free(r->buf);
|
22
|
-
}
|
23
|
-
if(r->session) {
|
24
|
-
free(r->session);
|
25
|
-
}
|
26
|
-
init_request(r);
|
27
|
-
}
|
28
|
-
|
29
|
-
void free_request(request_t* r) {
|
30
|
-
clear_request(r);
|
31
|
-
free(r);
|
32
|
-
}
|
33
|
-
|
34
|
-
void add_to_request(request_t* req, char* line, off_t offset) {
|
35
|
-
if ( !req->offset )
|
36
|
-
req->offset = offset;
|
37
|
-
|
38
|
-
req->buf = realloc(req->buf, sizeof(char*) * (req->lines + 1));
|
39
|
-
req->buf[req->lines] = line;
|
40
|
-
req->lines++;
|
41
|
-
}
|
data/ext/ultragrep/request.h
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#ifndef __REQUEST_H__
|
2
|
-
#define __REQUEST_H__
|
3
|
-
|
4
|
-
#include <time.h>
|
5
|
-
|
6
|
-
typedef struct request_t{
|
7
|
-
char **buf;
|
8
|
-
int lines;
|
9
|
-
time_t time;
|
10
|
-
char* session;
|
11
|
-
off_t offset;
|
12
|
-
|
13
|
-
struct request_t* next; //for linking
|
14
|
-
struct request_t* prev;
|
15
|
-
}request_t;
|
16
|
-
|
17
|
-
request_t* alloc_request();
|
18
|
-
void init_request(request_t* r);
|
19
|
-
void clear_request(request_t* r);
|
20
|
-
void free_request(request_t* r);
|
21
|
-
void add_to_request(request_t*, char*, off_t);
|
22
|
-
#endif //__REQUEST_H__
|
@@ -1,99 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <stdlib.h>
|
3
|
-
#include <getopt.h>
|
4
|
-
#include <string.h>
|
5
|
-
#include <time.h>
|
6
|
-
#include <unistd.h>
|
7
|
-
#include "pcre.h"
|
8
|
-
#include "rails_req.h"
|
9
|
-
#include "work_req.h"
|
10
|
-
#include "ug_index.h"
|
11
|
-
|
12
|
-
#define USAGE "Usage: ug_build_index (work|app) file\n"
|
13
|
-
|
14
|
-
|
15
|
-
// index file format
|
16
|
-
// [64bit,64bit] -- timestamp, file offset
|
17
|
-
// [32bit, Nbytes] -- extra data
|
18
|
-
|
19
|
-
void handle_request(request_t* req, build_idx_context_t* cxt) {
|
20
|
-
time_t floored_time;
|
21
|
-
floored_time = req->time - (req->time % INDEX_EVERY);
|
22
|
-
if ( !cxt->last_index_time || floored_time > cxt->last_index_time ) {
|
23
|
-
ug_write_index(cxt->index, floored_time, req->offset, NULL, 0);
|
24
|
-
cxt->last_index_time = floored_time;
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
int main(int argc, char **argv)
|
29
|
-
{
|
30
|
-
build_idx_context_t *cxt;
|
31
|
-
char *line = NULL, *index_fname = NULL, *dir;
|
32
|
-
ssize_t line_size, allocated;
|
33
|
-
|
34
|
-
|
35
|
-
if ( argc < 3 ) {
|
36
|
-
fprintf(stderr, USAGE);
|
37
|
-
exit(1);
|
38
|
-
}
|
39
|
-
|
40
|
-
cxt = malloc(sizeof(build_idx_context_t));
|
41
|
-
memset(cxt, 0, sizeof(build_idx_context_t));
|
42
|
-
|
43
|
-
if(strcmp(argv[1],"work") == 0)
|
44
|
-
{
|
45
|
-
cxt->m = work_req_matcher(&handle_request, NULL, cxt);
|
46
|
-
}
|
47
|
-
else if(strcmp(argv[1], "app") == 0)
|
48
|
-
{
|
49
|
-
cxt->m = rails_req_matcher(&handle_request, NULL, cxt);
|
50
|
-
}
|
51
|
-
else
|
52
|
-
{
|
53
|
-
fprintf(stderr, USAGE);
|
54
|
-
exit(1);
|
55
|
-
}
|
56
|
-
|
57
|
-
cxt->log = fopen(argv[2], "r");
|
58
|
-
if ( !cxt->log ) {
|
59
|
-
perror("Couldn't open log file");
|
60
|
-
exit(1);
|
61
|
-
}
|
62
|
-
|
63
|
-
index_fname = ug_get_index_fname(argv[2]);
|
64
|
-
|
65
|
-
cxt->index = fopen(index_fname, "r+");
|
66
|
-
if ( cxt->index ) {
|
67
|
-
struct ug_index idx;
|
68
|
-
ug_get_last_index_entry(cxt->index, &idx);
|
69
|
-
fseeko(cxt->log, idx.offset, SEEK_SET);
|
70
|
-
} else {
|
71
|
-
cxt->index = fopen(index_fname, "w+");
|
72
|
-
}
|
73
|
-
|
74
|
-
if ( !cxt->index ) {
|
75
|
-
perror("Couldn't open index file");
|
76
|
-
exit(1);
|
77
|
-
}
|
78
|
-
|
79
|
-
if ( strcmp(argv[2] + (strlen(argv[2]) - 3), ".gz") == 0 ) {
|
80
|
-
build_gz_index(cxt);
|
81
|
-
} else {
|
82
|
-
cxt->data_size = 0;
|
83
|
-
|
84
|
-
while(1) {
|
85
|
-
int ret;
|
86
|
-
line_size = getline(&line, &allocated, cxt->log);
|
87
|
-
ret = cxt->m->process_line(cxt->m, line, line_size, ftello(cxt->log) - line_size);
|
88
|
-
if(ret == EOF_REACHED || ret == STOP_SIGNAL) {
|
89
|
-
break;
|
90
|
-
}
|
91
|
-
line = NULL;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
fclose(cxt->index);
|
96
|
-
fclose(cxt->log);
|
97
|
-
}
|
98
|
-
|
99
|
-
|
data/ext/ultragrep/ug_cat.c
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <stdlib.h>
|
3
|
-
#include <string.h>
|
4
|
-
#include <libgen.h>
|
5
|
-
#include "ug_index.h"
|
6
|
-
|
7
|
-
/*
|
8
|
-
* ug_cat -- given a log file and (possibly) a file + (timestamp -> offset) index, cat the file starting
|
9
|
-
* from about that timestamp
|
10
|
-
*/
|
11
|
-
|
12
|
-
#define USAGE "Usage: ug_cat file timestamp\n"
|
13
|
-
|
14
|
-
int main(int argc, char **argv)
|
15
|
-
{
|
16
|
-
int nread;
|
17
|
-
FILE *log;
|
18
|
-
FILE *index;
|
19
|
-
char *index_fname, buf[4096];
|
20
|
-
|
21
|
-
if ( argc < 3 ) {
|
22
|
-
fprintf(stderr, USAGE);
|
23
|
-
exit(1);
|
24
|
-
}
|
25
|
-
|
26
|
-
log = fopen(argv[1], "r");
|
27
|
-
if ( !log ) {
|
28
|
-
perror("Couldn't open log file");
|
29
|
-
exit(1);
|
30
|
-
}
|
31
|
-
|
32
|
-
index_fname = ug_get_index_fname(argv[1]);
|
33
|
-
|
34
|
-
index = fopen(index_fname, "r");
|
35
|
-
if ( index ) {
|
36
|
-
ug_seek_to_timestamp(log, index, atol(argv[2]), NULL);
|
37
|
-
}
|
38
|
-
|
39
|
-
while ( nread = fread(buf, 1, 4096, log) ) {
|
40
|
-
fwrite(buf, 1, nread, stdout);
|
41
|
-
}
|
42
|
-
|
43
|
-
fclose(log);
|
44
|
-
}
|
45
|
-
|
46
|
-
|