[m-rev.] for review: reporting stats NOT to stderr
Julien Fischer
jfischer at opturion.com
Mon Mar 8 14:52:25 AEDT 2021
Hi Zoltan,
On Sun, 7 Mar 2021, Zoltan Somogyi wrote:
> We need the capability to print stats to a user-selected stream,
> and not just to stderr, if we are to convert the rest of the compiler
> to always use explicit streams.
>
> This diff makes the change only for the C backend. Would anyone
> volunteer to make the change to for the C# and Java backends?
I will take a look at them.
> For review by anyone. Note that this diff is from before replacing
> any ML_ prefixes with MR_ prefixes on code moved from the library
> to the runtime, to reduce clutter in any manual diffs.
...
> Allow reporting of stats to a stream for C.
>
> Until now, all the predicates that reported statistics wrote their output
> to stderr; users could not choose another stream. This diff adds ways
> to report those same statistics to a stream chosen by the user, though
> for now, only when targeting C.
>
> The code for reporting statistics used to be in benchmarking.m, in the
> form of a foreign_decl/foreign_code pair that declared and defined the
> needed data structures and functions, and foreign_procs that called them.
> All this code had stderr hard-coded as the destination stream.
>
> As long as the output is done by C code (as opposed to the C code
> constructing a big string containing all the stuff to be output),
> directing the output to a user-supplied io.text_output_stream requires
> converting that text_output_stream to a value of the C "FILE *" type.
> This requires access to the actual definition of the io.text_output_stream
> type, which is private to io.m. We could export it to benchmarking.m,
> but that is undesirable.
MR_file(*MR_unwrap_output_stream(Stream)) should do it.
(That's what we currently do in a similar situation in browser/listing.m.)
That said, I don't have any objections to do it the way you've done here
either.
> Instead, this diff moves the code that used to be in benchmarking.m's
> foreign_decl/foreign_code pair to a new module in the runtime,
> mercury_report_stats.[ch], which allows foreign_procs in both benchmarking.m
> and io.m to use it.
>
> We used to have
>
> impure report_stats/0 in benchmarking.m
> report_stats/2 in io.m
> report_stats/3 in io.m
Aside: perhaps we should consider deleting the impure versions of these
operations? They've not really been necessary since trace goals were
added to the language.
> The difference between the two versions in io.m is a "selector" argument
> that specifies which kind of stats to print. Adding a text_output_stream
> argument to report_stats/2 would create report_stats/3, which clashes
> with this existing name/arity pair. This diff therefore renames
> io.report_stats/2 as io.report_standard_stats.
That looks fine.
Julien.
More information about the reviews
mailing list