[m-rev.] Re: for review: procedure representations for the deep profiler

Paul Bone pbone at csse.unimelb.edu.au
Thu Sep 13 10:55:22 AEST 2007


On Tue, Sep 11, 2007 at 11:47:13AM +1000, Zoltan Somogyi wrote:
> Index: runtime/mercury_deep_profiling.c
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
> retrieving revision 1.26
> diff -u -b -r1.26 mercury_deep_profiling.c
> --- runtime/mercury_deep_profiling.c	29 Nov 2006 05:18:20 -0000	1.26
> +++ runtime/mercury_deep_profiling.c	10 Sep 2007 08:51:31 -0000
> @@ -817,10 +887,82 @@
>  
>      MR_flag_written_proc_layout(proc_layout);
>  
> -    MR_write_byte(fp, MR_deep_token_proc_static);
> -    MR_write_ptr(fp, kind_ps, ps_id);
> +    MR_write_byte(deep_fp, MR_deep_item_proc_static);
> +    MR_write_ptr(deep_fp, kind_ps, ps_id);
>  
>      procid = &proc_layout->MR_sle_proc_id;
> +    MR_write_out_str_proc_label(deep_fp, procid);
> +
> +    MR_write_string(deep_fp, ps->MR_ps_file_name);
> +    MR_write_num(deep_fp, ps->MR_ps_line_number);
> +    MR_write_byte(deep_fp, ps->MR_ps_is_in_interface);
> +    MR_write_num(deep_fp, ps->MR_ps_num_call_sites);
> +
> +    for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
> +        (void) MR_insert_call_site_static(&ps->MR_ps_call_sites[i], &css_id,
> +            NULL, MR_FALSE);
> +
> +#ifdef MR_DEEP_PROFILING_DEBUG
> +        if (debug_fp != NULL) {
> +            fprintf(debug_fp,
> +                "call site id %d in proc_static %p/%p/%d -> %d\n",
> +                i, proc_layout, ps, ps_id, css_id);
> +        }
> +#endif
> +
> +        MR_write_ptr(deep_fp, kind_css, css_id);
> +    }
> +
> +    for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
> +#ifdef MR_DEEP_PROFILING_DEBUG
> +        if (debug_fp != NULL) {
> +            fprintf(debug_fp, "in proc_static %p/%p/%d, call site %d\n",
> +                proc_layout, ps, ps_id, i);
> +        }
> +#endif
> +
> +        MR_write_out_call_site_static(deep_fp, &ps->MR_ps_call_sites[i]);
> +    }
> +
> +    if (procrep_fp != NULL) {
> +        const MR_uint_least8_t  *bytecode;
> +
> +        /*
> +        ** Some predicates in the Mercury standard library, such as
> +        ** exception.builtin_catch, have Mercury declarations but no Mercury
> +        ** implementation (even as foreign_proc code). We do still generate
> +        ** proc_static structures for them (since we *want* the hand-written
> +        ** C code to be able to collect deep profiling data (in this case,
> +        ** to count the number of executions of the EXCP port). This means that
> +        ** (a) they will have proc_layout structures, and (b) the bytecode
> +        ** pointer field in these structures will be NULL.
> +        **
> +        ** We handle such procedures by simply not including them in the
> +        ** module representation. This is fine, as long as any code that reads
> +        ** and processes the program representation is aware that the bodies
> +        ** of procedures defined outside Mercury may be missing.
> +        */
> +
> +        bytecode = proc_layout->MR_sle_body_bytes;
> +        if (bytecode != NULL) {
> +            int size;
> +            int bytenum;
> +
> +            putc(MR_next_proc, procrep_fp);
> +            MR_write_out_str_proc_label(procrep_fp, procid);
> +
> +            size = (bytecode[0] << 24) + (bytecode[1] << 16) +
> +                (bytecode[2] << 8) + bytecode[3];
> +            for (bytenum = 0; bytenum < size; bytenum++) {
> +                putc(bytecode[bytenum], procrep_fp);
> +            }
> +        }
> +    }
> +}
> +
> +void
> +MR_write_out_str_proc_label(FILE *deep_fp, const MR_ProcId *procid)
> +{
>      if (MR_PROC_ID_IS_UCI(*procid)) {
>  #ifdef MR_DEEP_PROFILING_DEBUG
>          if (debug_fp != NULL) {

Above size is set from the bytecode array using some bitshifts.  I
don't remember how this array is created.  Will this work on different
byte-order systems?

I have one more suggestion, otherwise I've finished reviewing this.

Thanks!



--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list