Skip to content

Commit c7cc6b3

Browse files
authored
Add support for Stats (#97)
1 parent d93e7a9 commit c7cc6b3

File tree

8 files changed

+112
-8
lines changed

8 files changed

+112
-8
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ TileDB-CSharp
22

33
# Build
44
## Download or build tiledb core library
5-
```
5+
6+
```bash
67
cd cpp
78
mkdir build && cd build
89
cmake ..
910
cmake --build . --target install
1011
```
1112
## Build TileDB.CSharp
12-
```
13+
14+
```bash
1315
cd sources/TileDB.CSharp
1416
dotnet build /p:Platform=x64 -c Release
1517
```
1618
## Test TileDB.CSharp
17-
```
19+
20+
```bash
1821
cd tests/TileDB.CSharp.Test
1922
dotnet test -c Release
2023
```

examples/TileDB.CSharp.Example/TileDB.CSharp.Example.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RollForward>Major</RollForward>
77
<RootNamespace>TileDB.CSharp.Examples</RootNamespace>
88
<TargetFramework>net5.0</TargetFramework>
9-
<Version>5.2.1</Version>
9+
<Version>5.2.2</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>

examples/bindings/quickstart_sparse_string/quickstart_sparse_string.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<OutputType>Exe</OutputType>
66
<RollForward>Major</RollForward>
77
<TargetFramework>net5.0</TargetFramework>
8-
<Version>5.2.1</Version>
8+
<Version>5.2.2</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>

sources/TileDB.CSharp/Stats.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using TileDB.Interop;
4+
5+
namespace TileDB.CSharp
6+
{
7+
public static unsafe class Stats
8+
{
9+
private static readonly Context _ctx;
10+
static Stats()
11+
{
12+
_ctx = Context.GetDefault();
13+
}
14+
15+
/// <summary>
16+
/// Enable statistic gathering
17+
/// </summary>
18+
public static void Enable() => _ctx.handle_error(Methods.tiledb_stats_enable());
19+
20+
/// <summary>
21+
/// Disable statistic gathering
22+
/// </summary>
23+
public static void Disable() => _ctx.handle_error(Methods.tiledb_stats_disable());
24+
25+
/// <summary>
26+
/// Reset all statistics previously gathered
27+
/// </summary>
28+
public static void Reset() => _ctx.handle_error(Methods.tiledb_stats_reset());
29+
30+
/// <summary>
31+
/// Dump TileDB statistics to stdout
32+
/// </summary>
33+
public static void Dump() => Console.WriteLine(Get());
34+
35+
/// <summary>
36+
/// Dump TileDB statistics to a file
37+
/// </summary>
38+
/// <param name="filePath">Path to file to dump statistics</param>
39+
public static void Dump(string filePath) => System.IO.File.WriteAllText(filePath, Get());
40+
41+
/// <summary>
42+
/// Get TileDB statistics as string
43+
/// </summary>
44+
/// <returns>string object containing dumped TileDB statistics</returns>
45+
public static string Get()
46+
{
47+
var ms = (sbyte**)Marshal.StringToHGlobalAnsi("");
48+
_ctx.handle_error(Methods.tiledb_stats_dump_str(ms));
49+
string stats = new(*ms);
50+
_ctx.handle_error(Methods.tiledb_stats_free_str(ms));
51+
Marshal.FreeHGlobal((IntPtr)ms);
52+
return stats;
53+
}
54+
}
55+
}

sources/TileDB.CSharp/TileDB.CSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RollForward>Major</RollForward>
77
<RootNamespace>TileDB.CSharp</RootNamespace>
88
<TargetFramework>net5.0</TargetFramework>
9-
<Version>5.2.1</Version>
9+
<Version>5.2.2</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>

sources/TileDB.CSharp/TileDB.CSharp.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>TileDB.CSharp</id>
5-
<version>5.2.1</version>
5+
<version>5.2.2</version>
66
<title>$title$</title>
77
<authors>TileDB Inc</authors>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>

sources/TileDB.Interop/TileDB.Interop.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<RollForward>Major</RollForward>
66
<TargetFramework>net5.0</TargetFramework>
7-
<Version>5.2.1</Version>
7+
<Version>5.2.2</Version>
88
</PropertyGroup>
99
</Project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace TileDB.CSharp.Test
4+
{
5+
[TestClass]
6+
public class StatsTest
7+
{
8+
private static readonly string ArrayUri = TestUtil.GetTempPath("test-stats");
9+
10+
[TestMethod]
11+
public void TestStats()
12+
{
13+
Stats.Enable();
14+
15+
var ctx = Context.GetDefault();
16+
var row = Dimension.Create(ctx, "rows", 1, 4, 2);
17+
var col = Dimension.Create(ctx, "cols", 1, 4, 2);
18+
var domain = new Domain(ctx);
19+
domain.AddDimensions(row, col);
20+
var schema = new ArraySchema(ctx, ArrayType.TILEDB_DENSE);
21+
schema.SetDomain(domain);
22+
schema.AddAttribute(new Attribute(ctx, "a1", DataType.TILEDB_INT32));
23+
schema.Check();
24+
TestUtil.CreateArray(ctx, ArrayUri, schema);
25+
26+
var array = new Array(ctx, ArrayUri);
27+
array.Open(QueryType.TILEDB_WRITE);
28+
var query = new Query(ctx, array);
29+
query.SetLayout(LayoutType.TILEDB_ROW_MAJOR);
30+
query.SetSubarray(new[] { 1, 4, 1, 4 });
31+
query.SetDataBuffer("a1", new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
32+
query.Submit();
33+
Assert.AreEqual(query.Status(), QueryStatus.TILEDB_COMPLETED);
34+
35+
string? stats = null;
36+
stats = Stats.Get();
37+
Assert.IsNotNull(stats);
38+
var filePath = TestUtil.GetTempPath("test-stats-dump");
39+
Stats.Dump(filePath);
40+
Assert.IsTrue(System.IO.File.Exists(filePath));
41+
42+
Stats.Dump();
43+
}
44+
45+
}
46+
}

0 commit comments

Comments
 (0)