pline 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README +134 -0
  2. data/ext/pline/depend +55 -0
  3. data/ext/pline/extconf.rb +14 -0
  4. data/ext/pline/iseq.c +124 -0
  5. data/ext/pline/minfo.c +167 -0
  6. data/ext/pline/pline.c.rb +68 -0
  7. data/ext/pline/profiler.c +125 -0
  8. data/ext/pline/ruby_source/1.9.2/debug.h +36 -0
  9. data/ext/pline/ruby_source/1.9.2/eval_intern.h +232 -0
  10. data/ext/pline/ruby_source/1.9.2/gc.h +77 -0
  11. data/ext/pline/ruby_source/1.9.2/id.h +170 -0
  12. data/ext/pline/ruby_source/1.9.2/insns.inc +179 -0
  13. data/ext/pline/ruby_source/1.9.2/insns_info.inc +695 -0
  14. data/ext/pline/ruby_source/1.9.2/iseq.h +104 -0
  15. data/ext/pline/ruby_source/1.9.2/manual_update.h +19 -0
  16. data/ext/pline/ruby_source/1.9.2/method.h +103 -0
  17. data/ext/pline/ruby_source/1.9.2/node.h +483 -0
  18. data/ext/pline/ruby_source/1.9.2/thread_pthread.h +27 -0
  19. data/ext/pline/ruby_source/1.9.2/thread_win32.h +33 -0
  20. data/ext/pline/ruby_source/1.9.2/vm_core.h +706 -0
  21. data/ext/pline/ruby_source/1.9.2/vm_exec.h +184 -0
  22. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.c +1734 -0
  23. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.h +208 -0
  24. data/ext/pline/ruby_source/1.9.2/vm_opts.h +51 -0
  25. data/ext/pline/ruby_source/1.9.3/atomic.h +56 -0
  26. data/ext/pline/ruby_source/1.9.3/constant.h +34 -0
  27. data/ext/pline/ruby_source/1.9.3/debug.h +41 -0
  28. data/ext/pline/ruby_source/1.9.3/eval_intern.h +234 -0
  29. data/ext/pline/ruby_source/1.9.3/gc.h +98 -0
  30. data/ext/pline/ruby_source/1.9.3/id.h +175 -0
  31. data/ext/pline/ruby_source/1.9.3/insns.inc +179 -0
  32. data/ext/pline/ruby_source/1.9.3/insns_info.inc +695 -0
  33. data/ext/pline/ruby_source/1.9.3/internal.h +227 -0
  34. data/ext/pline/ruby_source/1.9.3/iseq.h +125 -0
  35. data/ext/pline/ruby_source/1.9.3/manual_update.h +19 -0
  36. data/ext/pline/ruby_source/1.9.3/method.h +105 -0
  37. data/ext/pline/ruby_source/1.9.3/node.h +503 -0
  38. data/ext/pline/ruby_source/1.9.3/thread_pthread.h +51 -0
  39. data/ext/pline/ruby_source/1.9.3/thread_win32.h +40 -0
  40. data/ext/pline/ruby_source/1.9.3/vm_core.h +756 -0
  41. data/ext/pline/ruby_source/1.9.3/vm_exec.h +184 -0
  42. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.c +1749 -0
  43. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.h +220 -0
  44. data/ext/pline/ruby_source/1.9.3/vm_opts.h +51 -0
  45. data/ext/pline/sinfo.c +311 -0
  46. data/lib/pline.rb +11 -0
  47. data/lib/pline/minfo.rb +22 -0
  48. data/lib/pline/summarize.rb +127 -0
  49. data/lib/pline/util.rb +54 -0
  50. data/pline.gemspec +28 -0
  51. metadata +102 -0
@@ -0,0 +1,220 @@
1
+ /**********************************************************************
2
+
3
+ insnhelper.h - helper macros to implement each instructions
4
+
5
+ $Author$
6
+ created at: 04/01/01 15:50:34 JST
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_INSNHELPER_H
13
+ #define RUBY_INSNHELPER_H
14
+
15
+ /**
16
+ * VM Debug Level
17
+ *
18
+ * debug level:
19
+ * 0: no debug output
20
+ * 1: show instruction name
21
+ * 2: show stack frame when control stack frame is changed
22
+ * 3: show stack status
23
+ * 4: show register
24
+ * 5:
25
+ * 10: gc check
26
+ */
27
+
28
+ #ifndef VMDEBUG
29
+ #define VMDEBUG 0
30
+ #endif
31
+
32
+ #if 0
33
+ #undef VMDEBUG
34
+ #define VMDEBUG 3
35
+ #endif
36
+
37
+ enum {
38
+ BOP_PLUS,
39
+ BOP_MINUS,
40
+ BOP_MULT,
41
+ BOP_DIV,
42
+ BOP_MOD,
43
+ BOP_EQ,
44
+ BOP_EQQ,
45
+ BOP_LT,
46
+ BOP_LE,
47
+ BOP_LTLT,
48
+ BOP_AREF,
49
+ BOP_ASET,
50
+ BOP_LENGTH,
51
+ BOP_SIZE,
52
+ BOP_SUCC,
53
+ BOP_GT,
54
+ BOP_GE,
55
+ BOP_NOT,
56
+ BOP_NEQ,
57
+
58
+ BOP_LAST_
59
+ };
60
+
61
+ extern char ruby_vm_redefined_flag[BOP_LAST_];
62
+ extern VALUE ruby_vm_const_missing_count;
63
+
64
+
65
+ /**********************************************************/
66
+ /* deal with stack */
67
+ /**********************************************************/
68
+
69
+ #define PUSH(x) (SET_SV(x), INC_SP(1))
70
+ #define TOPN(n) (*(GET_SP()-(n)-1))
71
+ #define POPN(n) (DEC_SP(n))
72
+ #define POP() (DEC_SP(1))
73
+ #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
74
+
75
+ #define GET_TOS() (tos) /* dummy */
76
+
77
+ /**********************************************************/
78
+ /* deal with registers */
79
+ /**********************************************************/
80
+
81
+ #define REG_CFP (reg_cfp)
82
+ #define REG_PC (REG_CFP->pc)
83
+ #define REG_SP (REG_CFP->sp)
84
+ #define REG_LFP (REG_CFP->lfp)
85
+ #define REG_DFP (REG_CFP->dfp)
86
+
87
+ #define RESTORE_REGS() do { \
88
+ REG_CFP = th->cfp; \
89
+ } while (0)
90
+
91
+ #define REG_A reg_a
92
+ #define REG_B reg_b
93
+
94
+ #ifdef COLLECT_USAGE_ANALYSIS
95
+ #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
96
+ (USAGE_ANALYSIS_REGISTER((a), (b)), (v))
97
+ #else
98
+ #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) (v)
99
+ #endif
100
+
101
+ /* PC */
102
+ #define GET_PC() (USAGE_ANALYSIS_REGISTER_HELPER(0, 0, REG_PC))
103
+ #define SET_PC(x) (REG_PC = (USAGE_ANALYSIS_REGISTER_HELPER(0, 1, (x))))
104
+ #define GET_CURRENT_INSN() (*GET_PC())
105
+ #define GET_OPERAND(n) (GET_PC()[(n)])
106
+ #define ADD_PC(n) (SET_PC(REG_PC + (n)))
107
+
108
+ #define GET_PC_COUNT() (REG_PC - GET_ISEQ()->iseq_encoded)
109
+ #define JUMP(dst) (REG_PC += (dst))
110
+
111
+ /* FP */
112
+ #define GET_CFP() (USAGE_ANALYSIS_REGISTER_HELPER(2, 0, REG_CFP))
113
+ #define GET_LFP() (USAGE_ANALYSIS_REGISTER_HELPER(3, 0, REG_LFP))
114
+ #define SET_LFP(x) (REG_LFP = (USAGE_ANALYSIS_REGISTER_HELPER(3, 1, (x))))
115
+ #define GET_DFP() (USAGE_ANALYSIS_REGISTER_HELPER(4, 0, REG_DFP))
116
+ #define SET_DFP(x) (REG_DFP = (USAGE_ANALYSIS_REGISTER_HELPER(4, 1, (x))))
117
+
118
+ /* SP */
119
+ #define GET_SP() (USAGE_ANALYSIS_REGISTER_HELPER(1, 0, REG_SP))
120
+ #define SET_SP(x) (REG_SP = (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
121
+ #define INC_SP(x) (REG_SP += (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
122
+ #define DEC_SP(x) (REG_SP -= (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
123
+ #define SET_SV(x) (*GET_SP() = (x))
124
+ /* set current stack value as x */
125
+
126
+ #define GET_SP_COUNT() (REG_SP - th->stack)
127
+
128
+ /* instruction sequence C struct */
129
+ #define GET_ISEQ() (GET_CFP()->iseq)
130
+
131
+ /**********************************************************/
132
+ /* deal with variables */
133
+ /**********************************************************/
134
+
135
+ #define GET_PREV_DFP(dfp) ((VALUE *)((dfp)[0] & ~0x03))
136
+
137
+ #define GET_GLOBAL(entry) rb_gvar_get((struct rb_global_entry*)(entry))
138
+ #define SET_GLOBAL(entry, val) rb_gvar_set((struct rb_global_entry*)(entry), (val))
139
+
140
+ #define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 2))
141
+
142
+ /**********************************************************/
143
+ /* deal with values */
144
+ /**********************************************************/
145
+
146
+ #define GET_SELF() (USAGE_ANALYSIS_REGISTER_HELPER(5, 0, GET_CFP()->self))
147
+
148
+ /**********************************************************/
149
+ /* deal with control flow 2: method/iterator */
150
+ /**********************************************************/
151
+
152
+ #define COPY_CREF(c1, c2) do { \
153
+ NODE *__tmp_c2 = (c2); \
154
+ (c1)->nd_clss = __tmp_c2->nd_clss; \
155
+ (c1)->nd_visi = __tmp_c2->nd_visi;\
156
+ (c1)->nd_next = __tmp_c2->nd_next; \
157
+ if (__tmp_c2->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { \
158
+ (c1)->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; \
159
+ } \
160
+ } while (0)
161
+
162
+ #define CALL_METHOD(num, blockptr, flag, id, me, recv) do { \
163
+ VALUE v = vm_call_method(th, GET_CFP(), (num), (blockptr), (flag), (id), (me), (recv)); \
164
+ if (v == Qundef) { \
165
+ RESTORE_REGS(); \
166
+ NEXT_INSN(); \
167
+ } \
168
+ else { \
169
+ val = v; \
170
+ } \
171
+ } while (0)
172
+
173
+ #define GET_BLOCK_PTR() \
174
+ ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LFP()[0] & \
175
+ ((GET_LFP()[0] & 0x02) - 0x02))))
176
+
177
+ /**********************************************************/
178
+ /* deal with control flow 3: exception */
179
+ /**********************************************************/
180
+
181
+
182
+ /**********************************************************/
183
+ /* others */
184
+ /**********************************************************/
185
+
186
+ /* optimize insn */
187
+ #define FIXNUM_2_P(a, b) ((a) & (b) & 1)
188
+ #define BASIC_OP_UNREDEFINED_P(op) (LIKELY(ruby_vm_redefined_flag[(op)] == 0))
189
+ #define HEAP_CLASS_OF(obj) RBASIC(obj)->klass
190
+
191
+ #ifndef USE_IC_FOR_SPECIALIZED_METHOD
192
+ #define USE_IC_FOR_SPECIALIZED_METHOD 1
193
+ #endif
194
+
195
+ #if USE_IC_FOR_SPECIALIZED_METHOD
196
+
197
+ #define CALL_SIMPLE_METHOD(num, id, recv) do { \
198
+ VALUE klass = CLASS_OF(recv); \
199
+ CALL_METHOD((num), 0, 0, (id), vm_method_search((id), klass, ic), (recv)); \
200
+ } while (0)
201
+
202
+ #else
203
+
204
+ #define CALL_SIMPLE_METHOD(num, id, recv) do { \
205
+ VALUE klass = CLASS_OF(recv); \
206
+ CALL_METHOD((num), 0, 0, (id), rb_method_entry(klass, (id)), (recv)); \
207
+ } while (0)
208
+
209
+ #endif
210
+
211
+ static VALUE ruby_vm_global_state_version = 1;
212
+
213
+ #define GET_VM_STATE_VERSION() (ruby_vm_global_state_version)
214
+ #define INC_VM_STATE_VERSION() do { \
215
+ ruby_vm_global_state_version = (ruby_vm_global_state_version + 1); \
216
+ if (ruby_vm_global_state_version == 0) vm_clear_all_cache(); \
217
+ } while (0)
218
+ static void vm_clear_all_cache(void);
219
+
220
+ #endif /* RUBY_INSNHELPER_H */
@@ -0,0 +1,51 @@
1
+ /*-*-c-*-*/
2
+ /**********************************************************************
3
+
4
+ vm_opts.h - VM optimize option
5
+
6
+ $Author$
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+
13
+ #ifndef RUBY_VM_OPTS_H
14
+ #define RUBY_VM_OPTS_H
15
+
16
+ /* Compile options.
17
+ * You can change these options at runtime by VM::CompileOption.
18
+ * Following definitions are default values.
19
+ */
20
+
21
+ #define OPT_TRACE_INSTRUCTION 1
22
+ #define OPT_TAILCALL_OPTIMIZATION 0
23
+ #define OPT_PEEPHOLE_OPTIMIZATION 1
24
+ #define OPT_SPECIALISED_INSTRUCTION 1
25
+ #define OPT_INLINE_CONST_CACHE 1
26
+
27
+
28
+ /* Build Options.
29
+ * You can't change these options at runtime.
30
+ */
31
+
32
+ /* C compiler depend */
33
+ #define OPT_DIRECT_THREADED_CODE 1
34
+ #define OPT_TOKEN_THREADED_CODE 0
35
+ #define OPT_CALL_THREADED_CODE 0
36
+
37
+ /* VM running option */
38
+ #define OPT_CHECKED_RUN 1
39
+ #define OPT_INLINE_METHOD_CACHE 1
40
+ #define OPT_BLOCKINLINING 0
41
+
42
+ /* architecture independent, affects generated code */
43
+ #define OPT_OPERANDS_UNIFICATION 0
44
+ #define OPT_INSTRUCTIONS_UNIFICATION 0
45
+ #define OPT_UNIFY_ALL_COMBINATION 0
46
+ #define OPT_STACK_CACHING 0
47
+
48
+ /* misc */
49
+ #define SUPPORT_JOKE 0
50
+
51
+ #endif /* RUBY_VM_OPTS_H */
@@ -0,0 +1,311 @@
1
+ static st_table *scoring_sinfo_table;
2
+ static st_table *preline_sinfo_table;
3
+
4
+ typedef unsigned long long int pline_time_t;
5
+
6
+ /* pline_sinfo_container */
7
+ typedef struct pline_sinfo_container {
8
+ st_table *sinfo_table;
9
+ } pline_sinfo_container_t;
10
+ static ID sinfo_container_id;
11
+
12
+ static int sinfo_container_mark_i(st_data_t key, st_data_t value, st_data_t arg)
13
+ {
14
+ VALUE sinfo = (VALUE)value;
15
+ rb_gc_mark(sinfo);
16
+ return ST_CONTINUE;
17
+ }
18
+
19
+ static void sinfo_container_mark(void *p)
20
+ {
21
+ pline_sinfo_container_t *s = p;
22
+
23
+ if (!s) return;
24
+ st_foreach(s->sinfo_table, sinfo_container_mark_i, 0);
25
+ }
26
+
27
+ static void sinfo_container_free(void *p)
28
+ {
29
+ pline_sinfo_container_t *s = p;
30
+
31
+ if (!s) return;
32
+
33
+ st_free_table(s->sinfo_table);
34
+ xfree(s);
35
+ }
36
+
37
+ static const rb_data_type_t sinfo_container_data_type = {
38
+ "pline_sinfo_container",
39
+ {sinfo_container_mark, sinfo_container_free, NULL,},
40
+ };
41
+
42
+ static VALUE sinfo_container_s_alloc(VALUE klass)
43
+ {
44
+ VALUE obj;
45
+ pline_sinfo_container_t *s;
46
+
47
+ obj = TypedData_Make_Struct(klass, pline_sinfo_container_t, &sinfo_container_data_type, s);
48
+ s->sinfo_table = st_init_strtable();
49
+
50
+ return obj;
51
+ }
52
+
53
+ static st_table* sinfo_container_process_sinfo_table(void)
54
+ {
55
+ VALUE scon, thval = rb_thread_current();
56
+ pline_sinfo_container_t *s;
57
+
58
+ scon = rb_thread_local_aref(thval, sinfo_container_id);
59
+ if (!RTEST(scon)) {
60
+ scon = rb_funcall(cSourceInfoContainer, rb_intern("new"), 0);
61
+ rb_thread_local_aset(thval, sinfo_container_id, scon);
62
+ }
63
+ s = DATA_PTR(scon);
64
+
65
+ return s->sinfo_table;
66
+ }
67
+
68
+ /* pline_src_info */
69
+
70
+ typedef union pline_line_info {
71
+ pline_time_t score;
72
+ pline_time_t start;
73
+ long prev;
74
+ } pline_line_info_t;
75
+
76
+ typedef struct pline_src_info {
77
+ pline_line_info_t *lines;
78
+ long size;
79
+ } pline_src_info_t;
80
+
81
+ static void sinfo_mark(void *p)
82
+ {
83
+ pline_src_info_t *s = p;
84
+
85
+ if (!s) return;
86
+ }
87
+
88
+ static void sinfo_free(void *p)
89
+ {
90
+ pline_src_info_t *s = p;
91
+
92
+ if (!s) return;
93
+
94
+ if (s->lines) {
95
+ xfree(s->lines);
96
+ }
97
+ xfree(s);
98
+ }
99
+
100
+ static const rb_data_type_t sinfo_data_type = {
101
+ "pline_src_info",
102
+ {sinfo_mark, sinfo_free, NULL,},
103
+ };
104
+
105
+ static VALUE sinfo_s_alloc(VALUE klass)
106
+ {
107
+ VALUE obj;
108
+ pline_src_info_t *s;
109
+
110
+ obj = TypedData_Make_Struct(klass, pline_src_info_t, &sinfo_data_type, s);
111
+ s->lines = NULL;
112
+ s->size = 0;
113
+
114
+ return obj;
115
+ }
116
+
117
+ static VALUE sinfo_m_lines(VALUE self)
118
+ {
119
+ pline_src_info_t *s = DATA_PTR(self);
120
+ VALUE lines = rb_ary_new2(s->size);
121
+ int i;
122
+
123
+ for (i = 0; i < s->size; i++) {
124
+ rb_ary_push(lines, LL2NUM(s->lines[i].score));
125
+ }
126
+
127
+ return lines;
128
+ }
129
+
130
+ static VALUE sinfo_find(st_table *sinfo_table, const char *s)
131
+ {
132
+ VALUE sinfo;
133
+
134
+ if (st_lookup(sinfo_table, (st_data_t)s, (st_data_t*)&sinfo)) {
135
+ return sinfo;
136
+ } else {
137
+ return Qnil;
138
+ }
139
+ }
140
+
141
+ static void sinfo_allocate_lines(pline_src_info_t *sinfo, long line)
142
+ {
143
+ if (sinfo->lines) {
144
+ REALLOC_N(sinfo->lines, pline_line_info_t, line);
145
+ } else {
146
+ sinfo->lines = ALLOC_N(pline_line_info_t, line);
147
+ }
148
+ }
149
+
150
+ /* for scoring */
151
+ static VALUE sinfo_find_scoring_sinfo_force(const char *s)
152
+ {
153
+ VALUE sinfo = sinfo_find(scoring_sinfo_table, s);
154
+
155
+ if (!RTEST(sinfo)) {
156
+ sinfo = rb_funcall(cSourceInfo, rb_intern("new"), 0);
157
+ rb_gc_register_mark_object(sinfo);
158
+ st_insert(scoring_sinfo_table, (st_data_t)s, (st_data_t)sinfo);
159
+ }
160
+
161
+ return sinfo;
162
+ }
163
+
164
+ static void sinfo_expand_scoring_sinfo(pline_src_info_t *sinfo, long line)
165
+ {
166
+ long i;
167
+
168
+ if (sinfo->size < line) {
169
+ sinfo_allocate_lines(sinfo, line);
170
+ for (i = sinfo->size; i < line; i++) {
171
+ sinfo->lines[i].score = 0;
172
+ }
173
+ sinfo->size = line;
174
+ }
175
+ }
176
+
177
+ static VALUE sinfo_s_find(VALUE self, VALUE path)
178
+ {
179
+ VALUE sinfo;
180
+
181
+ if (TYPE(path) != T_STRING) {
182
+ rb_raise(rb_eArgError, "invalid argument");
183
+ }
184
+
185
+ return sinfo_find(scoring_sinfo_table, RSTRING_PTR(path));
186
+ }
187
+
188
+ /* for processing */
189
+ static VALUE sinfo_find_process_sinfo_force(const char *s)
190
+ {
191
+ st_table *process_sinfo_table = sinfo_container_process_sinfo_table();
192
+ VALUE sinfo = sinfo_find(process_sinfo_table, s);
193
+
194
+ if (!RTEST(sinfo)) {
195
+ sinfo = rb_funcall(cSourceInfo, rb_intern("new"), 0);
196
+ st_insert(process_sinfo_table, (st_data_t)s, (st_data_t)sinfo);
197
+ }
198
+
199
+ return sinfo;
200
+ }
201
+
202
+ static void sinfo_expand_process_sinfo(pline_src_info_t *sinfo, long line)
203
+ {
204
+ long i;
205
+
206
+ if (sinfo->size < line) {
207
+ sinfo_allocate_lines(sinfo, line);
208
+ for (i = sinfo->size; i < line; i++) {
209
+ sinfo->lines[i].start = NOVALUE;
210
+ }
211
+ sinfo->size = line;
212
+ }
213
+ }
214
+
215
+ /* for previous line search */
216
+ static VALUE sinfo_find_preline_sinfo_force(const char *s)
217
+ {
218
+ VALUE sinfo = sinfo_find(preline_sinfo_table, s);
219
+
220
+ if (!RTEST(sinfo)) {
221
+ sinfo = rb_funcall(cSourceInfo, rb_intern("new"), 0);
222
+ rb_gc_register_mark_object(sinfo);
223
+ st_insert(preline_sinfo_table, (st_data_t)s, (st_data_t)sinfo);
224
+ }
225
+
226
+ return sinfo;
227
+ }
228
+
229
+ static void sinfo_expand_preline_sinfo(pline_src_info_t *sinfo, long line)
230
+ {
231
+ long i;
232
+
233
+ if (sinfo->size < line) {
234
+ sinfo_allocate_lines(sinfo, line);
235
+ for (i = sinfo->size; i < line; i++) {
236
+ sinfo->lines[i].prev = -1;
237
+ }
238
+ sinfo->size = line;
239
+ }
240
+ }
241
+
242
+ static pline_time_t sinfo_measure_time(void)
243
+ {
244
+ pline_time_t t;
245
+
246
+ #ifdef _WIN32
247
+ FILETIME ft;
248
+
249
+ GetSystemTimeAsFileTime(&ft);
250
+ t = (((pline_time_t)ft.dwHighDateTime << 32) | (pline_time_t)ft.dwLowDateTime) * 100;
251
+ #else
252
+ struct timespec ts;
253
+
254
+ clock_gettime(CLOCK_REALTIME, &ts);
255
+ t = ((pline_time_t)ts.tv_sec)*1000*1000*1000 + ((pline_time_t)ts.tv_nsec);
256
+ #endif
257
+
258
+ return t;
259
+ }
260
+
261
+ /* measurement using sinfo */
262
+ static void sinfo_measure(const char *srcfile, long line)
263
+ {
264
+ VALUE scoring_v = sinfo_find_scoring_sinfo_force(srcfile);
265
+ VALUE process_v = sinfo_find_process_sinfo_force(srcfile);
266
+ VALUE preline_v = sinfo_find_preline_sinfo_force(srcfile);
267
+ pline_src_info_t *scoring_sinfo = DATA_PTR(scoring_v);
268
+ pline_src_info_t *process_sinfo = DATA_PTR(process_v);
269
+ pline_src_info_t *preline_sinfo = DATA_PTR(preline_v);
270
+ long i, cidx, pidx;
271
+ pline_time_t t;
272
+
273
+ sinfo_expand_scoring_sinfo(scoring_sinfo, line);
274
+ sinfo_expand_process_sinfo(process_sinfo, line);
275
+ sinfo_expand_preline_sinfo(preline_sinfo, line);
276
+
277
+ cidx = line2idx(line);
278
+ pidx = preline_sinfo->lines[cidx].prev;
279
+ if (pidx < 0) {
280
+ for (i = cidx - 1; i >= 0; i--) {
281
+ if (has_value(process_sinfo->lines[i].start)) {
282
+ pidx = preline_sinfo->lines[cidx].prev = i;
283
+ break;
284
+ }
285
+ }
286
+ }
287
+
288
+ t = sinfo_measure_time();
289
+ process_sinfo->lines[cidx].start = t;
290
+ if (pidx >= 0) {
291
+ if (has_value(process_sinfo->lines[pidx].start)) {
292
+ pline_time_t s = process_sinfo->lines[pidx].start;
293
+ scoring_sinfo->lines[pidx].score += (t - s);
294
+ process_sinfo->lines[pidx].start = NOVALUE;
295
+ }
296
+ }
297
+ }
298
+
299
+ static void pline_sinfo_init(void)
300
+ {
301
+ cSourceInfo = rb_define_class_under(mPLine, "SourceInfo", rb_cObject);
302
+ rb_define_singleton_method(cSourceInfo, "find", sinfo_s_find, 1);
303
+ rb_define_method(cSourceInfo, "lines", sinfo_m_lines, 0);
304
+ rb_define_alloc_func(cSourceInfo, sinfo_s_alloc);
305
+ cSourceInfoContainer = rb_define_class_under(cSourceInfo, "SourceInfoContainer", rb_cObject);
306
+ rb_define_alloc_func(cSourceInfoContainer, sinfo_container_s_alloc);
307
+ sinfo_container_id = rb_intern("__pline_sinfo_container");
308
+ scoring_sinfo_table = st_init_strtable();
309
+ preline_sinfo_table = st_init_strtable();
310
+ }
311
+