File size: 2,247 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from numpy.testing import assert_array_equal

import tiledb

from .common import (
    DiskTestCase,
    assert_captured,
)


class StatsTest(DiskTestCase):
    def test_stats(self, capfd):
        tiledb.stats_enable()
        tiledb.stats_reset()
        tiledb.stats_disable()

        tiledb.stats_enable()

        path = self.path("test_stats")

        with tiledb.from_numpy(path, np.arange(10)) as T:
            pass

        # basic output check for read stats
        tiledb.stats_reset()
        with tiledb.open(path) as T:
            tiledb.stats_enable()
            assert_array_equal(T, np.arange(10))

            # test stdout version
            tiledb.stats_dump()
            assert_captured(capfd, "TileDB Embedded Version:")

            # test string version
            stats_v = tiledb.stats_dump(print_out=False)
            if tiledb.libtiledb.version() < (2, 3):
                self.assertTrue("==== READ ====" in stats_v)
            else:
                self.assertTrue('"timers": {' in stats_v)
            self.assertTrue("==== Python Stats ====" in stats_v)

            stats_quiet = tiledb.stats_dump(print_out=False, verbose=False)
            if tiledb.libtiledb.version() < (2, 3):
                self.assertTrue("Time to load array schema" not in stats_quiet)

                # TODO seems to be a regression, no JSON
                stats_json = tiledb.stats_dump(json=True)
                self.assertTrue(isinstance(stats_json, dict))
                self.assertTrue("CONSOLIDATE_COPY_ARRAY" in stats_json)
            else:
                self.assertTrue("==== READ ====" in stats_quiet)

    def test_stats_include_python_json(self):
        tiledb.stats_enable()

        path = self.path("test_stats")

        with tiledb.from_numpy(path, np.arange(10)) as T:
            pass

        tiledb.stats_reset()
        with tiledb.open(path) as T:
            tiledb.stats_enable()
            assert_array_equal(T, np.arange(10))
            json_stats = tiledb.stats_dump(print_out=False, json=True)
            assert isinstance(json_stats, str)
            assert "python" in json_stats
            assert "timers" in json_stats
            assert "counters" in json_stats