forked from yihuai-gao/CommandCenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemorytest.m
129 lines (98 loc) · 3.41 KB
/
memorytest.m
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function memorytest(core)
seqmode = true; %false;
mem = NaN(1, 200);
f = figure;
a = subplot(2,1,1);
yyaxis left
p1 = plot(a, 1:length(mem), mem);
ylabel('MATLAB Memory Use')
yyaxis right
hold on
p3a = plot(a, 1:(length(mem)-1), mem(2:end));
% p3b = plot(a, 1:(length(mem)-1), mem(2:end));
% p3c = plot(a, 1:(length(mem)-1), mem(2:end));
% if seqmode
% legend({'Total Memory', 'Total Delta', 'Delta due to starting continuous', 'Delta due to getting frame'});
% else
% legend({'Total Memory', 'Total Delta', 'Delta due to snapping', 'Delta due to getting'});
% end
ylabel('Delta MATLAB Memory Use')
a = subplot(2,1,2);
yyaxis left
p2 = plot(a, 1:length(mem), mem);
ylabel('Time For Frame Grab')
yyaxis right
p4 = plot(a, 1:length(mem), mem);
ylabel('Num Frames')
tic
if core.isSequenceRunning()
core.stopSequenceAcquisition();
end
core.setExposure(100);
if seqmode
if ~core.isSequenceRunning()
core.startContinuousSequenceAcquisition(100);
end
end
N = 1;
m1 = memory;
basemem = m1.MemUsedMATLAB;
while isvalid(f) && ~(seqmode && ~core.isSequenceRunning)
if seqmode
if false %mod(N, 20) == 0
if core.isSequenceRunning
core.stopSequenceAcquisition
end
expnew = randi([250,300]);
disp(['Frame ' num2str(N) ': Setting exposure to ' num2str(expnew)]);
core.setExposure(expnew);
if ~core.isSequenceRunning()
core.startContinuousSequenceAcquisition(N); % Use increasing N to deduce if memory correlates.
disp(['Set image buffer to ' num2str(core.getImageBufferSize())]);
end
end
% m2 = memory;
dat = [];
while isempty(dat)
while core.getRemainingImageCount() == 0
% disp('Waiting for image.')
pause(.01);
end
try
dat = core.popNextImage();
catch err
disp(['Fail on frame #' num2str(N)]);
warning(err.message);
end
end
else
core.snapImage();
m2 = memory;
dat = core.getImage();
end
if isvalid(f)
p2.YData = circshift(p2.YData, 1);
p2.YData(1) = toc;
tic
m3 = memory;
p1.YData = circshift(p1.YData, 1);
p1.YData(1) = m3.MemUsedMATLAB - basemem;
p3a.YData = circshift(p3a.YData, 1);
% p3b.YData = circshift(p3b.YData, 1);
% p3c.YData = circshift(p3c.YData, 1);
p3a.YData(1) = m3.MemUsedMATLAB - m1.MemUsedMATLAB;
% p3b.YData(1) = m2.MemUsedMATLAB - m1.MemUsedMATLAB;
% p3c.YData(1) = m3.MemUsedMATLAB - m2.MemUsedMATLAB;
p4.YData = N - (1:length(mem));
m1 = m3;
drawnow;
end
N = N + 1;
end
if ~isvalid(f)
disp('Figure was closed.')
end
if (seqmode && ~core.isSequenceRunning())
disp('Camera aquisition failed.')
end
end