YAP 7.1.0
analyst.c
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: analyst.c *
12* Last rev: *
13* mods: *
14* comments: Tracing the abstract machine *
15* *
16*************************************************************************/
17#ifdef SCCS
18static char SccsId[] = "%W% %G%";
19
20#endif
21
22
23#ifdef ANALYST
24#include "Yatom.h"
25#include "yapio.h"
26#ifdef HAVE_STRING_H
27#include <string.h>
28#endif
29
30
31
32
33static Int p_reset_op_counters(void);
34static Int p_show_op_counters(void);
35static Int p_show_ops_by_group(void);
36
37static Int
38p_reset_op_counters()
39{
40 int i;
41
42 for (i = 0; i <= _std_top; ++i)
43 GLOBAL_opcount[i] = 0;
44 return TRUE;
45}
46
47static void
48print_instruction(int inst)
49{
50 int j;
51
52 fprintf(GLOBAL_stderr, "%s", Yap_op_names[inst]);
53 for (j = strlen(Yap_op_names[inst]); j < 25; j++)
54 putc(' ', GLOBAL_stderr);
55 j = GLOBAL_opcount[inst];
56 if (j < 100000000) {
57 putc(' ', GLOBAL_stderr);
58 if (j < 10000000) {
59 putc(' ', GLOBAL_stderr);
60 if (j < 1000000) {
61 putc(' ', GLOBAL_stderr);
62 if (j < 100000) {
63 putc(' ', GLOBAL_stderr);
64 if (j < 10000) {
65 putc(' ', GLOBAL_stderr);
66 if (j < 1000) {
67 putc(' ', GLOBAL_stderr);
68 if (j < 100) {
69 putc(' ', GLOBAL_stderr);
70 if (j < 10) {
71 putc(' ', GLOBAL_stderr);
72 }
73 }
74 }
75 }
76 }
77 }
78 }
79 }
80 fprintf(GLOBAL_stderr, "%llu\n", GLOBAL_opcount[inst]);
81}
82
83static Int
84p_show_op_counters()
85{
86 int i;
87 Term t1 = Deref(ARG1);
88
89 if (IsVarTerm(t1) || !IsAtomTerm(t1)) {
90 return FALSE;
91 } else {
92 Atom at1 = AtomOfTerm(t1);
93
94 if (IsWideAtom(at1)) {
95 wchar_t *program;
96
97 program = RepAtom(at1)->WStrOfAE;
98 fprintf(GLOBAL_stderr, "\n Instructions Executed in %S\n", program);
99 } else {
100 char *program;
101
102 program = RepAtom(at1)->StrOfAE;
103 fprintf(GLOBAL_stderr, "\n Instructions Executed in %s\n", program);
104 }
105 }
106
107 for (i = 0; i <= _std_top; ++i)
108 print_instruction(i);
109 fprintf(GLOBAL_stderr, "\n Control Instructions \n");
110 print_instruction(_op_fail);
111 print_instruction(_execute);
112 print_instruction(_dexecute);
113 print_instruction(_call);
114 print_instruction(_fcall);
115 print_instruction(_call_cpred);
116 print_instruction(_call_c_wfail);
117 print_instruction(_procceed);
118 print_instruction(_allocate);
119 print_instruction(_deallocate);
120
121 fprintf(GLOBAL_stderr, "\n Choice Point Manipulation Instructions\n");
122 print_instruction(_try_me);
123 print_instruction(_retry_me);
124 print_instruction(_trust_me);
125 print_instruction(_try_clause);
126 print_instruction(_try_in);
127 print_instruction(_retry);
128 print_instruction(_trust);
129
130 fprintf(GLOBAL_stderr, "\n Disjunction Instructions\n");
131 print_instruction(_either);
132 print_instruction(_or_else);
133 print_instruction(_or_last);
134 print_instruction(_jump);
135 print_instruction(_move_back);
136
137 fprintf(GLOBAL_stderr, "\n Dynamic Predicates Choicepoint Instructions\n");
138 print_instruction(_try_and_mark);
139 print_instruction(_retry_and_mark);
140
141 fprintf(GLOBAL_stderr, "\n C Predicates Choicepoint Instructions\n");
142 print_instruction(_try_c);
143 print_instruction(_retry_c);
144
145 fprintf(GLOBAL_stderr, "\n Indexing Instructions\n");
146 fprintf(GLOBAL_stderr, "\n Switch on Type\n");
147 print_instruction(_switch_on_type);
148 print_instruction(_switch_list_nl);
149 print_instruction(_switch_on_arg_type);
150 print_instruction(_switch_on_sub_arg_type);
151 fprintf(GLOBAL_stderr, "\n Switch on Value\n");
152 print_instruction(_if_cons);
153 print_instruction(_go_on_cons);
154 print_instruction(_switch_on_cons);
155 print_instruction(_if_func);
156 print_instruction(_go_on_func);
157 print_instruction(_switch_on_func);
158 fprintf(GLOBAL_stderr, "\n Other Switches\n");
159 print_instruction(_if_not_then);
160
161 fprintf(GLOBAL_stderr, "\n Get Instructions\n");
162 print_instruction(_get_x_var);
163 print_instruction(_get_y_var);
164 print_instruction(_get_x_val);
165 print_instruction(_get_y_val);
166 print_instruction(_get_atom);
167 print_instruction(_get_2atoms);
168 print_instruction(_get_3atoms);
169 print_instruction(_get_4atoms);
170 print_instruction(_get_5atoms);
171 print_instruction(_get_6atoms);
172 print_instruction(_get_list);
173 print_instruction(_get_struct);
174 fprintf(GLOBAL_stderr, "\n Optimised Get Instructions\n");
175 print_instruction(_glist_valx);
176 print_instruction(_glist_valy);
177 print_instruction(_gl_void_varx);
178 print_instruction(_gl_void_vary);
179 print_instruction(_gl_void_valx);
180 print_instruction(_gl_void_valy);
181
182 fprintf(GLOBAL_stderr, "\n Unify Read Instructions\n");
183 print_instruction(_unify_x_var);
184 print_instruction(_unify_x_var2);
185 print_instruction(_unify_y_var);
186 print_instruction(_unify_x_val);
187 print_instruction(_unify_y_val);
188 print_instruction(_unify_x_loc);
189 print_instruction(_unify_y_loc);
190 print_instruction(_unify_atom);
191 print_instruction(_unify_n_atoms);
192 print_instruction(_unify_n_voids);
193 print_instruction(_unify_list);
194 print_instruction(_unify_struct);
195 fprintf(GLOBAL_stderr, "\n Unify Last Read Instructions\n");
196 print_instruction(_unify_l_x_var);
197 print_instruction(_unify_l_x_var2);
198 print_instruction(_unify_l_y_var);
199 print_instruction(_unify_l_x_val);
200 print_instruction(_unify_l_y_val);
201 print_instruction(_unify_l_x_loc);
202 print_instruction(_unify_l_y_loc);
203 print_instruction(_unify_l_atom);
204 print_instruction(_unify_l_n_voids);
205 print_instruction(_unify_l_list);
206 print_instruction(_unify_l_struc);
207
208 fprintf(GLOBAL_stderr, "\n Unify Write Instructions\n");
209 print_instruction(_unify_x_var_write);
210 print_instruction(_unify_x_var2_write);
211 print_instruction(_unify_y_var_write);
212 print_instruction(_unify_x_val_write);
213 print_instruction(_unify_y_val_write);
214 print_instruction(_unify_x_loc_write);
215 print_instruction(_unify_y_loc_write);
216 print_instruction(_unify_atom_write);
217 print_instruction(_unify_n_atoms_write);
218 print_instruction(_unify_n_voids_write);
219 print_instruction(_unify_list_write);
220 print_instruction(_unify_struct_write);
221 fprintf(GLOBAL_stderr, "\n Unify Last Read Instructions\n");
222 print_instruction(_unify_l_x_var_write);
223 print_instruction(_unify_l_x_var2_write);
224 print_instruction(_unify_l_y_var_write);
225 print_instruction(_unify_l_x_val_write);
226 print_instruction(_unify_l_y_val_write);
227 print_instruction(_unify_l_x_loc_write);
228 print_instruction(_unify_l_y_loc_write);
229 print_instruction(_unify_l_atom_write);
230 print_instruction(_unify_l_n_voids_write);
231 print_instruction(_unify_l_list_write);
232 print_instruction(_unify_l_struc_write);
233
234 fprintf(GLOBAL_stderr, "\n Put Instructions\n");
235 print_instruction(_put_x_var);
236 print_instruction(_put_y_var);
237 print_instruction(_put_x_val);
238 print_instruction(_put_xx_val);
239 print_instruction(_put_y_val);
240 print_instruction(_put_unsafe);
241 print_instruction(_put_atom);
242 print_instruction(_put_list);
243 print_instruction(_put_struct);
244
245 fprintf(GLOBAL_stderr, "\n Write Instructions\n");
246 print_instruction(_write_x_var);
247 print_instruction(_write_y_var);
248 print_instruction(_write_x_val);
249 print_instruction(_write_y_val);
250 print_instruction(_write_x_loc);
251 print_instruction(_write_y_loc);
252 print_instruction(_write_atom);
253 print_instruction(_write_n_atoms);
254 print_instruction(_write_n_voids);
255 print_instruction(_write_list);
256 print_instruction(_write_struct);
257 fprintf(GLOBAL_stderr, "\n Last Write Instructions\n");
258 print_instruction(_write_l_list);
259 print_instruction(_write_l_struc);
260
261 fprintf(GLOBAL_stderr, "\n Miscellaneous Instructions\n");
262 print_instruction(_cut);
263 print_instruction(_cut_t);
264 print_instruction(_cut_e);
265 print_instruction(_skip);
266 print_instruction(_pop);
267 print_instruction(_pop_n);
268 print_instruction(_trust_fail);
269 print_instruction(_index_pred);
270 print_instruction(_lock_pred);
271#if THREADS
272 print_instruction(_thread_local);
273#endif
274 print_instruction(_save_b_x);
275 print_instruction(_save_b_y);
276 print_instruction(_save_pair_x);
277 print_instruction(_save_pair_y);
278 print_instruction(_save_pair_x_write);
279 print_instruction(_save_pair_y_write);
280 print_instruction(_save_appl_x);
281 print_instruction(_save_appl_y);
282 print_instruction(_save_appl_x_write);
283 print_instruction(_save_appl_y_write);
284 print_instruction(_Ystop);
285 print_instruction(_Nstop);
286
287 return TRUE;
288}
289
290typedef struct {
291 int nxvar, nxval, nyvar, nyval, ncons, nlist, nstru, nmisc;
292} uGLOBAL_opcount;
293
294typedef struct {
295 int ncalls, nexecs, nproceeds, ncallbips, ncuts, nallocs, ndeallocs;
296} cGLOBAL_opcount;
297
298typedef struct {
299 int ntries, nretries, ntrusts;
300} ccpcount;
301
302static Int
303p_show_ops_by_group(void)
304{
305
306 uGLOBAL_opcount c_get, c_unify, c_put, c_write;
307 cGLOBAL_opcount c_control;
308 ccpcount c_cp;
309 int gets, unifies, puts, writes, controls, choice_pts, indexes, misc,
310 total;
311 Term t1;
312 Atom at1;
313
314 t1 = Deref(ARG1);
315 if (IsVarTerm(t1) || !IsAtomTerm(t1))
316 return (FALSE);
317 at1 = AtomOfTerm(t1);
318 if (IsWideAtom(at1)) {
319 wchar_t *program;
320
321 program = RepAtom(at1)->WStrOfAE;
322 fprintf(GLOBAL_stderr, "\n Instructions Executed in %S\n", program);
323 } else {
324 char *program;
325
326 program = RepAtom(at1)->StrOfAE;
327 fprintf(GLOBAL_stderr, "\n Instructions Executed in %s\n", program);
328 }
329
330 c_get.nxvar =
331 GLOBAL_opcount[_get_x_var];
332 c_get.nyvar =
333 GLOBAL_opcount[_get_y_var];
334 c_get.nxval =
335 GLOBAL_opcount[_get_x_val];
336 c_get.nyval =
337 GLOBAL_opcount[_get_y_val];
338 c_get.ncons =
339 GLOBAL_opcount[_get_atom]+
340 GLOBAL_opcount[_get_2atoms]+
341 GLOBAL_opcount[_get_3atoms]+
342 GLOBAL_opcount[_get_4atoms]+
343 GLOBAL_opcount[_get_5atoms]+
344 GLOBAL_opcount[_get_6atoms];
345 c_get.nlist =
346 GLOBAL_opcount[_get_list] +
347 GLOBAL_opcount[_glist_valx] +
348 GLOBAL_opcount[_glist_valy] +
349 GLOBAL_opcount[_gl_void_varx] +
350 GLOBAL_opcount[_gl_void_vary] +
351 GLOBAL_opcount[_gl_void_valx] +
352 GLOBAL_opcount[_gl_void_valy];
353 c_get.nstru =
354 GLOBAL_opcount[_get_struct];
355
356 gets = c_get.nxvar + c_get.nyvar + c_get.nxval + c_get.nyval +
357 c_get.ncons + c_get.nlist + c_get.nstru;
358
359 c_unify.nxvar =
360 GLOBAL_opcount[_unify_x_var] +
361 GLOBAL_opcount[_unify_void] +
362 GLOBAL_opcount[_unify_n_voids] +
363 2 * GLOBAL_opcount[_unify_x_var2] +
364 2 * GLOBAL_opcount[_gl_void_varx] +
365 GLOBAL_opcount[_gl_void_vary] +
366 GLOBAL_opcount[_gl_void_valx] +
367 GLOBAL_opcount[_unify_l_x_var] +
368 GLOBAL_opcount[_unify_l_void] +
369 GLOBAL_opcount[_unify_l_n_voids] +
370 2 * GLOBAL_opcount[_unify_l_x_var2] +
371 GLOBAL_opcount[_unify_x_var_write] +
372 GLOBAL_opcount[_unify_void_write] +
373 GLOBAL_opcount[_unify_n_voids_write] +
374 2 * GLOBAL_opcount[_unify_x_var2_write] +
375 GLOBAL_opcount[_unify_l_x_var_write] +
376 GLOBAL_opcount[_unify_l_void_write] +
377 GLOBAL_opcount[_unify_l_n_voids_write] +
378 2 * GLOBAL_opcount[_unify_l_x_var2_write];
379 c_unify.nyvar =
380 GLOBAL_opcount[_unify_y_var] +
381 GLOBAL_opcount[_gl_void_vary] +
382 GLOBAL_opcount[_unify_l_y_var] +
383 GLOBAL_opcount[_unify_y_var_write] +
384 GLOBAL_opcount[_unify_l_y_var_write];
385 c_unify.nxval =
386 GLOBAL_opcount[_unify_x_val] +
387 GLOBAL_opcount[_unify_x_loc] +
388 GLOBAL_opcount[_glist_valx] +
389 GLOBAL_opcount[_gl_void_valx] +
390 GLOBAL_opcount[_unify_l_x_val] +
391 GLOBAL_opcount[_unify_l_x_loc] +
392 GLOBAL_opcount[_unify_x_val_write] +
393 GLOBAL_opcount[_unify_x_loc_write] +
394 GLOBAL_opcount[_unify_l_x_val_write] +
395 GLOBAL_opcount[_unify_l_x_loc_write];
396 c_unify.nyval =
397 GLOBAL_opcount[_unify_y_val] +
398 GLOBAL_opcount[_unify_y_loc] +
399 GLOBAL_opcount[_glist_valy] +
400 GLOBAL_opcount[_gl_void_valy] +
401 GLOBAL_opcount[_unify_l_y_val] +
402 GLOBAL_opcount[_unify_l_y_loc] +
403 GLOBAL_opcount[_unify_y_val_write] +
404 GLOBAL_opcount[_unify_y_loc_write] +
405 GLOBAL_opcount[_unify_l_y_val_write] +
406 GLOBAL_opcount[_unify_l_y_loc_write];
407 c_unify.ncons =
408 GLOBAL_opcount[_unify_atom] +
409 GLOBAL_opcount[_unify_n_atoms] +
410 GLOBAL_opcount[_unify_l_atom] +
411 GLOBAL_opcount[_unify_atom_write] +
412 GLOBAL_opcount[_unify_n_atoms_write] +
413 GLOBAL_opcount[_unify_l_atom_write];
414 c_unify.nlist =
415 GLOBAL_opcount[_unify_list] +
416 GLOBAL_opcount[_unify_l_list] +
417 GLOBAL_opcount[_unify_list_write] +
418 GLOBAL_opcount[_unify_l_list_write];
419 c_unify.nstru =
420 GLOBAL_opcount[_unify_struct] +
421 GLOBAL_opcount[_unify_l_struc] +
422 GLOBAL_opcount[_unify_struct_write] +
423 GLOBAL_opcount[_unify_l_struc_write];
424 c_unify.nmisc =
425 GLOBAL_opcount[_pop] +
426 GLOBAL_opcount[_pop_n];
427
428 unifies = c_unify.nxvar + c_unify.nyvar + c_unify.nxval + c_unify.nyval +
429 c_unify.ncons + c_unify.nlist + c_unify.nstru + c_unify.nmisc;
430
431 c_put.nxvar =
432 GLOBAL_opcount[_put_x_var];
433 c_put.nyvar =
434 GLOBAL_opcount[_put_y_var];
435 c_put.nxval =
436 GLOBAL_opcount[_put_x_val]+
437 2*GLOBAL_opcount[_put_xx_val];
438 c_put.nyval =
439 GLOBAL_opcount[_put_y_val];
440 c_put.ncons =
441 GLOBAL_opcount[_put_atom];
442 c_put.nlist =
443 GLOBAL_opcount[_put_list];
444 c_put.nstru =
445 GLOBAL_opcount[_put_struct];
446
447 puts = c_put.nxvar + c_put.nyvar + c_put.nxval + c_put.nyval +
448 c_put.ncons + c_put.nlist + c_put.nstru;
449
450 c_write.nxvar =
451 GLOBAL_opcount[_write_x_var] +
452 GLOBAL_opcount[_write_void] +
453 GLOBAL_opcount[_write_n_voids];
454 c_write.nyvar =
455 GLOBAL_opcount[_write_y_var];
456 c_write.nxval =
457 GLOBAL_opcount[_write_x_val];
458 c_write.nyval =
459 GLOBAL_opcount[_write_y_val];
460 c_write.ncons =
461 GLOBAL_opcount[_write_atom];
462 c_write.nlist =
463 GLOBAL_opcount[_write_list];
464 c_write.nstru =
465 GLOBAL_opcount[_write_struct];
466
467 writes = c_write.nxvar + c_write.nyvar + c_write.nxval + c_write.nyval +
468 c_write.ncons + c_write.nlist + c_write.nstru;
469
470 c_control.nexecs =
471 GLOBAL_opcount[_execute] +
472 GLOBAL_opcount[_dexecute];
473
474 c_control.ncalls =
475 GLOBAL_opcount[_call] +
476 GLOBAL_opcount[_fcall];
477
478 c_control.nproceeds =
479 GLOBAL_opcount[_procceed];
480
481 c_control.ncallbips =
482 GLOBAL_opcount[_call_cpred] +
483 GLOBAL_opcount[_call_c_wfail] +
484 GLOBAL_opcount[_try_c] +
485 GLOBAL_opcount[_retry_c] +
486 GLOBAL_opcount[_op_fail] +
487 GLOBAL_opcount[_trust_fail] +
488 GLOBAL_opcount[_p_atom_x] +
489 GLOBAL_opcount[_p_atom_y] +
490 GLOBAL_opcount[_p_atomic_x] +
491 GLOBAL_opcount[_p_atomic_y] +
492 GLOBAL_opcount[_p_compound_x] +
493 GLOBAL_opcount[_p_compound_y] +
494 GLOBAL_opcount[_p_float_x] +
495 GLOBAL_opcount[_p_float_y] +
496 GLOBAL_opcount[_p_integer_x] +
497 GLOBAL_opcount[_p_integer_y] +
498 GLOBAL_opcount[_p_nonvar_x] +
499 GLOBAL_opcount[_p_nonvar_y] +
500 GLOBAL_opcount[_p_number_x] +
501 GLOBAL_opcount[_p_number_y] +
502 GLOBAL_opcount[_p_var_x] +
503 GLOBAL_opcount[_p_var_y] +
504 GLOBAL_opcount[_p_db_ref_x] +
505 GLOBAL_opcount[_p_db_ref_y] +
506 GLOBAL_opcount[_p_cut_by_x] +
507 GLOBAL_opcount[_p_cut_by_y] +
508 GLOBAL_opcount[_p_primitive_x] +
509 GLOBAL_opcount[_p_primitive_y] +
510 GLOBAL_opcount[_p_equal] +
511 GLOBAL_opcount[_p_plus_vv] +
512 GLOBAL_opcount[_p_plus_vc] +
513 GLOBAL_opcount[_p_plus_y_vv] +
514 GLOBAL_opcount[_p_plus_y_vc] +
515 GLOBAL_opcount[_p_minus_vv] +
516 GLOBAL_opcount[_p_minus_cv] +
517 GLOBAL_opcount[_p_minus_y_vv] +
518 GLOBAL_opcount[_p_minus_y_cv] +
519 GLOBAL_opcount[_p_times_vv] +
520 GLOBAL_opcount[_p_times_vc] +
521 GLOBAL_opcount[_p_times_y_vv] +
522 GLOBAL_opcount[_p_times_y_vc] +
523 GLOBAL_opcount[_p_div_vv] +
524 GLOBAL_opcount[_p_div_vc] +
525 GLOBAL_opcount[_p_div_cv] +
526 GLOBAL_opcount[_p_div_y_vv] +
527 GLOBAL_opcount[_p_div_y_vc] +
528 GLOBAL_opcount[_p_div_y_cv] +
529 GLOBAL_opcount[_p_or_vv] +
530 GLOBAL_opcount[_p_or_vc] +
531 GLOBAL_opcount[_p_or_y_vv] +
532 GLOBAL_opcount[_p_or_y_vc] +
533 GLOBAL_opcount[_p_and_vv] +
534 GLOBAL_opcount[_p_and_vc] +
535 GLOBAL_opcount[_p_and_y_vv] +
536 GLOBAL_opcount[_p_and_y_vc] +
537 GLOBAL_opcount[_p_sll_vv] +
538 GLOBAL_opcount[_p_sll_vc] +
539 GLOBAL_opcount[_p_sll_y_vv] +
540 GLOBAL_opcount[_p_sll_y_vc] +
541 GLOBAL_opcount[_p_slr_vv] +
542 GLOBAL_opcount[_p_slr_vc] +
543 GLOBAL_opcount[_p_slr_y_vv] +
544 GLOBAL_opcount[_p_slr_y_vc] +
545 GLOBAL_opcount[_p_dif] +
546 GLOBAL_opcount[_p_eq] +
547 GLOBAL_opcount[_p_arg_vv] +
548 GLOBAL_opcount[_p_arg_cv] +
549 GLOBAL_opcount[_p_arg_y_vv] +
550 GLOBAL_opcount[_p_arg_y_cv] +
551 GLOBAL_opcount[_p_functor] +
552 GLOBAL_opcount[_p_func2s_vv] +
553 GLOBAL_opcount[_p_func2s_cv] +
554 GLOBAL_opcount[_p_func2s_vc] +
555 GLOBAL_opcount[_p_func2s_y_vv] +
556 GLOBAL_opcount[_p_func2s_y_cv] +
557 GLOBAL_opcount[_p_func2s_y_vc] +
558 GLOBAL_opcount[_p_func2f_xx] +
559 GLOBAL_opcount[_p_func2f_xy] +
560 GLOBAL_opcount[_p_func2f_yx] +
561 GLOBAL_opcount[_p_func2f_yy];
562
563 c_control.ncuts =
564 GLOBAL_opcount[_cut] +
565 GLOBAL_opcount[_cut_t] +
566 GLOBAL_opcount[_cut_e] +
567 GLOBAL_opcount[_commit_b_x] +
568 GLOBAL_opcount[_commit_b_y];
569
570 c_control.nallocs =
571 GLOBAL_opcount[_allocate] +
572 GLOBAL_opcount[_fcall];
573
574 c_control.ndeallocs =
575 GLOBAL_opcount[_dexecute] +
576 GLOBAL_opcount[_deallocate];
577
578 controls =
579 c_control.nexecs +
580 c_control.ncalls +
581 c_control.nproceeds +
582 c_control.ncuts +
583 c_control.nallocs +
584 c_control.ndeallocs +
585 GLOBAL_opcount[_jump] +
586 GLOBAL_opcount[_move_back] +
587 GLOBAL_opcount[_try_in];
588
589
590
591 c_cp.ntries =
592 GLOBAL_opcount[_try_me] +
593 GLOBAL_opcount[_try_and_mark] +
594 GLOBAL_opcount[_try_c] +
595 GLOBAL_opcount[_try_clause] +
596 GLOBAL_opcount[_either];
597
598 c_cp.nretries =
599 GLOBAL_opcount[_retry_me] +
600 GLOBAL_opcount[_retry_and_mark] +
601 GLOBAL_opcount[_retry_c] +
602 GLOBAL_opcount[_retry] +
603 GLOBAL_opcount[_or_else];
604
605 c_cp.ntrusts =
606 GLOBAL_opcount[_trust_me] +
607 GLOBAL_opcount[_trust] +
608 GLOBAL_opcount[_or_last];
609
610 choice_pts =
611 c_cp.ntries +
612 c_cp.nretries +
613 c_cp.ntrusts;
614
615 indexes =
616 GLOBAL_opcount[_jump_if_var] +
617 GLOBAL_opcount[_switch_on_type] +
618 GLOBAL_opcount[_switch_list_nl] +
619 GLOBAL_opcount[_switch_on_arg_type] +
620 GLOBAL_opcount[_switch_on_sub_arg_type] +
621 GLOBAL_opcount[_switch_on_cons] +
622 GLOBAL_opcount[_go_on_cons] +
623 GLOBAL_opcount[_if_cons] +
624 GLOBAL_opcount[_switch_on_func] +
625 GLOBAL_opcount[_go_on_func] +
626 GLOBAL_opcount[_if_func] +
627 GLOBAL_opcount[_if_not_then];
628 misc =
629 c_control.ncallbips +
630 GLOBAL_opcount[_Ystop] +
631 GLOBAL_opcount[_Nstop] +
632 GLOBAL_opcount[_index_pred] +
633 GLOBAL_opcount[_lock_pred] +
634#if THREADS
635 GLOBAL_opcount[_thread_local] +
636#endif
637 GLOBAL_opcount[_save_b_x] +
638 GLOBAL_opcount[_save_b_y] +
639 GLOBAL_opcount[_undef_p] +
640 GLOBAL_opcount[_import_p] +
641 GLOBAL_opcount[_spy_pred] +
642 GLOBAL_opcount[_spy_or_trymark] +
643 GLOBAL_opcount[_save_pair_x] +
644 GLOBAL_opcount[_save_pair_y] +
645 GLOBAL_opcount[_save_pair_x_write] +
646 GLOBAL_opcount[_save_pair_y_write] +
647 GLOBAL_opcount[_save_appl_x] +
648 GLOBAL_opcount[_save_appl_y] +
649 GLOBAL_opcount[_save_appl_x_write] +
650 GLOBAL_opcount[_save_appl_y_write];
651 total = gets + unifies + puts + writes + controls + choice_pts + indexes + misc;
652
653 /* for (i = 0; i <= _std_top; ++i)
654 * print_instruction(i);
655 */
656
657 fprintf(GLOBAL_stderr, "Groups are\n\n");
658 fprintf(GLOBAL_stderr, " GET instructions: %8d (%3d%%)\n", gets,
659 (gets * 100) / total);
660 fprintf(GLOBAL_stderr, " UNIFY instructions: %8d (%3d%%)\n", unifies,
661 (unifies * 100) / total);
662 fprintf(GLOBAL_stderr, " PUT instructions: %8d (%3d%%)\n", puts,
663 (puts * 100) / total);
664 fprintf(GLOBAL_stderr, " WRITE instructions: %8d (%3d%%)\n", writes,
665 (writes * 100) / total);
666 fprintf(GLOBAL_stderr, " CONTROL instructions: %8d (%3d%%)\n", controls,
667 (controls * 100) / total);
668 fprintf(GLOBAL_stderr, " CHOICE POINT instructions: %8d (%3d%%)\n", choice_pts,
669 (choice_pts * 100) / total);
670 fprintf(GLOBAL_stderr, " INDEXING instructions: %8d (%3d%%)\n", indexes,
671 (indexes * 100) / total);
672 fprintf(GLOBAL_stderr, " MISCELLANEOUS instructions: %8d (%3d%%)\n", misc,
673 (misc * 100) / total);
674 fprintf(GLOBAL_stderr, "_______________________________________________\n");
675 fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
676 (total * 100) / total);
677
678 fprintf(GLOBAL_stderr, "\n Analysis of Unification Instructions in %s \n", program);
679 fprintf(GLOBAL_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
680 fprintf(GLOBAL_stderr, " GET: %8d %8d %8d %8d %8d %8d %8d\n",
681 c_get.nxvar,
682 c_get.nyvar,
683 c_get.nxval,
684 c_get.nyval,
685 c_get.ncons,
686 c_get.nlist,
687 c_get.nstru);
688 fprintf(GLOBAL_stderr, "UNIFY: %8d %8d %8d %8d %8d %8d %8d\n",
689 c_unify.nxvar,
690 c_unify.nyvar,
691 c_unify.nxval,
692 c_unify.nyval,
693 c_unify.ncons,
694 c_unify.nlist,
695 c_unify.nstru);
696 fprintf(GLOBAL_stderr, " PUT: %8d %8d %8d %8d %8d %8d %8d\n",
697 c_put.nxvar,
698 c_put.nyvar,
699 c_put.nxval,
700 c_put.nyval,
701 c_put.ncons,
702 c_put.nlist,
703 c_put.nstru);
704 fprintf(GLOBAL_stderr, "WRITE: %8d %8d %8d %8d %8d %8d %8d\n",
705 c_write.nxvar,
706 c_write.nyvar,
707 c_write.nxval,
708 c_write.nyval,
709 c_write.ncons,
710 c_write.nlist,
711 c_write.nstru);
712 fprintf(GLOBAL_stderr, " ___________________________________________________\n");
713 fprintf(GLOBAL_stderr, "TOTAL: %8d %8d %8d %8d %8d %8d %8d\n",
714 c_get.nxvar + c_unify.nxvar + c_put.nxvar + c_write.nxvar,
715 c_get.nyvar + c_unify.nyvar + c_put.nyvar + c_write.nyvar,
716 c_get.nxval + c_unify.nxval + c_put.nxval + c_write.nxval,
717 c_get.nyval + c_unify.nyval + c_put.nyval + c_write.nyval,
718 c_get.ncons + c_unify.ncons + c_put.ncons + c_write.ncons,
719 c_get.nlist + c_unify.nlist + c_put.nlist + c_write.nlist,
720 c_get.nstru + c_unify.nstru + c_put.nstru + c_write.nstru
721 );
722
723 fprintf(GLOBAL_stderr, "\n Analysis of Unification Instructions in %s \n", program);
724 fprintf(GLOBAL_stderr, " XVAR, YVAR, XVAL, YVAL, CONS, LIST, STRUCT\n");
725 fprintf(GLOBAL_stderr, " GET: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
726 (((double) c_get.nxvar) * 100) / total,
727 (((double) c_get.nyvar) * 100) / total,
728 (((double) c_get.nxval) * 100) / total,
729 (((double) c_get.nyval) * 100) / total,
730 (((double) c_get.ncons) * 100) / total,
731 (((double) c_get.nlist) * 100) / total,
732 (((double) c_get.nstru) * 100) / total);
733 fprintf(GLOBAL_stderr, "UNIFY: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
734 (((double) c_unify.nxvar) * 100) / total,
735 (((double) c_unify.nyvar) * 100) / total,
736 (((double) c_unify.nxval) * 100) / total,
737 (((double) c_unify.nyval) * 100) / total,
738 (((double) c_unify.ncons) * 100) / total,
739 (((double) c_unify.nlist) * 100) / total,
740 (((double) c_unify.nstru) * 100) / total);
741 fprintf(GLOBAL_stderr, " PUT: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
742 (((double) c_put.nxvar) * 100) / total,
743 (((double) c_put.nyvar) * 100) / total,
744 (((double) c_put.nxval) * 100) / total,
745 (((double) c_put.nyval) * 100) / total,
746 (((double) c_put.ncons) * 100) / total,
747 (((double) c_put.nlist) * 100) / total,
748 (((double) c_put.nstru) * 100) / total);
749 fprintf(GLOBAL_stderr, "WRITE: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
750 (((double) c_write.nxvar) * 100) / total,
751 (((double) c_write.nyvar) * 100) / total,
752 (((double) c_write.nxval) * 100) / total,
753 (((double) c_write.nyval) * 100) / total,
754 (((double) c_write.ncons) * 100) / total,
755 (((double) c_write.nlist) * 100) / total,
756 (((double) c_write.nstru) * 100) / total);
757 fprintf(GLOBAL_stderr, " ___________________________________________________\n");
758 fprintf(GLOBAL_stderr, "TOTAL: %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%% %3.2f%%\n",
759 (((double) c_get.nxvar + c_unify.nxvar + c_put.nxvar + c_write.nxvar) * 100) / total,
760 (((double) c_get.nyvar + c_unify.nyvar + c_put.nyvar + c_write.nyvar) * 100) / total,
761 (((double) c_get.nxval + c_unify.nxval + c_put.nxval + c_write.nxval) * 100) / total,
762 (((double) c_get.nyval + c_unify.nyval + c_put.nyval + c_write.nyval) * 100) / total,
763 (((double) c_get.ncons + c_unify.ncons + c_put.ncons + c_write.ncons) * 100) / total,
764 (((double) c_get.nlist + c_unify.nlist + c_put.nlist + c_write.nlist) * 100) / total,
765 (((double) c_get.nstru + c_unify.nstru + c_put.nstru + c_write.nstru) * 100) / total
766 );
767
768 fprintf(GLOBAL_stderr, "\n Control Instructions Executed in %s \n", program);
769 fprintf(GLOBAL_stderr, "Grouped as\n\n");
770 fprintf(GLOBAL_stderr, " CALL instructions: %8d (%3d%%)\n",
771 c_control.ncalls, (c_control.ncalls * 100) / total);
772 fprintf(GLOBAL_stderr, " PROCEED instructions: %8d (%3d%%)\n",
773 c_control.nproceeds, (c_control.nproceeds * 100) / total);
774 fprintf(GLOBAL_stderr, " EXECUTE instructions: %8d (%3d%%)\n",
775 c_control.nexecs, (c_control.nexecs * 100) / total);
776 fprintf(GLOBAL_stderr, " CUT instructions: %8d (%3d%%)\n",
777 c_control.ncuts, (c_control.ncuts * 100) / total);
778 fprintf(GLOBAL_stderr, " CALL_BIP instructions: %8d (%3d%%)\n",
779 c_control.ncallbips, (c_control.ncallbips * 100) / total);
780 fprintf(GLOBAL_stderr, " ALLOCATE instructions: %8d (%3d%%)\n",
781 c_control.nallocs, (c_control.nallocs * 100) / total);
782 fprintf(GLOBAL_stderr, " DEALLOCATE instructions: %8d (%3d%%)\n",
783 c_control.ndeallocs, (c_control.ndeallocs * 100) / total);
784 fprintf(GLOBAL_stderr, "_______________________________________________\n");
785 fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
786 (total * 100) / total);
787
788 fprintf(GLOBAL_stderr, "\n Choice Point Manipulation Instructions Executed in %s \n", program);
789 fprintf(GLOBAL_stderr, "Grouped as\n\n");
790 fprintf(GLOBAL_stderr, " TRY instructions: %8d (%3d%%)\n",
791 c_cp.ntries, (c_cp.ntries * 100) / total);
792 fprintf(GLOBAL_stderr, " RETRY instructions: %8d (%3d%%)\n",
793 c_cp.nretries, (c_cp.nretries * 100) / total);
794 fprintf(GLOBAL_stderr, " TRUST instructions: %8d (%3d%%)\n",
795 c_cp.ntrusts, (c_cp.ntrusts * 100) / total);
796 fprintf(GLOBAL_stderr, "_______________________________________________\n");
797 fprintf(GLOBAL_stderr, " TOTAL instructions: %8d (%3d%%)\n\n", total,
798 (total * 100) / total);
799
800 return TRUE;
801}
802
803static Int
804p_show_sequences(void)
805{
806 int i, j;
807 YAP_ULONG_LONG min;
808 YAP_ULONG_LONG sum = 0;
809 Term t = Deref(ARG1);
810
811 if (IsVarTerm(t)) {
812 Yap_Error(INSTANTIATION_ERROR, t, "shows_sequences/1");
813 return FALSE;
814 }
815 if (!IsIntegerTerm(t)) {
816 Yap_Error(TYPE_ERROR_INTEGER, t, "shows_sequences/1");
817 return FALSE;
818 }
819 min = (YAP_ULONG_LONG)IntegerOfTerm(t);
820 if (min <= 0) {
821 Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "shows_sequences/1");
822 return FALSE;
823 }
824 if (min <= 0) {
825 Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "shows_sequences/1");
826 return FALSE;
827 }
828 for (i = 0; i <= _std_top; ++i) {
829 sum += GLOBAL_opcount[i];
830 }
831 for (i = 0; i <= _std_top; ++i) {
832 for (j = 0; j <= _std_top; ++j) {
833 YAP_ULONG_LONG seqs = Yap_2opcount[i][j];
834 if (seqs && sum/seqs <= min) {
835 /*
836 Term t[3], t0;
837 Functor f =
838 t[0] = Yap_MkFloatTerm(((double)seqs*100.0)/sum);
839 t[1] = Yap_LookupAtom(Yap_op_names[i]);
840 t[2] = Yap_LookupAtom(Yap_op_names[j]);
841 t0 = MkApplTerm(
842 Yap_MkPairTerm(Yap_op_names[i]
843 */
844 fprintf(stderr,"%f -> %s,%s\n",((double)seqs*100.0)/sum,Yap_op_names[i],Yap_op_names[j]);
845 /* we found one */
846 }
847 }
848 }
849 return TRUE;
850}
851
852void
853Yap_InitAnalystPreds(void)
854{
855 Yap_InitCPred("wam_profiler_reset_op_counters", 0, p_reset_op_counters, SafePredFlag |SyncPredFlag);
863 Yap_InitCPred("wam_profiler_show_op_counters", 1, p_show_op_counters, SafePredFlag|SyncPredFlag);
872 Yap_InitCPred("wam_profiler_show_ops_by_group", 1, p_show_ops_by_group, SafePredFlag |SyncPredFlag);
883 Yap_InitCPred("wam_profiler_show_sequences", 1, p_show_sequences, SafePredFlag |SyncPredFlag);
884}
885
886#endif /* ANALYST */