Class: Ruby::Coverage::Tracer

Inherits:
Object
  • Object
show all
Defined in:
ext/ruby/coverage/tracer.c

Instance Method Summary collapse

Constructor Details

#initializeObject



148
149
150
151
152
153
154
155
156
157
# File 'ext/ruby/coverage/tracer.c', line 148

static VALUE Ruby_Coverage_Tracer_initialize(VALUE self)
{
	struct Ruby_Coverage_Tracer *tracer;
	TypedData_Get_Struct(self, struct Ruby_Coverage_Tracer,
	                     &Ruby_Coverage_Tracer_type, tracer);

	RB_OBJ_WRITE(self, &tracer->callback, rb_block_proc());

	return self;
}

Instance Method Details

#startObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'ext/ruby/coverage/tracer.c', line 292

static VALUE Ruby_Coverage_Tracer_start(VALUE self)
{
	#ifdef HAVE_RB_TRACEARG_INSTRUCTION_SEQUENCE
	rb_add_event_hook2(
		(rb_event_hook_func_t)Ruby_Coverage_Tracer_on_script_compiled,
		RUBY_EVENT_SCRIPT_COMPILED,
		self,
		RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG
	);
	#else
	struct Ruby_Coverage_Tracer *tracer;
	TypedData_Get_Struct(self, struct Ruby_Coverage_Tracer, &Ruby_Coverage_Tracer_type, tracer);

	if (NIL_P(tracer->script_compiled_tracepoint)) {
		RB_OBJ_WRITE(self, &tracer->script_compiled_tracepoint,
			rb_tracepoint_new(Qnil, RUBY_EVENT_SCRIPT_COMPILED,
				Ruby_Coverage_Tracer_on_script_compiled, tracer));
	}

	rb_tracepoint_enable(tracer->script_compiled_tracepoint);
	#endif

	rb_add_event_hook2(
		(rb_event_hook_func_t)Ruby_Coverage_Tracer_on_line,
		RUBY_EVENT_LINE,
		self,
		RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG
	);

	return self;
}

#stopObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'ext/ruby/coverage/tracer.c', line 324

static VALUE Ruby_Coverage_Tracer_stop(VALUE self)
{
	struct Ruby_Coverage_Tracer *tracer;
	TypedData_Get_Struct(self, struct Ruby_Coverage_Tracer, &Ruby_Coverage_Tracer_type, tracer);

	#ifdef HAVE_RB_TRACEARG_INSTRUCTION_SEQUENCE
	rb_remove_event_hook_with_data((rb_event_hook_func_t)Ruby_Coverage_Tracer_on_script_compiled, self);
	#else
	if (!NIL_P(tracer->script_compiled_tracepoint)) {
		rb_tracepoint_disable(tracer->script_compiled_tracepoint);
	}
	#endif

	rb_remove_event_hook_with_data((rb_event_hook_func_t)Ruby_Coverage_Tracer_on_line, self);

	tracer->last_path_pointer = 0;
	RB_OBJ_WRITE(self, &tracer->last_counts, Qnil);

	return self;
}