20 val group_of_task: task -> group |
20 val group_of_task: task -> group |
21 val name_of_task: task -> string |
21 val name_of_task: task -> string |
22 val pri_of_task: task -> int |
22 val pri_of_task: task -> int |
23 val str_of_task: task -> string |
23 val str_of_task: task -> string |
24 val str_of_task_groups: task -> string |
24 val str_of_task_groups: task -> string |
25 val timing_of_task: task -> Time.time * Time.time * string list |
25 val task_statistics: task -> Properties.T |
26 val running: task -> (unit -> 'a) -> 'a |
26 val running: task -> (unit -> 'a) -> 'a |
27 val joining: task -> (unit -> 'a) -> 'a |
27 val joining: task -> (unit -> 'a) -> 'a |
28 val waiting: task -> task list -> (unit -> 'a) -> 'a |
28 val waiting: task -> task list -> (unit -> 'a) -> 'a |
29 type queue |
29 type queue |
30 val empty: queue |
30 val empty: queue |
112 abstype task = Task of |
112 abstype task = Task of |
113 {group: group, |
113 {group: group, |
114 name: string, |
114 name: string, |
115 id: int, |
115 id: int, |
116 pri: int option, |
116 pri: int option, |
117 timing: timing Synchronized.var option} |
117 timing: timing Synchronized.var option, |
|
118 pos: Position.T} |
118 with |
119 with |
119 |
120 |
120 val dummy_task = |
121 val dummy_task = |
121 Task {group = new_group NONE, name = "", id = 0, pri = NONE, timing = NONE}; |
122 Task {group = new_group NONE, name = "", id = 0, pri = NONE, timing = NONE, |
|
123 pos = Position.none}; |
122 |
124 |
123 fun new_task group name pri = |
125 fun new_task group name pri = |
124 Task {group = group, name = name, id = new_id (), pri = pri, timing = new_timing ()}; |
126 Task {group = group, name = name, id = new_id (), pri = pri, timing = new_timing (), |
|
127 pos = Position.thread_data ()}; |
125 |
128 |
126 fun group_of_task (Task {group, ...}) = group; |
129 fun group_of_task (Task {group, ...}) = group; |
127 fun name_of_task (Task {name, ...}) = name; |
130 fun name_of_task (Task {name, ...}) = name; |
128 fun pri_of_task (Task {pri, ...}) = the_default 0 pri; |
131 fun pri_of_task (Task {pri, ...}) = the_default 0 pri; |
129 |
132 |
130 fun str_of_task (Task {name, id, ...}) = |
133 fun str_of_task (Task {name, id, ...}) = |
131 if name = "" then string_of_int id else string_of_int id ^ " (" ^ name ^ ")"; |
134 if name = "" then string_of_int id else string_of_int id ^ " (" ^ name ^ ")"; |
132 |
135 |
133 fun str_of_task_groups task = str_of_task task ^ " in " ^ str_of_groups (group_of_task task); |
136 fun str_of_task_groups task = str_of_task task ^ " in " ^ str_of_groups (group_of_task task); |
134 |
|
135 fun timing_of_task (Task {timing, ...}) = |
|
136 (case timing of NONE => timing_start | SOME var => Synchronized.value var); |
|
137 |
137 |
138 fun update_timing update (Task {timing, ...}) e = |
138 fun update_timing update (Task {timing, ...}) e = |
139 uninterruptible (fn restore_attributes => fn () => |
139 uninterruptible (fn restore_attributes => fn () => |
140 let |
140 let |
141 val start = Time.now (); |
141 val start = Time.now (); |
144 val _ = (case timing of NONE => () | SOME var => Synchronized.change var (update t)); |
144 val _ = (case timing of NONE => () | SOME var => Synchronized.change var (update t)); |
145 in Exn.release result end) (); |
145 in Exn.release result end) (); |
146 |
146 |
147 fun task_ord (Task {id = id1, pri = pri1, ...}, Task {id = id2, pri = pri2, ...}) = |
147 fun task_ord (Task {id = id1, pri = pri1, ...}, Task {id = id2, pri = pri2, ...}) = |
148 prod_ord (rev_order o option_ord int_ord) int_ord ((pri1, id1), (pri2, id2)); |
148 prod_ord (rev_order o option_ord int_ord) int_ord ((pri1, id1), (pri2, id2)); |
|
149 |
|
150 fun task_statistics (Task {name, id, timing, pos, ...}) = |
|
151 let |
|
152 val (run, wait, wait_deps) = |
|
153 (case timing of NONE => timing_start | SOME var => Synchronized.value var); |
|
154 fun micros time = string_of_int (Time.toNanoseconds time div 1000); |
|
155 in |
|
156 [("now", signed_string_of_real (Time.toReal (Time.now ()))), |
|
157 ("task_name", name), ("task_id", Markup.print_int id), |
|
158 ("run", micros run), ("wait", micros wait), ("wait_deps", commas wait_deps)] @ |
|
159 Position.properties_of pos |
|
160 end; |
149 |
161 |
150 end; |
162 end; |
151 |
163 |
152 structure Tasks = Table(type key = task val ord = task_ord); |
164 structure Tasks = Table(type key = task val ord = task_ord); |
153 structure Task_Graph = Graph(type key = task val ord = task_ord); |
165 structure Task_Graph = Graph(type key = task val ord = task_ord); |