journalist 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20db52670ef27ceb9997cad3ec0549694690276d
4
- data.tar.gz: d0174b59664d9edede7a79aa7e4704acc2ef975f
3
+ metadata.gz: 95517034abf866395da885dd6c76b4dc4f247dc9
4
+ data.tar.gz: 05e3d8fc5475524bd32a85d2d44c30bdfd565b8e
5
5
  SHA512:
6
- metadata.gz: 6cdc6dfc98d9ebfa1df021b5b72a53b723ac7dee90bcdaf77ae7583d1099e29746ad834423157201eed852dcfa1d9930ac878cd3081f296e1a0ccb60843aa226
7
- data.tar.gz: 8768347c02d4d2e3d7604409388a2d06194ad849f1107f4fe88ddafb0b6acff5f365460212e5799de9518fd3411e89778ee086032ef1962fb51bba6ba8493f3b
6
+ metadata.gz: f3675511414ae3db9d0b011e9c89c4c36279137bd76d636b186a8db5fbc63e66477c62fd3922f255fa8d8c9b24cb5f401a45eb708b6f3e71881d1394504aae80
7
+ data.tar.gz: 67ceccb11555c8e7bacdb5a398fafeb05fbf57a0c7208c5e2e53aba77452648f7ddb363e76cb77983b1a7cd02655f1731fd70c8ea21b83db7e98befca5b3696b
data/.consolerc CHANGED
@@ -1,10 +1,21 @@
1
1
  def start
2
2
  Journalist.start
3
- stress_gc
4
3
  end
5
4
 
6
5
  def stress_gc
7
6
  100_000.times { "foo" }
8
7
  end
9
8
 
9
+ def fibo(num)
10
+ if num < 2
11
+ num
12
+ else
13
+ fibo(num-1) + fibo(num-2)
14
+ end
15
+ end
16
+
17
+ def slow
18
+ fibo(34) # Slow enough on my computer
19
+ end
20
+
10
21
  puts "Fixtures loaded"
