The sampling thread can be invoked from within the development environment. Sampling gives approximate results in less time. Let’s verify this claim. So we will first run the collector without sampling. We will switch on the trace mode and run the tested program. As a result all port events will be recorded indiscriminately of the time frame. The following sequence runs the collector without sampling:
?- trace. ?- time(test), time(test). test in 1816.0 ms test in 1132.8 ms ?- nodebug.
We have run the test program twice to show the warm-up effect. The following sequence shows the relative port statistics. Since we have run the collector without sampling, the relative port statistics will be exact:
?- show. Pred Call Exit Redo Fail member / 2 26.3 % 25.9 % 25.8 % 26.2 % nextTo / 3 5.7 % 21.6 % 21.6 % 5.7 % rightTo / 3 68.1 % 52.5 % 52.6 % 68.1 %
Next we will run the collector with sampling. This time we will only switch on the debug mode. Before running the test program we will start the sampler. As a result port events will be only recorded during the trace intervals. The following sequence runs the collector with sampling:
?- reset. ?- ['jekdev/study/ports/thread.p']. ?- debug. ?- start_sampler. ?- time(test), time(test). test in 257.3 ms test in 207.0 ms ?- stop_sampler. ?- nodebug.
The collector with sampling does need less time than the collector without sampling. In the present case we see that only around a 1/4 of the time is needed. The following sequence shows the relative port statistics. Since we have run the collector with sampling, the relative port statistics will be approximations:
?- show. Pred Call Exit Redo Fail member / 2 26.2 % 24.3 % 24.0 % 25.8 % nextTo / 3 5.6 % 21.9 % 22.1 % 5.7 % rightTo / 3 68.2 % 53.8 % 54.0 % 68.5 %
Comparing the approximations with the exact values shows a difference in the range of 0.1% to 1.8%. By means of reporting the absolute values and with the help of a little math we could even extrapolate the exact values from the approximate values and a debug only run. But this would require more stable time measurements and thus possibly averaging the measurement over multiple runs. This would obviate our goal of a fast method.