| author | haftmann | 
| Wed, 05 Feb 2020 20:17:00 +0000 | |
| changeset 71420 | 572ab9e64e18 | 
| parent 70991 | f9f7c34b7dd4 | 
| child 71637 | 45c2b8cf1b26 | 
| permissions | -rw-r--r-- | 
| 14815 | 1 | (* Title: Pure/General/output.ML | 
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 2 | Author: Makarius | 
| 14815 | 3 | |
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 4 | Isabelle output channels. | 
| 14815 | 5 | *) | 
| 6 | ||
| 7 | signature BASIC_OUTPUT = | |
| 8 | sig | |
| 18682 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 9 | val writeln: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 10 | val tracing: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 11 | val warning: string -> unit | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 12 | val legacy_feature: string -> unit | 
| 61885 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 13 |   val profile_time: ('a -> 'b) -> 'a -> 'b
 | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 14 |   val profile_time_thread: ('a -> 'b) -> 'a -> 'b
 | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 15 |   val profile_allocations: ('a -> 'b) -> 'a -> 'b
 | 
| 14815 | 16 | end; | 
| 17 | ||
| 18 | signature OUTPUT = | |
| 19 | sig | |
| 20 | include BASIC_OUTPUT | |
| 40131 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
40125diff
changeset | 21 | type output = string | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 22 | val default_output: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 23 | val default_escape: output -> string | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 24 | val add_mode: string -> (string -> output * int) -> (output -> string) -> unit | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 25 | val output_width: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 26 | val output: string -> output | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 27 | val escape: output -> string | 
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 28 | val physical_stdout: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 29 | val physical_stderr: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 30 | val physical_writeln: output -> unit | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 31 | type protocol_message_fn = Output_Primitives.protocol_message_fn | 
| 51661 | 32 | exception Protocol_Message of Properties.T | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 33 | val protocol_message_undefined: protocol_message_fn | 
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 34 | val writelns: string list -> unit | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 35 | val state: string -> unit | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 36 | val information: string -> unit | 
| 54387 | 37 | val error_message': serial * string -> unit | 
| 38 | val error_message: string -> unit | |
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 39 | val system_message: string -> unit | 
| 70662 | 40 | val status: string list -> unit | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 41 | val report: string list -> unit | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 42 | val result: Properties.T -> string list -> unit | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 43 | val protocol_message: protocol_message_fn | 
| 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 44 | val try_protocol_message: protocol_message_fn | 
| 14815 | 45 | end; | 
| 46 | ||
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 47 | signature PRIVATE_OUTPUT = | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 48 | sig | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 49 | include OUTPUT | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 50 | val writeln_fn: (output list -> unit) Unsynchronized.ref | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 51 | val state_fn: (output list -> unit) Unsynchronized.ref | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 52 | val information_fn: (output list -> unit) Unsynchronized.ref | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 53 | val tracing_fn: (output list -> unit) Unsynchronized.ref | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 54 | val warning_fn: (output list -> unit) Unsynchronized.ref | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 55 | val legacy_fn: (output list -> unit) Unsynchronized.ref | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 56 | val error_message_fn: (serial * output list -> unit) Unsynchronized.ref | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 57 | val system_message_fn: (output list -> unit) Unsynchronized.ref | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 58 | val status_fn: (output list -> unit) Unsynchronized.ref | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 59 | val report_fn: (output list -> unit) Unsynchronized.ref | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 60 | val result_fn: (Properties.T -> output list -> unit) Unsynchronized.ref | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 61 | val protocol_message_fn: Output_Primitives.protocol_message_fn Unsynchronized.ref | 
| 65301 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 62 | val init_channels: unit -> unit | 
| 55387 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 63 | end; | 
| 
51f0876f61df
seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
 wenzelm parents: 