@@ -76,7 +76,7 @@ journalist_on_newobj(VALUE tpval, void *data) {
76
76
 
77
77
  static void
78
78
  journalist_on_freeobj(VALUE tpval, void *data) {
79
- // rb_journalist_socket_send("freeobj\n");
79
+ // TODO: Keep track of how many objects were freed and aggregate that info.
80
80
  }
81
81
 
82
82
  static int
@@ -85,11 +85,12 @@ journalist_allocations_send_locations(st_data_t key, st_data_t value, st_data_t
85
85
  char *location = (char *)key;
86
86
  int total = (int)value;
87
87
 
88
- char message[4096];
89
- sprintf(message, "newobj_loc: type %s loc %s count %d\n",
90
- type, location, total);
91
-
92
- rb_journalist_socket_send(message);
88
+ rb_journalist_socket_send(3,
89
+ "newobj_loc",
90
+ "type", 's', type,
91
+ "location", 's', location,
92
+ "count", 'i', total
93
+ );
93
94
 
94
95
  return ST_CONTINUE;
95
96
  }
@@ -99,11 +100,11 @@ journalist_allocations_send_types(st_data_t key, st_data_t value, st_data_t _) {
99
100
  char *type = (char *)key;
100
101
  aggregation_entry_t *entry = (aggregation_entry_t *)value;
101
102
 
102
- char message[4096];
103
- sprintf(message, "newobj: type %s count %d\n",
104
- type, entry->total);
105
-
106
- rb_journalist_socket_send(message);
103
+ rb_journalist_socket_send(2,
104
+ "newobj",
105
+ "type", 's', type,
106
+ "total", 'i', entry->total
107
+ );
107
108
 
108
109
  st_foreach(entry->locations, journalist_allocations_send_locations, key);
109
110
  st_free_table(entry->locations);
@@ -5,17 +5,23 @@ static struct {
5
5
  VALUE c_return;
6
6
  } calls_tp_hook;
7
7
 
8
- // TODO: For now, a very basic counter. What we really want to do is keep around
9
- // the trace argument, and keep track of what's going on at all times (maybe
10
- // even benchmark how long calls take and only output the info on return.)
11
- static int stack_size = 0;
12
-
13
- const char c_call_fmt[] = "c_call: "
14
- "class %s method %s class_method %d stack_depth %d "
15
- "path %s line %d\n";
8
+ static uint64_t call_times[MAX_CALLS] = {0};
9
+ static int call_count = 0;
16
10
 
17
11
  static void
18
12
  journalist_on_call_c_call(VALUE tpval, void *data) {
13
+ call_times[call_count] = ru_utime_usec();
14
+ call_count++;
15
+ }
16
+
17
+ static void
18
+ journalist_on_call_c_return(VALUE tpval, void *data) {
19
+ if(call_count == 0) return;
20
+ call_count--;
21
+
22
+ uint64_t diff = ru_utime_usec() - call_times[call_count];
23
+ if(diff < 250000) return;
24
+
19
25
  rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval);
20
26
 
21
27
  VALUE self = rb_tracearg_self(tparg);
@@ -24,27 +30,16 @@ journalist_on_call_c_call(VALUE tpval, void *data) {
24
30
  VALUE lineno = rb_tracearg_lineno(tparg);
25
31
  bool singleton = TYPE(self) == T_CLASS || TYPE(self) == T_MODULE;
26
32
 
27
- char buffer[4096];
28
- sprintf(buffer,
29
- c_call_fmt,
30
- rb_obj_classname(self),
31
- rb_id2name(SYM2ID(method_id)),
32
- singleton,
33
- stack_size,
34
- RSTRING_PTR(path),
35
- NUM2INT(lineno)
33
+ rb_journalist_socket_send(7,
34
+ "slow_cpu",
35
+ "class", 's', rb_obj_classname(self),
36
+ "method", 's', rb_id2name(SYM2ID(method_id)),
37
+ "class_method", 'b', singleton,
38
+ "stack_depth", 'i', call_count,
39
+ "path", 's', RSTRING_PTR(path),
40
+ "line", 'i', NUM2INT(lineno),
41
+ "diff", 't', diff
36
42
  );
37
-
38
- rb_journalist_socket_send(buffer);
39
- stack_size++;
40
- }
41
-
42
- static void
43
- journalist_on_call_c_return(VALUE tpval, void *data) {
44
- if(stack_size == 0) return;
45
-
46
- rb_journalist_socket_send("c_return\n");
47
- stack_size--;
48
43
  }
49
44
 
50
45
  void
@@ -3,6 +3,8 @@
3
3
 
4
4
  #include "journalist.h"
5
5
 
6
+ #define MAX_CALLS 32768
7
+
6
8
  void rb_journalist_calls_init();
7
9
  void rb_journalist_calls_start();
8
10
  void rb_journalist_calls_stop();
@@ -1,5 +1,7 @@
1
1
  require "mkmf"
2
2
 
3
+ pkg_config('yajl')
4
+
3
5
  $CFLAGS << " -Wall -Werror -Wno-unused-parameter "
4
6
 
5
7
  create_makefile("journalist/journalist")
@@ -31,32 +31,23 @@ static VALUE sym_count,
31
31
  sym_oldmalloc_increase,
32
32
  sym_oldmalloc_limit;
33
33
 
34
- const char gc_end_sweep_fmt[] = "gc_end_sweep: "
35
- "count %d heap_used %d heap_length %d heap_live_slot %d heap_free_slot %d "
36
- "heap_final_slot %d heap_swept_slot %d total_allocated_object %d "
37
- "total_freed_object %d malloc_increase %d malloc_limit %d "
38
- "minor_gc_count %d major_gc_count %d remembered_shady_object %d "
39
- "remembered_shady_object_limit %d old_object %d old_object_limit %d "
40
- "oldmalloc_increase %d oldmalloc_limit %d\n";
41
-
42
34
  static void
43
35
  journalist_on_gc_start(VALUE tpval, void *data) {
44
- rb_journalist_socket_send("gc_start\n");
36
+ rb_journalist_socket_send(0, "gc_start");
45
37
  }
46
38
 
47
39
  static void
48
40
  journalist_on_gc_end_mark(VALUE tpval, void *data) {
49
- rb_journalist_socket_send("gc_mark\n");
41
+ rb_journalist_socket_send(0, "gc_mark");
50
42
  }
51
43
 
52
44
  static void
53
45
  journalist_on_gc_end_sweep(VALUE tpval, void *data) {
54
- char buffer[4096];
55
46
  rb_gc_stat(cookie.gc);
56
47
 
57
- #define STAT(name) NUM2INT(rb_hash_aref(cookie.gc, sym_##name))
58
- sprintf(buffer,
59
- gc_end_sweep_fmt,
48
+ #define STAT(name) #name, 'i', NUM2INT(rb_hash_aref(cookie.gc, sym_##name))
49
+ rb_journalist_socket_send(19,
50
+ "gc_end_sweep",
60
51
  STAT(count),
61
52
  STAT(heap_used),
62
53
  STAT(heap_length),
@@ -78,8 +69,6 @@ journalist_on_gc_end_sweep(VALUE tpval, void *data) {
78
69
  STAT(oldmalloc_limit)
79
70
  );
80
71
  #undef STAT
81
-
82
- rb_journalist_socket_send(buffer);
83
72
  }
84
73
 
85
74
  void
@@ -47,3 +47,11 @@ timeofday_usec() {
47
47
  return (uint64_t)tv.tv_sec*1e6 +
48
48
  (uint64_t)tv.tv_usec;
49
49
  }
50
+
51
+ uint64_t
52
+ ru_utime_usec() {
53
+ struct rusage r_usage;
54
+ getrusage(RUSAGE_SELF, &r_usage);
55
+ return (uint64_t)r_usage.ru_utime.tv_sec*1e6 +
56
+ (uint64_t)r_usage.ru_utime.tv_usec;
57
+ }
@@ -1,6 +1,7 @@
1
1
  #ifndef JOURNALIST_H
2
2
  #define JOURNALIST_H 1
3
3
 
4
+ #include <inttypes.h>
4
5
  #include <pthread.h>
5
6
  #include <stdbool.h>
6
7
  #include <stdio.h>
@@ -16,5 +17,5 @@
16
17
  #include "socket.h"
17
18
 
18
19
  uint64_t timeofday_usec();
19
-
20
+ uint64_t ru_utime_usec();
20
21
  #endif /* JOURNALIST_H */
@@ -5,8 +5,14 @@ static pthread_mutex_t sock_mutex = PTHREAD_MUTEX_INITIALIZER;
5
5
  FILE *journalist_file;
6
6
  static char journalist_file_path_fmt[] = "/tmp/journalist-%d";
7
7
 
8
+ yajl_gen gen;
9
+
8
10
  void
9
11
  rb_journalist_socket_init() {
12
+
13
+ gen = yajl_gen_alloc(NULL);
14
+ yajl_gen_config(gen, yajl_gen_beautify, 0);
15
+
10
16
  pid_t pid = getpid();
11
17
 
12
18
  char path[1024];
@@ -21,11 +27,78 @@ rb_journalist_socket_init() {
21
27
  }
22
28
 
23
29
  void
24
- rb_journalist_socket_send(char *message) {
30
+ rb_journalist_socket_send(int count, char *event, ...)
31
+ {
25
32
  pthread_mutex_lock(&sock_mutex);
26
33
 
27
- fwrite(message, sizeof(char), strlen(message), journalist_file);
34
+ yajl_gen_map_open(gen);
35
+
36
+ yajl_gen_string(gen, (const unsigned char *)"event", 5);
37
+ yajl_gen_string(gen, (const unsigned char *)event, strlen(event));
38
+
39
+ if(count > 0) {
40
+ va_list arguments;
41
+ va_start(arguments, event);
42
+
43
+ char buf[32];
44
+ char *key;
45
+ int type;
46
+ size_t length;
47
+
48
+ char *string;
49
+ int integer;
50
+ uint64_t uint64;
51
+
52
+ int i;
53
+
54
+ for(i = 0; i < count; i++) {
55
+ key = va_arg(arguments, char *);
56
+ type = va_arg(arguments, int);
57
+
58
+ yajl_gen_string(gen, (const unsigned char *)key, strlen(key));
59
+
60
+ switch(type) {
61
+ case 's':
62
+ string = va_arg(arguments, char *);
63
+ length = strlen(string);
64
+
65
+ yajl_gen_string(gen, (const unsigned char *)string, length);
66
+ break;
67
+
68
+ case 'i':
69
+ integer = va_arg(arguments, int);
70
+ sprintf(buf, "%d", integer);
71
+ length = strlen(buf);
72
+
73
+ yajl_gen_number(gen, buf, length);
74
+ break;
75
+
76
+ case 'b':
77
+ yajl_gen_bool(gen, va_arg(arguments, int));
78
+ break;
79
+
80
+ case 't':
81
+ uint64 = va_arg(arguments, uint64_t);
82
+ sprintf(buf, "%" PRIu64, uint64);
83
+ length = strlen(buf);
84
+
85
+ yajl_gen_number(gen, buf, length);
86
+ break;
87
+ }
88
+ }
89
+ }
90
+
91
+ yajl_gen_map_close(gen);
92
+
93
+ const unsigned char *buffer;
94
+ size_t length;
95
+
96
+ yajl_gen_get_buf(gen, &buffer, &length);
97
+
98
+ fprintf(journalist_file, "%s\n", buffer);
28
99
  fflush(journalist_file);
29
100
 
101
+ yajl_gen_clear(gen);
102
+ yajl_gen_reset(gen, "");
30
103
  pthread_mutex_unlock(&sock_mutex);
31
104
  }
@@ -5,9 +5,11 @@
5
5
  #include <string.h>
6
6
  #include <unistd.h>
7
7
 
8
+ #include "yajl_gen.h"
9
+
8
10
  #include "journalist.h"
9
11
 
10
12
  void rb_journalist_socket_init();
11
- void rb_journalist_socket_send(char *message);
13
+ void rb_journalist_socket_send(int count, char *event, ...);
12
14
 
13
15
  #endif /* SOCKET_H */
@@ -1,3 +1,3 @@
1
1
  module Journalist
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journalist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Medeiros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-21 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler