]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/profiler/sampling/sampling-tests.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / tools / profiler / sampling / sampling-tests.factor
1 USING: assocs byte-arrays calendar kernel kernel.private math memory
2 namespaces parser random sequences threads tools.profiler.sampling
3 tools.profiler.sampling.private tools.test ;
4 IN: tools.profiler.sampling.tests
5
6 ! collect-tops: top is the last element in the array
7 { 5 } [
8     { { 1 2 3 4 5 6 { 3 4 5 } } } 1 2 collect-tops
9     keys first
10 ] unit-test
11
12 ! Make sure the profiler doesn't blow up the VM
13 TUPLE: boom ;
14 { } [ 10 [ [ ] profile ] times ] unit-test
15 [ 10 [ [ boom new throw ] profile ] times ] [ boom? ] must-fail-with
16 { } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times gc ] profile ] times ] unit-test
17 { } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times compact-gc ] profile ] times ] unit-test
18 { } [ 2 [ [ 1 seconds sleep ] profile ] times ] unit-test
19
20 { } [ [ 300,000 <iota> [ sq sq sq ] map drop ] profile flat profile. ] unit-test
21 { } [ [ 300,000 <iota> [ sq sq sq ] map drop ] profile top-down profile. ] unit-test
22
23 f raw-profile-data set-global
24 gc
25
26 { t t } [
27     ! Seed the samples data
28     [ "resource:basis/tools/memory/memory.factor" run-file ] profile
29     (get-samples) length 0 >
30     OBJ-SAMPLE-CALLSTACKS special-object first 0 >
31 ] unit-test
32
33 { t } [
34     ! On x86.64, [ ] profile doesn't generate any samples at all
35     ! because it runs so quickly. On x86.32, one spurious sample is
36     ! sometimes generated for some unknown reason.
37     gc [ ] profile (get-samples) length 1 <=
38 ] unit-test