This file is indexed.

/usr/lib/python2.7/dist-packages/tables/tests/check_leaks.py is in python-tables 3.4.2-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# -*- coding: utf-8 -*-

from __future__ import print_function
from __future__ import absolute_import
import os
import time

import tables
from six.moves import range

tref = time.time()
trel = tref


def show_mem(explain):
    global tref, trel

    filename = "/proc/%s/status" % os.getpid()
    with open(filename) as fd:
        for line in fd:
            if line.startswith("VmSize:"):
                vmsize = int(line.split()[1])
            elif line.startswith("VmRSS:"):
                vmrss = int(line.split()[1])
            elif line.startswith("VmData:"):
                vmdata = int(line.split()[1])
            elif line.startswith("VmStk:"):
                vmstk = int(line.split()[1])
            elif line.startswith("VmExe:"):
                vmexe = int(line.split()[1])
            elif line.startswith("VmLib:"):
                vmlib = int(line.split()[1])

    print("\nMemory usage: ******* %s *******" % explain)
    print("VmSize: %7s kB\tVmRSS: %7s kB" % (vmsize, vmrss))
    print("VmData: %7s kB\tVmStk: %7s kB" % (vmdata, vmstk))
    print("VmExe:  %7s kB\tVmLib: %7s kB" % (vmexe, vmlib))
    print("WallClock time:", time.time() - tref, end=' ')
    print("  Delta time:", time.time() - trel)
    trel = time.time()


