Skip to content

Commit 486985e

Browse files
committed
handle in-memory arrays
1 parent 91df8cb commit 486985e

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

+util/nwbTree.m

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ function nwbTree(nwbfile)
2828
elseif isa(new_node, 'char')
2929
uitreenode(tree_node, 'Text', [p{1} ': ' new_node]);
3030
elseif isnumeric(new_node)
31-
uitreenode(tree_node, 'Text', [p{1} ': ' num2str(new_node)]);
31+
if numel(new_node) == 1
32+
uitreenode(tree_node, 'Text', [p{1} ': ' num2str(new_node)]);
33+
else
34+
data_node = uitreenode(tree_node, 'Text', p{1});
35+
uitreenode(data_node, 'Text', ['shape: [' num2str(size(new_node)) ']'])
36+
uitreenode(data_node, 'Text', ['class: ' class(new_node)])
37+
end
3238
else
3339
uitreenode(tree_node, 'Text', p{1});
3440
end
@@ -42,4 +48,63 @@ function nwbTree(nwbfile)
4248
end
4349

4450

51+
function [ bytes ] = getMemSize( variable, sizelimit, name, indent )
52+
if nargin < 2
53+
sizelimit = -1;
54+
end
55+
if nargin < 3
56+
name = 'variable';
57+
end
58+
if nargin < 4
59+
indent = '';
60+
end
61+
62+
strsize = 30;
63+
64+
props = properties(variable);
65+
if size(props, 1) < 1
66+
67+
bytes = whos(varname(variable));
68+
bytes = bytes.bytes;
69+
70+
if bytes > sizelimit
71+
if bytes < 1024
72+
fprintf('%s%s: %i\n', indent, pad(name, strsize - length(indent)), bytes);
73+
elseif bytes < 2^20
74+
fprintf('%s%s: %i Kb\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^10));
75+
elseif bytes < 2^30
76+
fprintf('%s%s: %i Mb\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^20));
77+
else
78+
fprintf('%s%s: %i Gb [!]\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^30));
79+
end
80+
end
81+
else
82+
83+
fprintf('\n%s[%s] \n\n', indent, name);
84+
bytes = 0;
85+
for ii=1:length(props)
86+
currentProperty = getfield(variable, char(props(ii)));
87+
pp = props(ii);
88+
bytes = bytes + getMemSize(currentProperty, sizelimit, pp{1}, [indent, ' ']);
89+
end
90+
91+
if length(indent) == 0
92+
fprintf('\n');
93+
name = 'TOTAL';
94+
if bytes < 1024
95+
fprintf('%s%s: %i\n', indent, pad(name, strsize - length(indent)), bytes);
96+
elseif bytes < 2^20
97+
fprintf('%s%s: %i Kb\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^10));
98+
elseif bytes < 2^30
99+
fprintf('%s%s: %i Mb\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^20));
100+
else
101+
fprintf('%s%s: %i Gb [!]\n', indent, pad(name, strsize - length(indent)), round(bytes / 2^30));
102+
end
103+
end
104+
105+
end
106+
107+
end
108+
109+
45110
end

0 commit comments

Comments
 (0)