rename millis to system-millis, micros to system-micros, add nano-count

db4
Doug Coleman 2009-11-18 15:58:48 -06:00
parent 0145f0f860
commit 6f7ec206a1
33 changed files with 103 additions and 92 deletions

View File

@ -59,7 +59,7 @@ SYMBOL: bootstrap-time
[
! We time bootstrap
millis
system-millis
default-image-name "output-image" set-global
@ -84,14 +84,14 @@ SYMBOL: bootstrap-time
load-components
millis over - core-bootstrap-time set-global
system-millis over - core-bootstrap-time set-global
run-bootstrap-init
f error set-global
f error-continuation set-global
millis swap - bootstrap-time set-global
system-millis swap - bootstrap-time set-global
print-report
"deploy-vocab" get [

View File

@ -391,7 +391,7 @@ M: duration time-
: gmt ( -- timestamp )
#! GMT time, right now
unix-1970 micros microseconds time+ ;
unix-1970 system-micros microseconds time+ ;
: now ( -- timestamp ) gmt >local-time ;
: hence ( duration -- timestamp ) now swap time+ ;

View File

@ -22,7 +22,7 @@ server-state f
: expire-state ( class -- )
new
-1/0. millis [a,b] >>expires
-1/0. system-millis [a,b] >>expires
delete-tuples ;
TUPLE: server-state-manager < filter-responder timeout ;

View File

@ -511,11 +511,11 @@ M: bad-executable summary
\ code-room { } { byte-array } define-primitive
\ code-room make-flushable
\ micros { } { integer } define-primitive
\ micros make-flushable
\ system-micros { } { integer } define-primitive
\ system-micros make-flushable
\ nanos { } { integer } define-primitive
\ nanos make-flushable
\ nano-count { } { integer } define-primitive
\ nano-count make-flushable
\ tag { object } { fixnum } define-primitive
\ tag make-foldable

View File

@ -95,7 +95,7 @@ PRIVATE>
{
{ [ run-queue deque-empty? not ] [ 0 ] }
{ [ sleep-queue heap-empty? ] [ f ] }
[ sleep-queue heap-peek nip micros [-] ]
[ sleep-queue heap-peek nip system-micros [-] ]
} cond ;
DEFER: stop
@ -108,7 +108,7 @@ DEFER: stop
: expire-sleep? ( heap -- ? )
dup heap-empty?
[ drop f ] [ heap-peek nip micros <= ] if ;
[ drop f ] [ heap-peek nip system-micros <= ] if ;
: expire-sleep ( thread -- )
f >>sleep-entry resume ;
@ -184,7 +184,7 @@ M: f sleep-until
GENERIC: sleep ( dt -- )
M: real sleep
micros + >integer sleep-until ;
system-micros + >integer sleep-until ;
: interrupt ( thread -- )
dup state>> [

View File

@ -18,8 +18,8 @@ IN: tools.memory
: kilobytes ( n -- str )
1024 /i commas " KB" append ;
: micros>string ( n -- str )
commas " µs" append ;
: nanos>string ( n -- str )
1000 /i commas " µs" append ;
: copying-room. ( copying-sizes -- )
{
@ -153,11 +153,11 @@ TUPLE: gc-stats collections times ;
[ collections>> ]
[
times>> {
[ sum micros>string ]
[ mean >integer micros>string ]
[ median >integer micros>string ]
[ infimum micros>string ]
[ supremum micros>string ]
[ sum nanos>string ]
[ mean >integer nanos>string ]
[ median >integer nanos>string ]
[ infimum nanos>string ]
[ supremum nanos>string ]
} cleave
] bi
] bi
@ -172,7 +172,7 @@ PRIVATE>
: gc-event. ( event -- )
{
{ "Event type:" [ op>> gc-op-string ] }
{ "Total time:" [ total-time>> micros>string ] }
{ "Total time:" [ total-time>> nanos>string ] }
{ "Space reclaimed:" [ space-reclaimed kilobytes ] }
} object-table. ;
@ -188,10 +188,10 @@ PRIVATE>
{ "Cards scanned:" [ [ cards-scanned>> ] map-sum commas ] }
{ "Decks scanned:" [ [ decks-scanned>> ] map-sum commas ] }
{ "Code blocks scanned:" [ [ code-blocks-scanned>> ] map-sum commas ] }
{ "Total time:" [ [ total-time>> ] map-sum micros>string ] }
{ "Card scan time:" [ [ card-scan-time>> ] map-sum micros>string ] }
{ "Code block scan time:" [ [ code-scan-time>> ] map-sum micros>string ] }
{ "Data heap sweep time:" [ [ data-sweep-time>> ] map-sum micros>string ] }
{ "Code heap sweep time:" [ [ code-sweep-time>> ] map-sum micros>string ] }
{ "Compaction time:" [ [ compaction-time>> ] map-sum micros>string ] }
{ "Total time:" [ [ total-time>> ] map-sum nanos>string ] }
{ "Card scan time:" [ [ card-scan-time>> ] map-sum nanos>string ] }
{ "Code block scan time:" [ [ code-scan-time>> ] map-sum nanos>string ] }
{ "Data heap sweep time:" [ [ data-sweep-time>> ] map-sum nanos>string ] }
{ "Code heap sweep time:" [ [ code-sweep-time>> ] map-sum nanos>string ] }
{ "Compaction time:" [ [ compaction-time>> ] map-sum nanos>string ] }
} object-table. ;

View File

@ -14,7 +14,7 @@ IN: tools.threads
] with-cell
[
sleep-entry>> [
key>> micros [-] number>string write
key>> nano-count 1000 /i [-] number>string write
" us" write
] when*
] with-cell ;

View File

@ -10,7 +10,7 @@ ARTICLE: "timing" "Timing code and collecting statistics"
"A lower-level word puts timings on the stack, intead of printing:"
{ $subsections benchmark }
"You can also read the system clock directly:"
{ $subsections micros }
{ $subsections system-micros }
{ $see-also "profiling" "calendar" } ;
ABOUT: "timing"
@ -25,7 +25,7 @@ HELP: time
{ $values { "quot" quotation } }
{ $description "Runs a quotation, gathering statistics about method dispatch and garbage collection, and then prints the total run time." } ;
{ benchmark micros time } related-words
{ benchmark system-micros system-millis time } related-words
HELP: collect-gc-events
{ $values { "quot" quotation } }

View File

@ -5,10 +5,10 @@ tools.dispatch ;
IN: tools.time
: benchmark ( quot -- runtime )
micros [ call micros ] dip - ; inline
nano-count [ call nano-count ] dip - ; inline
: time. ( time -- )
"Running time: " write 1000000 /f pprint " seconds" print ;
"Running time: " write 1000000000 /f pprint " seconds" print ;
: time-banner. ( -- )
"Additional information was collected." print

View File

@ -174,7 +174,7 @@ HELP: hand-last-button
{ $var-description "Global variable. The mouse button most recently pressed." } ;
HELP: hand-last-time
{ $var-description "Global variable. The timestamp of the most recent mouse button click. This timestamp has the same format as the output value of " { $link micros } "." } ;
{ $var-description "Global variable. The timestamp of the most recent mouse button click. This timestamp has the same format as the output value of " { $link system-micros } "." } ;
HELP: hand-buttons
{ $var-description "Global variable. A vector of mouse buttons currently held down." } ;

View File

@ -432,8 +432,8 @@ tuple
{ "(exit)" "system" (( n -- )) }
{ "data-room" "memory" (( -- data-room )) }
{ "code-room" "memory" (( -- code-room )) }
{ "micros" "system" (( -- us )) }
{ "nanos" "system" (( -- us )) }
{ "system-micros" "system" (( -- us )) }
{ "nano-count" "system" (( -- ns )) }
{ "modify-code-heap" "compiler.units" (( alist -- )) }
{ "(dlopen)" "alien.libraries" (( path -- dll )) }
{ "(dlsym)" "alien.libraries" (( name dll -- alien )) }

View File

@ -16,8 +16,8 @@ ARTICLE: "system" "System interface"
}
"Getting the current time:"
{ $subsections
micros
millis
system-micros
system-micros
}
"Exiting the Factor VM:"
{ $subsections exit } ;
@ -77,12 +77,12 @@ HELP: exit ( n -- )
{ $values { "n" "an integer exit code" } }
{ $description "Exits the Factor process." } ;
HELP: micros ( -- us )
HELP: system-micros ( -- us )
{ $values { "us" integer } }
{ $description "Outputs the number of microseconds ellapsed since midnight January 1, 1970." }
{ $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;
HELP: millis ( -- ms )
HELP: system-millis ( -- ms )
{ $values { "ms" integer } }
{ $description "Outputs the number of milliseconds ellapsed since midnight January 1, 1970." }
{ $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;

View File

@ -55,6 +55,6 @@ PRIVATE>
: embedded? ( -- ? ) 15 getenv ;
: millis ( -- ms ) micros 1000 /i ;
: system-millis ( -- ms ) system-micros 1000 /i ;
: exit ( n -- ) do-shutdown-hooks (exit) ;

View File

@ -21,7 +21,7 @@ GENERIC: draw* ( tick-slice delegate -- )
SYMBOL: game-loop
: since-last-tick ( loop -- milliseconds )
last-tick>> millis swap - ;
last-tick>> system-millis swap - ;
: tick-slice ( loop -- slice )
[ since-last-tick ] [ tick-length>> ] bi /f 1.0 min ;
@ -53,7 +53,7 @@ TUPLE: game-loop-error game-loop error ;
drop ;
: ?tick ( loop count -- )
[ millis >>last-tick drop ] [
[ system-millis >>last-tick drop ] [
over [ since-last-tick ] [ tick-length>> ] bi >=
[ [ drop increment-tick ] [ drop tick ] [ 1 - ?tick ] 2tri ]
[ 2drop ] if
@ -70,12 +70,12 @@ TUPLE: game-loop-error game-loop error ;
with-variable ;
: benchmark-millis ( loop -- millis )
millis swap benchmark-time>> - ;
system-millis swap benchmark-time>> - ;
PRIVATE>
: reset-loop-benchmark ( loop -- )
millis >>benchmark-time
system-millis >>benchmark-time
dup tick-number>> >>benchmark-tick-number
dup frame-number>> >>benchmark-frame-number
drop ;
@ -86,7 +86,7 @@ PRIVATE>
[ frame-number>> ] [ benchmark-frame-number>> - ] [ benchmark-millis ] tri /f ;
: start-loop ( loop -- )
millis >>last-tick
system-millis >>last-tick
t >>running?
[ reset-loop-benchmark ]
[ [ run-loop ] curry "game loop" spawn ]
@ -98,7 +98,7 @@ PRIVATE>
drop ;
: <game-loop> ( tick-length delegate -- loop )
millis f f 0 0 millis 0 0
system-millis f f 0 0 system-millis 0 0
game-loop boa ;
M: game-loop dispose

View File

@ -39,9 +39,9 @@ CONSTANT: max-speed 30.0
>>tunnel to-tunnel-start ;
: update-time ( player -- seconds-passed )
millis swap [ last-move>> - 1000 / ] [ (>>last-move) ] 2bi ;
system-millis swap [ last-move>> - 1000 / ] [ (>>last-move) ] 2bi ;
: moved ( player -- ) millis swap (>>last-move) ;
: moved ( player -- ) system-millis swap (>>last-move) ;
: speed-range ( -- range )
max-speed [0,b] ;

View File

@ -358,8 +358,8 @@ M: space-invaders update-video ( value addr cpu -- )
: sync-frame ( millis -- millis )
#! Sleep until the time for the next frame arrives.
1000 60 / >fixnum + system:millis - dup 0 >
[ milliseconds threads:sleep ] [ drop threads:yield ] if system:millis ;
1000 60 / >fixnum + system:system-millis - dup 0 >
[ milliseconds threads:sleep ] [ drop threads:yield ] if system:system-millis ;
: invaders-process ( millis gadget -- )
#! Run a space invaders gadget inside a
@ -377,7 +377,7 @@ M: space-invaders update-video ( value addr cpu -- )
M: invaders-gadget graft* ( gadget -- )
dup cpu>> init-sounds
f over (>>quit?)
[ system:millis swap invaders-process ] curry
[ system:system-millis swap invaders-process ] curry
"Space invaders" threads:spawn drop ;
M: invaders-gadget ungraft* ( gadget -- )

View File

@ -104,10 +104,10 @@ CONSTANT: default-height 20
dup { 0 1 } tetris-move [ move-drop ] [ lock-piece ] if ;
: update ( tetris -- )
millis over last-update>> -
system-millis over last-update>> -
over update-interval > [
dup move-down
millis >>last-update
system-millis >>last-update
] when drop ;
: ?update ( tetris -- )

View File

@ -119,7 +119,7 @@ void factor_vm::init_factor(vm_parameters *p)
if(p->image_path == NULL)
p->image_path = default_image_path();
srand(current_micros());
srand(system_micros());
init_ffi();
init_stacks(p->ds_size,p->rs_size);
init_callbacks(p->callback_size);

View File

@ -8,7 +8,7 @@ gc_event::gc_event(gc_op op_, factor_vm *parent) :
cards_scanned(0),
decks_scanned(0),
code_blocks_scanned(0),
start_time(current_micros()),
start_time(nano_count()),
card_scan_time(0),
code_scan_time(0),
data_sweep_time(0),
@ -17,70 +17,70 @@ gc_event::gc_event(gc_op op_, factor_vm *parent) :
{
data_heap_before = parent->data_room();
code_heap_before = parent->code_room();
start_time = current_micros();
start_time = nano_count();
}
void gc_event::started_card_scan()
{
temp_time = current_micros();
temp_time = nano_count();
}
void gc_event::ended_card_scan(cell cards_scanned_, cell decks_scanned_)
{
cards_scanned += cards_scanned_;
decks_scanned += decks_scanned_;
card_scan_time = (current_micros() - temp_time);
card_scan_time = (nano_count() - temp_time);
}
void gc_event::started_code_scan()
{
temp_time = current_micros();
temp_time = nano_count();
}
void gc_event::ended_code_scan(cell code_blocks_scanned_)
{
code_blocks_scanned += code_blocks_scanned_;
code_scan_time = (current_micros() - temp_time);
code_scan_time = (nano_count() - temp_time);
}
void gc_event::started_data_sweep()
{
temp_time = current_micros();
temp_time = nano_count();
}
void gc_event::ended_data_sweep()
{
data_sweep_time = (current_micros() - temp_time);
data_sweep_time = (nano_count() - temp_time);
}
void gc_event::started_code_sweep()
{
temp_time = current_micros();
temp_time = nano_count();
}
void gc_event::ended_code_sweep()
{
code_sweep_time = (current_micros() - temp_time);
code_sweep_time = (nano_count() - temp_time);
}
void gc_event::started_compaction()
{
temp_time = current_micros();
temp_time = nano_count();
}
void gc_event::ended_compaction()
{
compaction_time = (current_micros() - temp_time);
compaction_time = (nano_count() - temp_time);
}
void gc_event::ended_gc(factor_vm *parent)
{
data_heap_after = parent->data_room();
code_heap_after = parent->code_room();
total_time = current_micros() - start_time;
total_time = nano_count() - start_time;
}
gc_state::gc_state(gc_op op_, factor_vm *parent) : op(op_), start_time(current_micros())
gc_state::gc_state(gc_op op_, factor_vm *parent) : op(op_), start_time(nano_count())
{
event = new gc_event(op,parent);
}

View File

@ -35,7 +35,7 @@ const char *default_image_path()
return new_path;
}
u64 current_nanos()
u64 nano_count()
{
struct timespec t;
int ret;

View File

@ -85,7 +85,7 @@ Protocol *objc_getProtocol(char *name)
return nil;
}
u64 current_nanos()
u64 nano_count()
{
u64 t;
mach_timebase_info_data_t info;

View File

@ -40,11 +40,11 @@ factor_vm *tls_vm()
static void *null_dll;
s64 current_micros()
u64 system_micros()
{
struct timeval t;
gettimeofday(&t,NULL);
return (s64)t.tv_sec * 1000000 + t.tv_usec;
return (u64)t.tv_sec * 1000000 + t.tv_usec;
}
void sleep_micros(cell usec)
@ -52,9 +52,19 @@ void sleep_micros(cell usec)
usleep(usec);
}
void sleep_nanos(cell nsec)
void sleep_nanos(timespec ts)
{
//nanosleep(n
timespec ts_rem;
int ret;
ret = nanosleep(&ts,&ts_rem);
while(ret == -1 && errno == EINTR)
{
memcpy(&ts, &ts_rem, sizeof(ts));
ret = nanosleep(&ts, &ts_rem);
}
if(ret == -1)
fatal_error("nanosleep failed", 0);
}
void factor_vm::init_ffi()

View File

@ -52,9 +52,10 @@ void unix_init_signals();
void signal_handler(int signal, siginfo_t* siginfo, void* uap);
void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
s64 current_micros();
u64 current_nanos();
u64 system_micros();
u64 nano_count();
void sleep_micros(cell usec);
void sleep_nanos(cell nsec);
void init_platform_globals();

View File

@ -3,7 +3,7 @@
namespace factor
{
s64 current_micros()
u64 system_micros()
{
SYSTEMTIME st;
FILETIME ft;

View File

@ -22,7 +22,7 @@ char *getenv(char *name);
#define snprintf _snprintf
#define snwprintf _snwprintf
s64 current_micros();
u64 system_micros();
void c_to_factor_toplevel(cell quot);
void open_console();

View File

@ -28,15 +28,15 @@ factor_vm *tls_vm()
return vm;
}
s64 current_micros()
u64 system_micros()
{
FILETIME t;
GetSystemTimeAsFileTime(&t);
return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32)
return (((u64)t.dwLowDateTime | (u64)t.dwHighDateTime<<32)
- EPOCH_OFFSET) / 10;
}
u64 current_nanos()
u64 nano_count()
{
LARGE_INTEGER count;
LARGE_INTEGER frequency;

View File

@ -43,8 +43,8 @@ typedef wchar_t vm_char;
inline static void init_signals() {}
inline static void early_init() {}
s64 current_micros();
u64 current_nanos();
u64 system_micros();
u64 nano_count();
long getpagesize();
}

View File

@ -66,8 +66,8 @@ PRIMITIVE_FORWARD(set_callstack)
PRIMITIVE_FORWARD(exit)
PRIMITIVE_FORWARD(data_room)
PRIMITIVE_FORWARD(code_room)
PRIMITIVE_FORWARD(micros)
PRIMITIVE_FORWARD(nanos)
PRIMITIVE_FORWARD(system_micros)
PRIMITIVE_FORWARD(nano_count)
PRIMITIVE_FORWARD(modify_code_heap)
PRIMITIVE_FORWARD(dlopen)
PRIMITIVE_FORWARD(dlsym)
@ -203,8 +203,8 @@ const primitive_type primitives[] = {
primitive_exit,
primitive_data_room,
primitive_code_room,
primitive_micros,
primitive_nanos,
primitive_system_micros,
primitive_nano_count,
primitive_modify_code_heap,
primitive_dlopen,
primitive_dlsym,

View File

@ -8,14 +8,14 @@ void factor_vm::primitive_exit()
exit(to_fixnum(dpop()));
}
void factor_vm::primitive_micros()
void factor_vm::primitive_system_micros()
{
box_unsigned_8(current_micros());
box_unsigned_8(system_micros());
}
void factor_vm::primitive_nanos()
void factor_vm::primitive_nano_count()
{
box_unsigned_8(current_nanos());
box_unsigned_8(nano_count());
}
void factor_vm::primitive_sleep()

View File

@ -117,8 +117,8 @@ struct factor_vm
// run
void primitive_exit();
void primitive_micros();
void primitive_nanos();
void primitive_system_micros();
void primitive_nano_count();
void primitive_sleep();
void primitive_set_slot();