54387diff
changeset | 64 | |
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 65 | structure Private_Output: PRIVATE_OUTPUT = | 
| 14815 | 66 | struct | 
| 67 | ||
| 23616 | 68 | (** print modes **) | 
| 14881 | 69 | |
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 70 | type output = string; (*raw system output*) | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 71 | |
| 23616 | 72 | fun default_output s = (s, size s); | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 73 | fun default_escape (s: output) = s; | 
| 14815 | 74 | |
| 23616 | 75 | local | 
| 76 |   val default = {output = default_output, escape = default_escape};
 | |
| 43684 | 77 |   val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]);
 | 
| 23616 | 78 | in | 
| 43684 | 79 | fun add_mode name output escape = | 
| 62894 | 80 | if Thread_Data.is_virtual then () | 
| 81 |     else Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape}));
 | |
| 23616 | 82 | fun get_mode () = | 
| 43684 | 83 | the_default default | 
| 84 | (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); | |
| 23616 | 85 | end; | 
| 14815 | 86 | |
| 19265 | 87 | fun output_width x = #output (get_mode ()) x; | 
| 14815 | 88 | val output = #1 o output_width; | 
| 23727 | 89 | |
| 23616 | 90 | fun escape x = #escape (get_mode ()) x; | 
| 14815 | 91 | |
| 92 | ||
| 93 | ||
| 94 | (** output channels **) | |
| 95 | ||
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 96 | (* primitives -- provided via bootstrap environment *) | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 97 | |
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 98 | val writeln_fn = Unsynchronized.ref Output_Primitives.writeln_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 99 | val state_fn = Unsynchronized.ref Output_Primitives.state_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 100 | val information_fn = Unsynchronized.ref Output_Primitives.information_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 101 | val tracing_fn = Unsynchronized.ref Output_Primitives.tracing_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 102 | val warning_fn = Unsynchronized.ref Output_Primitives.warning_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 103 | val legacy_fn = Unsynchronized.ref Output_Primitives.legacy_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 104 | val error_message_fn = Unsynchronized.ref Output_Primitives.error_message_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 105 | val system_message_fn = Unsynchronized.ref Output_Primitives.system_message_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 106 | val status_fn = Unsynchronized.ref Output_Primitives.status_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 107 | val report_fn = Unsynchronized.ref Output_Primitives.report_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 108 | val result_fn = Unsynchronized.ref Output_Primitives.result_fn; | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 109 | |
| 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 110 | type protocol_message_fn = Output_Primitives.protocol_message_fn; | 
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 111 | val protocol_message_fn = Unsynchronized.ref Output_Primitives.protocol_message_fn; | 
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 112 | |
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 113 | |
| 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 114 | (* physical output -- not to be used in user-space *) | 
| 14984 | 115 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 116 | fun physical_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut); | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 117 | fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); | 
| 14815 | 118 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 119 | fun physical_writeln "" = () | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 120 | | physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) | 
| 14815 | 121 | |
| 14984 | 122 | |
| 123 | (* Isabelle output channels *) | |
| 124 | ||
| 51661 | 125 | exception Protocol_Message of Properties.T; | 
| 126 | ||
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 127 | val protocol_message_undefined: Output_Primitives.protocol_message_fn = | 
| 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 128 | fn props => fn _ => raise Protocol_Message props; | 
| 70907 | 129 | |
| 65301 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 130 | fun init_channels () = | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 131 | (writeln_fn := (physical_writeln o implode); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 132 | state_fn := (fn ss => ! writeln_fn ss); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 133 | information_fn := Output_Primitives.ignore_outputs; | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 134 | tracing_fn := (fn ss => ! writeln_fn ss); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 135 | warning_fn := (physical_writeln o prefix_lines "### " o implode); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 136 | legacy_fn := (fn ss => ! warning_fn ss); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 137 | error_message_fn := (fn (_, ss) => physical_writeln (prefix_lines "*** " (implode ss))); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 138 | system_message_fn := (fn ss => ! writeln_fn ss); | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 139 | status_fn := Output_Primitives.ignore_outputs; | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 140 | report_fn := Output_Primitives.ignore_outputs; | 
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 141 | result_fn := (fn _ => Output_Primitives.ignore_outputs); | 
| 70907 | 142 | protocol_message_fn := protocol_message_undefined); | 
| 65301 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 143 | |
| 
fca593a62785
restore output channels after shutdown, e.g. relevant for saved heap;
 wenzelm parents: 
