File: OMLBasicTest.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (102 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function OMLBasicTest(screenid, querystresstest)
% OMLBasicTest([screenid=max][, querystresstest = 0]) - Test basic correctness of OpenML timestamping.
%
% Performs a sequence of 300 flips, acquires timestamps of
% Flip completion according to OML_sync_control timestamping,
% as well as a post-swap GetSecs timestamp and a timestamp of
% the last vblank. If OpenML timestamping works correctly, then
% all three timestamps should be almost identical, ie., the vblank
% and flip timestamps should be identical, the GetSecs timestamp
% only minimally later than the flip timestamp, depending on
% system scheduling noise and load.
%
% If the timestamps (minus a few outliers) disagree, then
% something is likely broken in OpenML flip timestamping.
%
% if the optional parameter 'querystresstest' is set to a
% value > 0 then a stress test of vblank count and timestamp
% queries is run for 'querystresstest' seconds and potential
% trouble is reported.
%

global t;
global drt;
global dsw;

AssertOpenGL;

Screen('Preference','VBLTimestampingmode', 4);

if nargin < 1 || isempty(screenid)
    screenid=max(Screen('Screens'));
end

if nargin < 2 || isempty(querystresstest)
    querystresstest = 0;
end

win = Screen('OpenWindow', screenid);
ifi = Screen('GetFlipInterval', win);

GetSecs;
WaitSecs(0);
Priority(MaxPriority(win));

if querystresstest > 0
    oldLastVBLTime = nan;
    tEnd = GetSecs + querystresstest;
    while GetSecs < tEnd
        winfo = Screen('GetWindowInfo', win);
        if winfo.LastVBLTime < oldLastVBLTime - 0.000050
            fprintf('QueryStressTest: New ts %f < old ts %f --> delta %f msecs!!\n', winfo.LastVBLTime, oldLastVBLTime, 1000 * (winfo.LastVBLTime - oldLastVBLTime));
        end

        oldLastVBLTime = winfo.LastVBLTime;
    end
end

n=300;
t=zeros(3,n);

for i=1:n
    t(1,i) = Screen('Flip', win);
    t(3,i) = GetSecs;
    winfo = Screen('GetWindowInfo', win);
    t(2,i) = winfo.LastVBLTime;
end

Priority(0);
sca;

drt = 1000 * (t(3,:) - t(1,:));
dsw = 1000 * (t(2,:) - t(1,:));

mrt = max(abs(drt));
msw = max(abs(dsw));

fprintf('\n\n');
fprintf('Maximum deviation between GetSecs and stimulus onset timestamp: %f msecs. --> ', mrt);
if mrt < ifi * 1000 / 2
    fprintf('Decent.\n');
else
    fprintf('Troublesome!\n');
end

fprintf('Maximum deviation between VBlank and stimulus onset timestamp: %f msecs. --> ', msw);
if msw < ifi * 1000 / 2
    fprintf('Decent.\n');
else
    fprintf('Troublesome!\n');
end

fprintf('See plots for details...\n');

close all;
plot(drt);
title('GetSecs - swapcomplete [msecs]:');

figure;
plot(dsw);
title('vblank - swapcomplete [msecs]:');

return;