]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/threads/threads.factor
1b75e46e2545ec97b8e8abe20f564dd6d2670d28
[factor.git] / basis / tools / threads / threads.factor
1 ! Copyright (C) 2008 Slava Pestov.\r
2 ! See http://factorcode.org/license.txt for BSD license.\r
3 USING: threads kernel prettyprint prettyprint.config\r
4 io io.styles sequences assocs namespaces sorting boxes\r
5 heaps.private system math math.parser math.order accessors ;\r
6 IN: tools.threads\r
7 \r
8 : thread. ( thread -- )\r
9     dup id>> pprint-cell\r
10     dup name>> over [ write-object ] with-cell\r
11     dup state>> [\r
12         [ dup self eq? "running" "yield" ? ] unless*\r
13         write\r
14     ] with-cell\r
15     [\r
16         sleep-entry>> [\r
17             key>> millis [-] number>string write\r
18             " ms" write\r
19         ] when*\r
20     ] with-cell ;\r
21 \r
22 : threads. ( -- )\r
23     standard-table-style [\r
24         [\r
25             { "ID:" "Name:" "Waiting on:" "Remaining sleep:" }\r
26             [ [ write ] with-cell ] each\r
27         ] with-row\r
28 \r
29         threads >alist sort-keys values [\r
30             [ thread. ] with-row\r
31         ] each\r
32     ] tabular-output ;\r