63517diff
changeset | 144 | val _ = if Thread_Data.is_virtual then () else init_channels (); | 
| 14815 | 145 | |
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 146 | fun writelns ss = ! writeln_fn (map output ss); | 
| 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56333diff
changeset | 147 | fun writeln s = writelns [s]; | 
| 59184 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 148 | fun state s = ! state_fn [output s]; | 
| 
830bb7ddb3ab
explicit message channels for "state", "information";
 wenzelm parents: 
58850diff
changeset | 149 | fun information s = ! information_fn [output s]; | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 150 | fun tracing s = ! tracing_fn [output s]; | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 151 | fun warning s = ! warning_fn [output s]; | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59184diff
changeset | 152 | fun legacy_feature s = ! legacy_fn [output ("Legacy feature! " ^ s)];
 | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 153 | fun error_message' (i, s) = ! error_message_fn (i, [output s]); | 
| 54387 | 154 | fun error_message s = error_message' (serial (), s); | 
| 57975 
c657c68a60ab
explicit system message for protocol failure -- show on Syslog panel instead of Raw Output;
 wenzelm parents: 
56830diff
changeset | 155 | fun system_message s = ! system_message_fn [output s]; | 
| 70662 | 156 | fun status ss = ! status_fn (map output ss); | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 157 | fun report ss = ! report_fn (map output ss); | 
| 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
56304diff
changeset | 158 | fun result props ss = ! result_fn props (map output ss); | 
| 70991 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 159 | fun protocol_message props body = ! protocol_message_fn props body; | 
| 
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
 wenzelm parents: 
70907diff
changeset | 160 | fun try_protocol_message props body = protocol_message props body handle Protocol_Message _ => (); | 
| 15190 | 161 | |
| 61885 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 162 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 163 | (* profiling *) | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 164 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 165 | local | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 166 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 167 | fun output_profile title entries = | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 168 | let | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 169 | val body = entries | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 170 | |> sort (int_ord o apply2 fst) | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 171 | |> map (fn (count, name) => | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 172 | let | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 173 | val c = string_of_int count; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 174 | val prefix = replicate_string (Int.max (0, 10 - size c)) " "; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 175 | in prefix ^ c ^ " " ^ name end); | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 176 | val total = fold (curry (op +) o fst) entries 0; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 177 | in | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 178 | if total = 0 then () | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 179 | else warning (cat_lines (title :: (body @ ["total: " ^ string_of_int total]))) | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 180 | end; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 181 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 182 | in | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 183 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 184 | fun profile_time f x = | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 185 | ML_Profiling.profile_time (output_profile "time profile:") f x; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 186 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 187 | fun profile_time_thread f x = | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 188 | ML_Profiling.profile_time_thread (output_profile "time profile (this thread):") f x; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 189 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 190 | fun profile_allocations f x = | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 191 | ML_Profiling.profile_allocations (output_profile "allocations profile:") f x; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 192 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 193 | end; | 
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 194 | |
| 
acdfc76a6c33
more explicit ML profiling, with official Isabelle output;
 wenzelm parents: 
59203diff
changeset | 195 | |
| 14815 | 196 | end; | 
| 197 | ||
| 62930 
51ac6bc389e8
shared output primitives of physical/virtual Pure;
 wenzelm parents: 
62894diff
changeset | 198 | structure Output: OUTPUT = Private_Output; | 
| 32738 | 199 | structure Basic_Output: BASIC_OUTPUT = Output; | 
| 200 | open Basic_Output; |