def write_group(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            fileh.create_group(fileh.root, 'group' + str(child),
                               "child: %d" % child)
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_group(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'group' + str(child))
            assert node is not None
            # flavor = node._v_attrs.CLASS
#         for child in fileh.walk_nodes():
#             pass
        show_mem("After reading metadata. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_array(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            fileh.create_array(fileh.root, 'array' + str(child),
                               [1, 1], "child: %d" % child)
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_array(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'array' + str(child))
            # flavor = node._v_attrs.FLAVOR
            data = node[:]  # Read data
            assert data is not None
        show_mem("After reading data. Iter %s" % i)
#         for child in range(nchildren):
#             node = fileh.get_node(fileh.root, 'array' + str(child))
#             flavor = node._v_attrs.FLAVOR
            # flavor = node._v_attrs
#         for child in fileh.walk_nodes():
#             pass
#         show_mem("After reading metadata. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_carray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            fileh.create_carray(fileh.root, 'array' + str(child),
                                tables.IntAtom(), (2,), "child: %d" % child)
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_carray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'array' + str(child))
            # flavor = node._v_attrs.FLAVOR
            data = node[:]  # Read data
            assert data is not None
            # print("data-->", data)
        show_mem("After reading data. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_earray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            ea = fileh.create_earray(fileh.root, 'array' + str(child),
                                     tables.IntAtom(), shape=(0,),
                                     title="child: %d" % child)
            ea.append([1, 2, 3])
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_earray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'array' + str(child))
            # flavor = node._v_attrs.FLAVOR
            data = node[:]  # Read data
            assert data is not None
            # print("data-->", data)
        show_mem("After reading data. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_vlarray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            vl = fileh.create_vlarray(fileh.root, 'array' + str(child),
                                      tables.IntAtom(), "child: %d" % child)
            vl.append([1, 2, 3])
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_vlarray(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'array' + str(child))
            # flavor = node._v_attrs.FLAVOR
            data = node[:]  # Read data
            assert data is not None
            # print("data-->", data)
        show_mem("After reading data. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_table(filename, nchildren, niter):

    class Record(tables.IsDescription):
        var1 = tables.IntCol(pos=1)
        var2 = tables.StringCol(length=1, pos=2)
        var3 = tables.FloatCol(pos=3)

    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            t = fileh.create_table(fileh.root, 'table' + str(child),
                                   Record, "child: %d" % child)
            t.append([[1, "2", 3.]])
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_table(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'table' + str(child))
            # klass = node._v_attrs.CLASS
            data = node[:]  # Read data
            assert data is not None
            # print("data-->", data)
        show_mem("After reading data. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def write_xtable(filename, nchildren, niter):

    class Record(tables.IsDescription):
        var1 = tables.IntCol(pos=1)
        var2 = tables.StringCol(length=1, pos=2)
        var3 = tables.FloatCol(pos=3)

    for i in range(niter):
        fileh = tables.open_file(filename, mode="w")
        for child in range(nchildren):
            t = fileh.create_table(fileh.root, 'table' + str(child),
                                   Record, "child: %d" % child)
            t.append([[1, "2", 3.]])
            t.cols.var1.create_index()
        show_mem("After creating. Iter %s" % i)
        fileh.close()
        show_mem("After close")


def read_xtable(filename, nchildren, niter):
    for i in range(niter):
        fileh = tables.open_file(filename, mode="r")
        for child in range(nchildren):
            node = fileh.get_node(fileh.root, 'table' + str(child))
            # klass = node._v_attrs.CLASS
            # data = node[:]  # Read data
            # print("data-->", data)
        show_mem("After reading data. Iter %s" % i)
        fileh.close()
        show_mem("After close")
        del node


if __name__ == '__main__':
    import pstats
    import argparse
    import profile as prof

    def _get_parser():
        parser = argparse.ArgumentParser(
            description='Check for PyTables memory leaks.')
        parser.add_argument('-v', '--verbose', action='store_true',
                            help='enable verbose mode')
        parser.add_argument('-p', '--profile', action='store_true',
                            help='profile')
        parser.add_argument('-a', '--array', action='store_true',
                            help='create/read arrays (default)')
        parser.add_argument('-c', '--carray', action='store_true',
                            help='create/read carrays')
        parser.add_argument('-e', '--earray', action='store_true',
                            help='create/read earrays')
        parser.add_argument('-l', '--vlarray', action='store_true',
                            help='create/read vlarrays')
        parser.add_argument('-t', '--table', action='store_true',
                            help='create/read tables')
        parser.add_argument('-x', '--indexed-table', action='store_true',
                            dest='xtable', help='create/read indexed-tables')
        parser.add_argument('-g', '--group', action='store_true',
                            help='create/read groups')
        parser.add_argument('-r', '--read', action='store_true',
                            help='only read test')
        parser.add_argument('-w', '--write', action='store_true',
                            help='only write test')
        parser.add_argument('-n', '--nchildren', type=int, default=1000,
                            help='number of children (%(default)d is the '
                                 'default)')
        parser.add_argument('-i', '--niter', type=int, default=3,
                            help='number of iterations (default: %(default)d)')

        parser.add_argument('filename', help='HDF5 file name')

        return parser

    parser = _get_parser()
    args = parser.parse_args()

    # set 'array' as default value if no ather option has been specified
    for name in ('carray', 'earray', 'vlarray', 'table', 'xtable', 'group'):
        if getattr(args, name):
            break
    else:
        args.array = True

    filename = args.filename
    nchildren = args.nchildren
    niter = args.niter

    if args.array:
        fwrite = 'write_array'
        fread = 'read_array'
    elif args.carray:
        fwrite = 'write_carray'
        fread = 'read_carray'
    elif args.earray:
        fwrite = 'write_earray'
        fread = 'read_earray'
    elif args.vlarray:
        fwrite = 'write_vlarray'
        fread = 'read_vlarray'
    elif args.table:
        fwrite = 'write_table'
        fread = 'read_table'
    elif args.xtable:
        fwrite = 'write_xtable'
        fread = 'read_xtable'
    elif args.group:
        fwrite = 'write_group'
        fread = 'read_group'

    show_mem("Before open")
    if args.write:
        if args.profile:
            prof.run(str(fwrite)+'(filename, nchildren, niter)',
                     'write_file.prof')
            stats = pstats.Stats('write_file.prof')
            stats.strip_dirs()
            stats.sort_stats('time', 'calls')
            if args.verbose:
                stats.print_stats()
            else:
                stats.print_stats(20)
        else:
            eval(fwrite+'(filename, nchildren, niter)')
    if args.read:
        if args.profile:
            prof.run(fread+'(filename, nchildren, niter)', 'read_file.prof')
            stats = pstats.Stats('read_file.prof')
            stats.strip_dirs()
            stats.sort_stats('time', 'calls')
            if args.verbose:
                print('profile -verbose')
                stats.print_stats()
            else:
                stats.print_stats(20)
        else:
            eval(fread+'(filename, nchildren, niter)')