factor/basis/tools/threads/threads.factor

33 lines
959 B
Factor
Raw Normal View History

2008-02-18 06:07:40 -05:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-02-18 08:30:16 -05:00
USING: threads kernel prettyprint prettyprint.config
2008-02-21 20:13:11 -05:00
io io.styles sequences assocs namespaces sorting boxes
2008-08-29 18:07:30 -04:00
heaps.private system math math.parser math.order accessors ;
IN: tools.threads
2008-02-18 06:07:40 -05:00
: thread. ( thread -- )
dup thread-id pprint-cell
2008-02-21 02:25:40 -05:00
dup thread-name over [ write-object ] with-cell
dup thread-state [
[ dup self eq? "running" "yield" ? ] unless*
write
] with-cell
2008-02-21 20:13:11 -05:00
[
thread-sleep-entry [
2008-08-29 18:07:30 -04:00
key>> millis [-] number>string write
2008-02-21 20:13:11 -05:00
" ms" write
] when*
] with-cell ;
2008-02-18 06:07:40 -05:00
: threads. ( -- )
standard-table-style [
[
2008-04-11 08:15:26 -04:00
{ "ID:" "Name:" "Waiting on:" "Remaining sleep:" }
2008-02-18 06:07:40 -05:00
[ [ write ] with-cell ] each
] with-row
threads >alist sort-keys values [
2008-02-18 06:07:40 -05:00
[ thread. ] with-row
] each
] tabular-output ;