From 6ed7923145ba151b841a61bbb191390f0612d585 Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Sat, 1 Nov 2014 09:12:55 +0530 Subject: [PATCH 1/8] Split object_space_dump into smaller messages --- ext/rbkit_event.c | 7 ++ ext/rbkit_event.h | 5 + ext/rbkit_event_packer.c | 165 +++++++++++++++------------ ext/rbkit_event_packer.h | 6 + ext/rbkit_message_aggregator.c | 8 +- ext/rbkit_message_aggregator.h | 7 +- ext/rbkit_tracer.c | 69 ++++++----- spec/object_space_dump_spec.rb | 28 +++-- spec/support/foo_bar_sample_class.rb | 2 +- 9 files changed, 188 insertions(+), 109 deletions(-) diff --git a/ext/rbkit_event.c b/ext/rbkit_event.c index f26b637..78e4d26 100644 --- a/ext/rbkit_event.c +++ b/ext/rbkit_event.c @@ -1,5 +1,7 @@ #include "rbkit_event.h" +static size_t snapshot_no = 0; + VALUE rbkit_event_types_as_hash() { VALUE events = rb_hash_new(); rb_hash_aset(events, ID2SYM(rb_intern("obj_created")), INT2FIX(obj_created)); @@ -54,6 +56,11 @@ rbkit_object_space_dump_event *new_rbkit_object_space_dump_event(rbkit_object_du header->event_type = object_space_dump; event->dump = dump; + event->packed_objects = 0; + event->object_count = dump->object_count; + event->current_page = dump->first; + event->current_page_index = 0; + event->snapshot_no = ++snapshot_no; return event; } diff --git a/ext/rbkit_event.h b/ext/rbkit_event.h index dc6eae4..8d6253e 100644 --- a/ext/rbkit_event.h +++ b/ext/rbkit_event.h @@ -47,6 +47,11 @@ rbkit_hash_event *new_rbkit_hash_event(rbkit_event_type event_type, VALUE hash); typedef struct _rbkit_object_space_dump_event { rbkit_event_header event_header; rbkit_object_dump *dump; + size_t packed_objects; + size_t object_count; + rbkit_object_dump_page *current_page; + size_t current_page_index; + size_t snapshot_no; } rbkit_object_space_dump_event; rbkit_object_space_dump_event *new_rbkit_object_space_dump_event(rbkit_object_dump *dump); diff --git a/ext/rbkit_event_packer.c b/ext/rbkit_event_packer.c index 9815f24..4e2f3a0 100644 --- a/ext/rbkit_event_packer.c +++ b/ext/rbkit_event_packer.c @@ -109,90 +109,111 @@ static void pack_gc_stats_event(rbkit_hash_event *event, msgpack_packer *packer) static void pack_object_space_dump_event(rbkit_object_space_dump_event *event, msgpack_packer *packer) { rbkit_object_dump *dump = event->dump; - msgpack_pack_map(packer, 3); + msgpack_pack_map(packer, 4); pack_event_header(packer, event->event_header.event_type); + + // Incrementing integer holding the snapshot no + // that the message belongs to + pack_string(packer, "snapshot_no"); + msgpack_pack_int(packer, event->snapshot_no); + pack_string(packer, "payload"); + + // Find the batch size + size_t objects_in_batch = MAX_OBJECT_DUMPS_IN_MESSAGE ; + int objects_left = event->object_count - event->packed_objects; + if(objects_left < MAX_OBJECT_DUMPS_IN_MESSAGE) + objects_in_batch = objects_left; + // Set size of array to hold all objects - msgpack_pack_array(packer, dump->object_count); + msgpack_pack_array(packer, objects_in_batch); // Iterate through all object data - rbkit_object_dump_page * page = dump->first ; - while(page != NULL) { - rbkit_object_data *data; - size_t i = 0; - for(;i < page->count; i++) { - data = &(page->data[i]); - /* Object dump is a map that looks like this : - * { - * object_id: , - * class: , - * references: [, , ...], - * file: , - * line: , - * size: - * } - */ - - msgpack_pack_map(packer, 6); - - // Key1 : "object_id" - pack_string(packer, "object_id"); - - // Value1 : pointer address of object - char * object_id; - asprintf(&object_id, "%p", data->object_id); - pack_string(packer, object_id); - free(object_id); - - // Key2 : "class_name" - pack_string(packer, "class_name"); - - // Value2 : Class name of object - pack_string(packer, data->class_name); - - // Key3 : "references" - pack_string(packer, "references"); - - // Value3 : References held by the object - msgpack_pack_array(packer, data->reference_count); - if(data->reference_count != 0) { - size_t count = 0; - for(; count < data->reference_count; count++ ) { - char * object_id; - asprintf(&object_id, "%p", data->references[count]); - pack_string(packer, object_id); - free(object_id); - } - free(data->references); + int count = 0; + int i = 0; + rbkit_object_data *data; + rbkit_object_dump_page * page; + while(count < objects_in_batch) { + if(event->current_page_index == RBKIT_OBJECT_DUMP_PAGE_SIZE) { + event->current_page_index = 0; + rbkit_object_dump_page * prev = event->current_page; + event->current_page = event->current_page->next; + free(prev); + } + page = event->current_page; + i = event->current_page_index; + data = &(page->data[i]); + /* Object dump is a map that looks like this : + * { + * object_id: , + * class: , + * references: [, , ...], + * file: , + * line: , + * size: + * } + */ + + msgpack_pack_map(packer, 6); + + // Key1 : "object_id" + pack_string(packer, "object_id"); + + // Value1 : pointer address of object + char * object_id; + asprintf(&object_id, "%p", data->object_id); + pack_string(packer, object_id); + free(object_id); + + // Key2 : "class_name" + pack_string(packer, "class_name"); + + // Value2 : Class name of object + pack_string(packer, data->class_name); + + // Key3 : "references" + pack_string(packer, "references"); + + // Value3 : References held by the object + msgpack_pack_array(packer, data->reference_count); + if(data->reference_count != 0) { + size_t count = 0; + for(; count < data->reference_count; count++ ) { + char * object_id; + asprintf(&object_id, "%p", data->references[count]); + pack_string(packer, object_id); + free(object_id); } + free(data->references); + } - // Key4 : "file" - pack_string(packer, "file"); + // Key4 : "file" + pack_string(packer, "file"); - // Value4 : File path where object is defined - pack_string(packer, data->file); + // Value4 : File path where object is defined + pack_string(packer, data->file); - // Key5 : "line" - pack_string(packer, "line"); + // Key5 : "line" + pack_string(packer, "line"); - // Value5 : Line no where object is defined - if(data->line == 0) - msgpack_pack_nil(packer); - else - msgpack_pack_unsigned_long(packer, data->line); + // Value5 : Line no where object is defined + if(data->line == 0) + msgpack_pack_nil(packer); + else + msgpack_pack_unsigned_long(packer, data->line); - // Key6 : "size" - pack_string(packer, "size"); + // Key6 : "size" + pack_string(packer, "size"); - // Value6 : Size of the object in memory - if(data->size == 0) - msgpack_pack_nil(packer); - else - msgpack_pack_uint32(packer, data->size); - } - rbkit_object_dump_page * prev = page; - page = page->next; - free(prev); + // Value6 : Size of the object in memory + if(data->size == 0) + msgpack_pack_nil(packer); + else + msgpack_pack_uint32(packer, data->size); + + event->current_page_index++; + event->packed_objects++; + count++; } } diff --git a/ext/rbkit_event_packer.h b/ext/rbkit_event_packer.h index 2307fae..d321907 100644 --- a/ext/rbkit_event_packer.h +++ b/ext/rbkit_event_packer.h @@ -3,6 +3,12 @@ #include "msgpack.h" #include "rbkit_event.h" +// Object dump will be split into multiple +// messages. This macro defines the number +// of object data that should be packed +// as the payload of one message. +#define MAX_OBJECT_DUMPS_IN_MESSAGE 20 + void pack_event(rbkit_event_header *event_header, msgpack_packer *packer); #endif diff --git a/ext/rbkit_message_aggregator.c b/ext/rbkit_message_aggregator.c index 30dff6e..3a5817d 100644 --- a/ext/rbkit_message_aggregator.c +++ b/ext/rbkit_message_aggregator.c @@ -37,7 +37,7 @@ void message_list_clear() { // Copies the msgpack sbuffer to the end of // a dynamically growing array -void add_message(msgpack_sbuffer *buffer) { +void queue_message(msgpack_sbuffer *buffer) { while(!has_enough_space_for(buffer->size)) double_the_capacity(); memcpy(message_array + used_memsize, buffer->data, buffer->size); @@ -57,3 +57,9 @@ void get_event_collection_message(msgpack_sbuffer *sbuf) { free(event); msgpack_packer_free(pk); } + +// Returns the number of messages which are queued in the +// current event_collection batch +size_t queued_message_count() { + return no_of_messages; +} diff --git a/ext/rbkit_message_aggregator.h b/ext/rbkit_message_aggregator.h index 0ba4753..5d7fe31 100644 --- a/ext/rbkit_message_aggregator.h +++ b/ext/rbkit_message_aggregator.h @@ -3,10 +3,15 @@ #include "msgpack.h" +// No of events that will be grouped +// into one event_collection message +#define MESSAGE_BATCH_SIZE 400 + void message_list_new(); -void add_message(msgpack_sbuffer *); +void queue_message(msgpack_sbuffer *); void get_event_collection_message(msgpack_sbuffer *); void message_list_destroy(); void message_list_clear(); +size_t queued_message_count(); #endif diff --git a/ext/rbkit_tracer.c b/ext/rbkit_tracer.c index e732b82..d6d5aae 100644 --- a/ext/rbkit_tracer.c +++ b/ext/rbkit_tracer.c @@ -46,6 +46,34 @@ static rbkit_logger * get_trace_logger() { return logger; } +/* + * Creates a msgpack array which contains all the messages packed after + * the last time send_messages() was called, and sends it over the PUB socket. + */ +static VALUE send_messages() { + //Get all aggregated messages as payload of a single event. + msgpack_sbuffer * sbuf = msgpack_sbuffer_new(); + get_event_collection_message(sbuf); + //Send the msgpack array over zmq PUB socket + if(sbuf && sbuf->size > 0) + zmq_send(zmq_publisher, sbuf->data, sbuf->size, 0); + // Clear the aggregated messages + message_list_clear(); + msgpack_sbuffer_free(sbuf); + return Qnil; +} + +// Adds the message to the queue and sends the queued messages if +// the queue becomes full. +static void send_message(msgpack_sbuffer *buffer) { + queue_message(buffer); + if(queued_message_count() == MESSAGE_BATCH_SIZE) { + // Always call send_messages from Ruby land. This is done + // to allow send_messages to be mocked while running tests. + rb_funcall(rb_define_module("Rbkit"), rb_intern("send_messages"), 0, NULL); + } +} + static void gc_start_i(VALUE tpval, void *data) { @@ -54,7 +82,7 @@ gc_start_i(VALUE tpval, void *data) event->event_type = gc_start; pack_event(event, arg->msgpacker); free(event); - add_message(arg->sbuf); + send_message(arg->sbuf); } static void @@ -65,7 +93,7 @@ gc_end_mark_i(VALUE tpval, void *data) event->event_type = gc_end_m; pack_event(event, arg->msgpacker); free(event); - add_message(arg->sbuf); + send_message(arg->sbuf); } static void @@ -76,7 +104,7 @@ gc_end_sweep_i(VALUE tpval, void *data) event->event_type = gc_end_s; pack_event(event, arg->msgpacker); free(event); - add_message(arg->sbuf); + send_message(arg->sbuf); } static void @@ -108,7 +136,7 @@ static void newobj_i(VALUE tpval, void *data) { rbkit_obj_created_event *event = new_rbkit_obj_created_event(obj, class_name, info); pack_event(event, arg->msgpacker); free(event); - add_message(arg->sbuf); + send_message(arg->sbuf); } // Refer Ruby source ext/objspace/object_tracing.c::freeobj_i @@ -123,7 +151,7 @@ static void freeobj_i(VALUE tpval, void *data) { rbkit_obj_destroyed_event *event = new_rbkit_obj_destroyed_event(obj); pack_event(event, arg->msgpacker); free(event); - add_message(arg->sbuf); + send_message(arg->sbuf); } static VALUE start_stat_server(int argc, VALUE *argv, VALUE self) { @@ -274,7 +302,7 @@ static VALUE send_hash_as_event(int argc, VALUE *argv, VALUE self) { pack_event(event, packer); free(event); - add_message(buffer); + send_message(buffer); msgpack_sbuffer_free(buffer); msgpack_packer_free(packer); return Qnil; @@ -299,33 +327,22 @@ static VALUE send_objectspace_dump() { rbkit_object_dump * dump = get_object_dump(logger->object_table); rbkit_object_space_dump_event *event = new_rbkit_object_space_dump_event(dump); - pack_event(event, pk); - free(event); - add_message(buffer); + // Object space dump can span across messages. + // So we keep creating and queueing the messages + // until we've packed all objects. + while(event->packed_objects < event->object_count) { + pack_event(event, pk); + send_message(buffer); + } + + free(event); free(dump); msgpack_sbuffer_free(buffer); msgpack_packer_free(pk); return Qnil; } -/* - * Creates a msgpack array which contains all the messages packed after - * the last time send_messages() was called, and sends it over the PUB socket. - */ -static VALUE send_messages() { - //Get all aggregated messages as payload of a single event. - msgpack_sbuffer * sbuf = msgpack_sbuffer_new(); - get_event_collection_message(sbuf); - //Send the msgpack array over zmq PUB socket - if(sbuf && sbuf->size > 0) - zmq_send(zmq_publisher, sbuf->data, sbuf->size, 0); - // Clear the aggregated messages - message_list_clear(); - msgpack_sbuffer_free(sbuf); - return Qnil; -} - static VALUE enable_test_mode() { Init_rbkit_test_helper(); return Qnil; diff --git a/spec/object_space_dump_spec.rb b/spec/object_space_dump_spec.rb index 74b03be..e0f1894 100644 --- a/spec/object_space_dump_spec.rb +++ b/spec/object_space_dump_spec.rb @@ -11,18 +11,30 @@ packed_message = Rbkit.get_queued_messages Rbkit.stop_server @message_list = MessagePack.unpack packed_message - @message = @message_list['payload'] - .find{|x| x['event_type'] == Rbkit::EVENT_TYPES[:object_space_dump]} - @foo_info = @message['payload'].select{|x| x['class_name'] == 'Foo'} - @bar_info = @message['payload'].select{|x| x['class_name'] == 'Bar'} - @short_lived_bar_info = @message['payload'].select{|x| x['class_name'] == 'ShortLivedBar'} - @array_info = @message['payload'] - .select{|obj| obj['object_id'] == @foo_info.first['references'].last } + @object_dump_messages = @message_list['payload'] + .select{|x| x['event_type'] == Rbkit::EVENT_TYPES[:object_space_dump]} + @foo_info = @bar_info = @array_info = @short_lived_bar_info = [] + @object_count = 0 + @object_dump_messages.each do |message| + @foo_info += message['payload'].select{|x| x['class_name'] == 'Foo'} + @bar_info += message['payload'].select{|x| x['class_name'] == 'Bar'} + @short_lived_bar_info += message['payload'].select{|x| x['class_name'] == 'ShortLivedBar'} + @object_count += message['payload'].size + end + @object_dump_messages.each do |message| + @array_info += message['payload'].select{|x| x['object_id'] == @foo_info.first['references'].last } + end + end it "should be part of message list" do expect(@message_list) .to have_message(Rbkit::EVENT_TYPES[:object_space_dump]) - .with_count(1) + end + + it 'should be split into messages of 20 objects each' do + message_count, left_over_objects = @object_count.divmod(20) + message_count += 1 unless left_over_objects.zero? + expect(@object_dump_messages.size).to eql(message_count) end it 'should record objects only once' do diff --git a/spec/support/foo_bar_sample_class.rb b/spec/support/foo_bar_sample_class.rb index 3d9f27c..7b78502 100644 --- a/spec/support/foo_bar_sample_class.rb +++ b/spec/support/foo_bar_sample_class.rb @@ -4,7 +4,7 @@ class Foo attr_reader :array, :bar def initialize @bar = Bar.new - ShortLivedBar.new #not reference outside this scope + ShortLivedBar.new #not referenced outside this scope @array = [1, 2, 3, 4, 5, 6, 7] end end From 1c1e4c73cd2ca0e21f2c687bf3331b316a50ba80 Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Sat, 1 Nov 2014 09:53:30 +0530 Subject: [PATCH 2/8] Fix crash and leak --- ext/rbkit_test_helper.c | 6 ------ ext/rbkit_tracer.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ext/rbkit_test_helper.c b/ext/rbkit_test_helper.c index 9671490..a7bb7e5 100644 --- a/ext/rbkit_test_helper.c +++ b/ext/rbkit_test_helper.c @@ -1,11 +1,6 @@ #include #include "rbkit_message_aggregator.h" -static VALUE noop_send_messages() { - //NOOP - return Qnil; -} - static VALUE get_queued_messages() { msgpack_sbuffer * sbuf = msgpack_sbuffer_new(); get_event_collection_message(sbuf); @@ -20,6 +15,5 @@ static VALUE get_queued_messages() { void Init_rbkit_test_helper(void) { VALUE rbkit_module = rb_define_module("Rbkit"); - rb_define_module_function(rbkit_module, "send_messages", noop_send_messages, 0); rb_define_module_function(rbkit_module, "get_queued_messages", get_queued_messages, 0); } diff --git a/ext/rbkit_tracer.c b/ext/rbkit_tracer.c index d6d5aae..cae7fb3 100644 --- a/ext/rbkit_tracer.c +++ b/ext/rbkit_tracer.c @@ -28,6 +28,7 @@ static void *zmq_publisher; static void *zmq_context; static void *zmq_response_socket; static zmq_pollitem_t items[1]; +static int test_mode_enabled = 0; static rbkit_logger * get_trace_logger() { int i = 0; @@ -51,6 +52,9 @@ static rbkit_logger * get_trace_logger() { * the last time send_messages() was called, and sends it over the PUB socket. */ static VALUE send_messages() { + if(test_mode_enabled) + return Qnil; //NOOP + //Get all aggregated messages as payload of a single event. msgpack_sbuffer * sbuf = msgpack_sbuffer_new(); get_event_collection_message(sbuf); @@ -67,11 +71,8 @@ static VALUE send_messages() { // the queue becomes full. static void send_message(msgpack_sbuffer *buffer) { queue_message(buffer); - if(queued_message_count() == MESSAGE_BATCH_SIZE) { - // Always call send_messages from Ruby land. This is done - // to allow send_messages to be mocked while running tests. - rb_funcall(rb_define_module("Rbkit"), rb_intern("send_messages"), 0, NULL); - } + if(queued_message_count() == MESSAGE_BATCH_SIZE) + send_messages(); } static void @@ -336,6 +337,7 @@ static VALUE send_objectspace_dump() { send_message(buffer); } + free(event->current_page); free(event); free(dump); msgpack_sbuffer_free(buffer); @@ -344,6 +346,7 @@ static VALUE send_objectspace_dump() { } static VALUE enable_test_mode() { + test_mode_enabled = 1; Init_rbkit_test_helper(); return Qnil; } From 8b2178af3501342c52834507174ded58aa228031 Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Sun, 9 Nov 2014 11:26:30 +0530 Subject: [PATCH 3/8] [ci skip] Update event format --- EVENT_FORMAT.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EVENT_FORMAT.md b/EVENT_FORMAT.md index 225b165..73c2c3e 100644 --- a/EVENT_FORMAT.md +++ b/EVENT_FORMAT.md @@ -116,6 +116,9 @@ When the GC_END_SWEEP event is triggered, no payload is sent. ### Message frame for OBJECT_SPACE_DUMP : +Object space dump is split into multiple messages. Each message is of +the following format : + ```yaml { event_type: object_space_dump From 34afe2db306603cdc891eff6aa56a8099f1a785f Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Wed, 19 Nov 2014 10:27:53 +0530 Subject: [PATCH 4/8] Update MAX_OBJECT_DUMPS_IN_MESSAGE to 1000 --- ext/rbkit_event_packer.h | 2 +- spec/object_space_dump_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/rbkit_event_packer.h b/ext/rbkit_event_packer.h index 843c71c..2c23444 100644 --- a/ext/rbkit_event_packer.h +++ b/ext/rbkit_event_packer.h @@ -7,7 +7,7 @@ // messages. This macro defines the number // of object data that should be packed // as the payload of one message. -#define MAX_OBJECT_DUMPS_IN_MESSAGE 20 +#define MAX_OBJECT_DUMPS_IN_MESSAGE 1000 typedef enum _rbkit_message_fields { rbkit_message_field_event_type, diff --git a/spec/object_space_dump_spec.rb b/spec/object_space_dump_spec.rb index f3d274f..9ade2ef 100644 --- a/spec/object_space_dump_spec.rb +++ b/spec/object_space_dump_spec.rb @@ -53,8 +53,8 @@ .to have_message(Rbkit::EVENT_TYPES[:object_space_dump]) end - it 'should be split into messages of 20 objects each' do - message_count, left_over_objects = object_count.divmod(20) + it 'should be split into messages of 1000 objects each' do + message_count, left_over_objects = object_count.divmod(1000) message_count += 1 unless left_over_objects.zero? expect(object_dump_messages.size).to eql(message_count) end From 12d4adde1a4a95bbb187a3c7074592eca65749f8 Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Wed, 21 Jan 2015 23:21:29 +0530 Subject: [PATCH 5/8] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb87eb7..b2f3922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,7 @@ v0.1.6 * First final public release * CHANGELOG.md created +WIP +=== +* Split object dump into smaller messages ([#77](https://github.com/code-mancers/rbkit/pull/77)) From f235ece3e925fa27bc088ecd7e8a0afb6464f47e Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Thu, 22 Jan 2015 13:34:28 -0500 Subject: [PATCH 6/8] Remove checked in Makefile --- .gitignore | 1 + ext/Makefile_2_2_0 | 260 --------------------------------------------- 2 files changed, 1 insertion(+), 260 deletions(-) delete mode 100644 ext/Makefile_2_2_0 diff --git a/.gitignore b/.gitignore index 43b80a7..d49d64b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /vendor/ruby/ /ext/Makefile +/ext/Makefile_2_2_0 /ext/mkmf.log /ext/rbkit_tracer.bundle /ext/*.o diff --git a/ext/Makefile_2_2_0 b/ext/Makefile_2_2_0 deleted file mode 100644 index 3443835..0000000 --- a/ext/Makefile_2_2_0 +++ /dev/null @@ -1,260 +0,0 @@ - -SHELL = /bin/sh - -# V=0 quiet, V=1 verbose. other values don't work. -V = 0 -Q1 = $(V:1=) -Q = $(Q1:0=@) -ECHO1 = $(V:1=@:) -ECHO = $(ECHO1:0=@echo) -NULLCMD = : - -#### Start of system configuration section. #### - -srcdir = . -topdir = /Users/emil/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0 -hdrdir = $(topdir) -arch_hdrdir = /Users/emil/.rvm/rubies/ruby-2.2.0/include/ruby-2.2.0/x86_64-darwin13 -PATH_SEPARATOR = : -VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby -prefix = $(DESTDIR)/Users/emil/.rvm/rubies/ruby-2.2.0 -rubysitearchprefix = $(rubylibprefix)/$(sitearch) -rubyarchprefix = $(rubylibprefix)/$(arch) -rubylibprefix = $(libdir)/$(RUBY_BASE_NAME) -exec_prefix = $(prefix) -vendorarchhdrdir = $(vendorhdrdir)/$(sitearch) -sitearchhdrdir = $(sitehdrdir)/$(sitearch) -rubyarchhdrdir = $(rubyhdrdir)/$(arch) -vendorhdrdir = $(rubyhdrdir)/vendor_ruby -sitehdrdir = $(rubyhdrdir)/site_ruby -rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME) -vendorarchdir = $(vendorlibdir)/$(sitearch) -vendorlibdir = $(vendordir)/$(ruby_version) -vendordir = $(rubylibprefix)/vendor_ruby -sitearchdir = $(sitelibdir)/$(sitearch) -sitelibdir = $(sitedir)/$(ruby_version) -sitedir = $(rubylibprefix)/site_ruby -rubyarchdir = $(rubylibdir)/$(arch) -rubylibdir = $(rubylibprefix)/$(ruby_version) -sitearchincludedir = $(includedir)/$(sitearch) -archincludedir = $(includedir)/$(arch) -sitearchlibdir = $(libdir)/$(sitearch) -archlibdir = $(libdir)/$(arch) -ridir = $(datarootdir)/$(RI_BASE_NAME) -mandir = $(datarootdir)/man -localedir = $(datarootdir)/locale -libdir = $(exec_prefix)/lib -psdir = $(docdir) -pdfdir = $(docdir) -dvidir = $(docdir) -htmldir = $(docdir) -infodir = $(datarootdir)/info -docdir = $(datarootdir)/doc/$(PACKAGE) -oldincludedir = $(DESTDIR)/usr/include -includedir = $(prefix)/include -localstatedir = $(prefix)/var -sharedstatedir = $(prefix)/com -sysconfdir = $(prefix)/etc -datadir = $(datarootdir) -datarootdir = $(prefix)/share -libexecdir = $(exec_prefix)/libexec -sbindir = $(exec_prefix)/sbin -bindir = $(exec_prefix)/bin -archdir = $(rubyarchdir) - - -CC = gcc -CXX = g++ -LIBRUBY = $(LIBRUBY_SO) -LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a -LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) -LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation -empty = -OUTFLAG = -o $(empty) -COUTFLAG = -o $(empty) - -RUBY_EXTCONF_H = -cflags = $(optflags) $(debugflags) $(warnflags) -optflags = -O3 -fno-fast-math -debugflags = -ggdb3 -warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -CCDLFLAGS = -fno-common -CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe -g $(ARCH_FLAG) -INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir) -DEFS = -CPPFLAGS = -DRBKIT_DEV -DHAVE_RB_POSTPONED_JOB_REGISTER_ONE -DHAVE_RB_PROFILE_FRAMES -DHAVE_RB_TRACEPOINT_NEW -DHAVE_CONST_RUBY_INTERNAL_EVENT_NEWOBJ -DHAVE_ZMQ_H -DHAVE_MSGPACK_H -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags) -CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG) -ldflags = -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -ARCH_FLAG = -DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) -LDSHARED = $(CC) -dynamic -bundle -LDSHAREDXX = $(CXX) -dynamic -bundle -AR = ar -EXEEXT = - -RUBY_INSTALL_NAME = $(RUBY_BASE_NAME) -RUBY_SO_NAME = ruby.2.2.0 -RUBYW_INSTALL_NAME = -RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version) -RUBYW_BASE_NAME = rubyw -RUBY_BASE_NAME = ruby - -arch = x86_64-darwin13 -sitearch = $(arch) -ruby_version = 2.2.0 -ruby = $(bindir)/$(RUBY_BASE_NAME) -RUBY = $(ruby) -ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h - -RM = rm -f -RM_RF = $(RUBY) -run -e rm -- -rf -RMDIRS = rmdir -p -MAKEDIRS = mkdir -p -INSTALL = /usr/bin/install -c -INSTALL_PROG = $(INSTALL) -m 0755 -INSTALL_DATA = $(INSTALL) -m 644 -COPY = cp -TOUCH = exit > - -#### End of system configuration section. #### - -preload = - -libpath = /usr/local/opt/libyaml/lib /usr/local/opt/readline/lib /usr/local/opt/libksba/lib /usr/local/opt/openssl/lib . $(libdir) -LIBPATH = -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -L$(libdir) -DEFFILE = - -CLEANFILES = mkmf.log -DISTCLEANFILES = -DISTCLEANDIRS = - -extout = -extout_prefix = -target_prefix = -LOCAL_LIBS = -LIBS = $(LIBRUBYARG_SHARED) -lmsgpack -lzmq -lpthread -ldl -lobjc -ORIG_SRCS = rbkit_allocation_info.c rbkit_event.c rbkit_event_packer.c rbkit_message_aggregator.c rbkit_object_graph.c rbkit_test_helper.c rbkit_tracer.c -SRCS = $(ORIG_SRCS) -OBJS = rbkit_allocation_info.o rbkit_event.o rbkit_event_packer.o rbkit_message_aggregator.o rbkit_object_graph.o rbkit_test_helper.o rbkit_tracer.o -HDRS = $(srcdir)/rbkit_allocation_info.h $(srcdir)/rbkit_event.h $(srcdir)/rbkit_event_packer.h $(srcdir)/rbkit_message_aggregator.h $(srcdir)/rbkit_object_graph.h $(srcdir)/rbkit_test_helper.h $(srcdir)/rbkit_tracer.h -TARGET = rbkit_tracer -TARGET_NAME = rbkit_tracer -TARGET_ENTRY = Init_$(TARGET_NAME) -DLLIB = $(TARGET).bundle -EXTSTATIC = -STATIC_LIB = - -TIMESTAMP_DIR = . -BINDIR = $(bindir) -RUBYCOMMONDIR = $(sitedir)$(target_prefix) -RUBYLIBDIR = $(sitelibdir)$(target_prefix) -RUBYARCHDIR = $(sitearchdir)$(target_prefix) -HDRDIR = $(rubyhdrdir)/ruby$(target_prefix) -ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix) - -TARGET_SO = $(DLLIB) -CLEANLIBS = $(TARGET).bundle -CLEANOBJS = *.o *.bak - -all: $(DLLIB) -static: $(STATIC_LIB) -.PHONY: all install static install-so install-rb -.PHONY: clean clean-so clean-static clean-rb - -clean-static:: -clean-rb-default:: -clean-rb:: -clean-so:: -clean: clean-so clean-static clean-rb-default clean-rb - -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time - -distclean-rb-default:: -distclean-rb:: -distclean-so:: -distclean-static:: -distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb - -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log - -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) - -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true - -realclean: distclean -install: install-so install-rb - -install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time - $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) -clean-static:: - -$(Q)$(RM) $(STATIC_LIB) -install-rb: pre-install-rb install-rb-default -install-rb-default: pre-install-rb-default -pre-install-rb: Makefile -pre-install-rb-default: Makefile -pre-install-rb-default: - @$(NULLCMD) -$(TIMESTAMP_DIR)/.RUBYARCHDIR.time: - $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR) - $(Q) $(TOUCH) $@ - -site-install: site-install-so site-install-rb -site-install-so: install-so -site-install-rb: install-rb - -.SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S - -.cc.o: - $(ECHO) compiling $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cc.S: - $(ECHO) translating $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< - -.mm.o: - $(ECHO) compiling $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.mm.S: - $(ECHO) translating $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< - -.cxx.o: - $(ECHO) compiling $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cxx.S: - $(ECHO) translating $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< - -.cpp.o: - $(ECHO) compiling $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cpp.S: - $(ECHO) translating $(<) - $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $< - -.c.o: - $(ECHO) compiling $(<) - $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< - -.c.S: - $(ECHO) translating $(<) - $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $< - -.m.o: - $(ECHO) compiling $(<) - $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< - -.m.S: - $(ECHO) translating $(<) - $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $< - -$(DLLIB): $(OBJS) Makefile - $(ECHO) linking shared-object $(DLLIB) - -$(Q)$(RM) $(@) - $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) - $(Q) $(POSTLINK) - - - -$(OBJS): $(HDRS) $(ruby_headers) From c1a3f143c81ea9564ed9021c6a59749e02879e7c Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Fri, 23 Jan 2015 11:06:49 -0500 Subject: [PATCH 7/8] Bump the protcol version This version of protocol is not compatible with previous version. --- ext/rbkit_event_packer.h | 2 +- spec/status_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/rbkit_event_packer.h b/ext/rbkit_event_packer.h index 2acaee7..a953b07 100644 --- a/ext/rbkit_event_packer.h +++ b/ext/rbkit_event_packer.h @@ -1,6 +1,6 @@ #ifndef RBKIT_MESSAGE_PACKER #define RBKIT_MESSAGE_PACKER -#define RBKIT_PROTOCOL_VERSION "1.0" +#define RBKIT_PROTOCOL_VERSION "1.1" #include "msgpack.h" #include "rbkit_event.h" diff --git a/spec/status_spec.rb b/spec/status_spec.rb index 4093025..5c7f5fe 100644 --- a/spec/status_spec.rb +++ b/spec/status_spec.rb @@ -56,7 +56,7 @@ describe 'rbkit_protocol_version field' do let(:field) { Rbkit.status[:rbkit_protocol_version] } it 'should be equal to Rbkit version' do - expect(Rbkit::PROTOCOL_VERSION).to eql "1.0" + expect(Rbkit::PROTOCOL_VERSION).to eql "1.1" expect(field).to eql Rbkit::PROTOCOL_VERSION end end From 4dceaf185bcba0241a385a7c3b18972d4133501f Mon Sep 17 00:00:00 2001 From: Emil Soman Date: Sat, 24 Jan 2015 01:09:59 +0530 Subject: [PATCH 8/8] Rename snapshot_no to correlation_id --- docs/protocol.md | 2 +- ext/rbkit_event.c | 4 ++-- ext/rbkit_event.h | 2 +- ext/rbkit_event_packer.c | 10 +++++----- ext/rbkit_event_packer.h | 2 +- spec/object_space_dump_spec.rb | 7 +++++++ 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/protocol.md b/docs/protocol.md index 6bf4d21..e1bd0b5 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -176,8 +176,8 @@ the following format : timestamp: , payload: [ { + correlation_id: , object_id: , - snapshot_no: , class_name: , references: [, , ... ], file: , diff --git a/ext/rbkit_event.c b/ext/rbkit_event.c index 4cd4887..c16653b 100644 --- a/ext/rbkit_event.c +++ b/ext/rbkit_event.c @@ -1,6 +1,6 @@ #include "rbkit_event.h" -static size_t snapshot_no = 0; +static size_t correlation_id = 0; VALUE rbkit_event_types_as_hash() { VALUE events = rb_hash_new(); @@ -61,7 +61,7 @@ rbkit_object_space_dump_event *new_rbkit_object_space_dump_event(rbkit_object_du event->object_count = dump->object_count; event->current_page = dump->first; event->current_page_index = 0; - event->snapshot_no = ++snapshot_no; + event->correlation_id = ++correlation_id; return event; } diff --git a/ext/rbkit_event.h b/ext/rbkit_event.h index f8fa089..647dd0d 100644 --- a/ext/rbkit_event.h +++ b/ext/rbkit_event.h @@ -51,7 +51,7 @@ typedef struct _rbkit_object_space_dump_event { size_t object_count; rbkit_object_dump_page *current_page; size_t current_page_index; - size_t snapshot_no; + size_t correlation_id; } rbkit_object_space_dump_event; rbkit_object_space_dump_event *new_rbkit_object_space_dump_event(rbkit_object_dump *dump); diff --git a/ext/rbkit_event_packer.c b/ext/rbkit_event_packer.c index c363dd8..adc8c0a 100644 --- a/ext/rbkit_event_packer.c +++ b/ext/rbkit_event_packer.c @@ -105,10 +105,10 @@ static void pack_object_space_dump_event(rbkit_object_space_dump_event *event, m msgpack_pack_map(packer, 4); pack_event_header(packer, event->event_header.event_type); - // Incrementing integer holding the snapshot no - // that the message belongs to - msgpack_pack_int(packer, rbkit_message_field_snapshot_no); - msgpack_pack_int(packer, event->snapshot_no); + // Incrementing integer holding the correlation_id + // indicating the event which the message belongs to + msgpack_pack_int(packer, rbkit_message_field_correlation_id); + msgpack_pack_int(packer, event->correlation_id); msgpack_pack_int(packer, rbkit_message_field_payload); @@ -267,7 +267,7 @@ VALUE rbkit_message_fields_as_hash() { rb_hash_aset(events, ID2SYM(rb_intern("line")), INT2FIX(rbkit_message_field_line)); rb_hash_aset(events, ID2SYM(rb_intern("size")), INT2FIX(rbkit_message_field_size)); rb_hash_aset(events, ID2SYM(rb_intern("message_counter")), INT2FIX(rbkit_message_field_message_counter)); - rb_hash_aset(events, ID2SYM(rb_intern("snapshot_no")), INT2FIX(rbkit_message_field_snapshot_no)); + rb_hash_aset(events, ID2SYM(rb_intern("correlation_id")), INT2FIX(rbkit_message_field_correlation_id)); OBJ_FREEZE(events); return events; } diff --git a/ext/rbkit_event_packer.h b/ext/rbkit_event_packer.h index 2acaee7..847ba78 100644 --- a/ext/rbkit_event_packer.h +++ b/ext/rbkit_event_packer.h @@ -21,7 +21,7 @@ typedef enum _rbkit_message_fields { rbkit_message_field_line, rbkit_message_field_size, rbkit_message_field_message_counter, - rbkit_message_field_snapshot_no + rbkit_message_field_correlation_id } rbkit_message_fields; VALUE rbkit_message_fields_as_hash(); diff --git a/spec/object_space_dump_spec.rb b/spec/object_space_dump_spec.rb index 9aecc32..7ca6ae7 100644 --- a/spec/object_space_dump_spec.rb +++ b/spec/object_space_dump_spec.rb @@ -11,6 +11,7 @@ let(:line) { Rbkit::MESSAGE_FIELDS[:line] } let(:size_field) { Rbkit::MESSAGE_FIELDS[:size] } let(:references) { Rbkit::MESSAGE_FIELDS[:references] } + let(:correlation_id) { Rbkit::MESSAGE_FIELDS[:correlation_id] } let(:object_dump_messages) do @message_list[payload] .select{|x| x[event_type] == Rbkit::EVENT_TYPES[:object_space_dump]} @@ -92,4 +93,10 @@ it 'should record correct size' do expect(array_info.first[size_field]).to be > 0 end + + it 'should record correct correlation_id' do + foo_correlation_id = foo_info.first[correlation_id] + expect(bar_info.first[correlation_id]).to eql foo_correlation_id + expect(array_info.first[correlation_id]).to eql foo_correlation_id + end end