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