[m-rev.] for review: dumping trace counts

Ralph Becket rafe at csse.unimelb.edu.au
Mon Sep 25 13:34:42 AEST 2006


Zoltan Somogyi, Monday, 25 September 2006:
> compiler/mercury_compile.m:
> 	Add a mechanism for dumping out trace counts at selected stages.

The code looks fine.

> @@ -4625,10 +4627,71 @@
>              CurDumpFileName = DumpFileName
>          ),
>          !:DumpInfo = prev_dumped_hlds(CurDumpFileName, HLDS)
> +    ; should_dump_stage(StageNum, StageNumStr, StageName, DumpTraceStages) ->
> +        module_info_get_name(HLDS, ModuleName),
> +        module_name_to_file_name(ModuleName, ".trace_counts", yes,
> +            BaseFileName, !IO),
> +        DumpFileName = BaseFileName ++ "." ++ StageNumStr ++ "-" ++ StageName,
> +        dump_trace_counts_to(DumpFileName, Result, !IO),
> +        ( Result = 0 ->
> +            maybe_write_string(Verbose, "% Dumped trace counts to `", !IO),
> +            maybe_write_string(Verbose, DumpFileName, !IO),
> +            maybe_write_string(Verbose, "'\n", !IO),
> +            maybe_flush_output(Verbose, !IO)
> +        ; Result = 1 ->
> +            io.write_string("% Couldn't dump trace counts to `", !IO),
> +            io.write_string(DumpFileName, !IO),
> +            io.write_string("': no compiled with debugging\n", !IO),
> +            io.flush_output(!IO)
> +        ; Result = 2 ->
> +            io.write_string("% Couldn't dump trace counts to `", !IO),
> +            io.write_string(DumpFileName, !IO),
> +            io.write_string("': trace counting not turned on\n", !IO),
> +            io.flush_output(!IO)
> +        ; Result = 3 ->
> +            io.write_string("% Couldn't dump trace counts to `", !IO),
> +            io.write_string(DumpFileName, !IO),
> +            io.write_string("': couldn't open file\n", !IO),
> +            io.flush_output(!IO)
> +        ;
> +            io.write_string("% Couldn't dump trace counts to `", !IO),
> +            io.write_string(DumpFileName, !IO),
> +            io.write_string("'\n", !IO),
> +            io.flush_output(!IO)
> +        )
>      ;
>          true
>      ).
>  
> +:- pred dump_trace_counts_to(string::in, int::out, io::di, io::uo) is det.
> +
> +:- pragma foreign_proc("C",
> +    dump_trace_counts_to(FileName::in, Result::out, _IO0::di, _IO::uo),
> +    [will_not_call_mercury, promise_pure],
> +"
> +#ifdef  MR_EXEC_TRACE
> +    FILE    *fp;
> +
> +    if (MR_trace_count_enabled && MR_trace_func_enabled) {
> +        fp = fopen(FileName, ""w"");
> +        if (fp != NULL) {
> +            MR_trace_write_label_exec_counts(fp, MR_FALSE);
> +            Result = 0;
> +            (void) fclose(fp);
> +        } else {
> +            Result = 3;
> +        }
> +    } else {
> +        Result = 2;
> +    }
> +#else
> +    Result = 1;
> +#endif
> +").
> +
> +% Default definition for non-C backends.
> +dump_trace_counts_to(_, 1, !IO).
> +

The business of magic numbers in mixed C/Mercury code crops up often
enough that we really should provide better support for sharing
constants between Mercury and foreign code.

--------------------------------------------------------------------------
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