quasardb 3.14.1.dev5__cp312-cp312-win32.whl → 3.14.2.dev0__cp312-cp312-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of quasardb might be problematic. Click here for more details.

Files changed (56) hide show
  1. quasardb/CMakeLists.txt +5 -1
  2. quasardb/__init__.py +1 -1
  3. quasardb/batch_column.hpp +1 -1
  4. quasardb/batch_inserter.hpp +1 -1
  5. quasardb/blob.hpp +1 -1
  6. quasardb/cluster.cpp +89 -0
  7. quasardb/cluster.hpp +38 -51
  8. quasardb/continuous.hpp +1 -1
  9. quasardb/convert/array.hpp +1 -1
  10. quasardb/convert/point.hpp +1 -1
  11. quasardb/convert/range.hpp +1 -1
  12. quasardb/convert/value.hpp +1 -1
  13. quasardb/convert.hpp +1 -1
  14. quasardb/detail/qdb_resource.hpp +11 -1
  15. quasardb/detail/ts_column.hpp +1 -1
  16. quasardb/direct_blob.hpp +1 -1
  17. quasardb/direct_handle.hpp +1 -1
  18. quasardb/direct_integer.hpp +1 -1
  19. quasardb/double.hpp +1 -1
  20. quasardb/entry.hpp +1 -1
  21. quasardb/error.hpp +1 -1
  22. quasardb/handle.cpp +29 -0
  23. quasardb/handle.hpp +3 -15
  24. quasardb/integer.hpp +1 -1
  25. quasardb/logger.cpp +3 -0
  26. quasardb/logger.hpp +1 -1
  27. quasardb/masked_array.hpp +1 -1
  28. quasardb/metrics.cpp +103 -0
  29. quasardb/metrics.hpp +112 -0
  30. quasardb/module.cpp +2 -0
  31. quasardb/node.hpp +1 -1
  32. quasardb/numpy.hpp +1 -1
  33. quasardb/options.hpp +1 -1
  34. quasardb/pandas/__init__.py +1 -1
  35. quasardb/perf.hpp +1 -1
  36. quasardb/pytypes.hpp +1 -1
  37. quasardb/qdb_api.dll +0 -0
  38. quasardb/quasardb.cp312-win32.pyd +0 -0
  39. quasardb/query.cpp +14 -3
  40. quasardb/query.hpp +1 -1
  41. quasardb/reader/ts_row.hpp +1 -1
  42. quasardb/reader/ts_value.hpp +1 -1
  43. quasardb/string.hpp +1 -1
  44. quasardb/table.cpp +34 -0
  45. quasardb/table.hpp +64 -32
  46. quasardb/table_reader.hpp +1 -1
  47. quasardb/tag.hpp +1 -1
  48. quasardb/timestamp.hpp +1 -1
  49. quasardb/utils.hpp +1 -1
  50. quasardb/writer.cpp +4 -0
  51. quasardb/writer.hpp +1 -1
  52. {quasardb-3.14.1.dev5.dist-info → quasardb-3.14.2.dev0.dist-info}/LICENSE.md +1 -1
  53. {quasardb-3.14.1.dev5.dist-info → quasardb-3.14.2.dev0.dist-info}/METADATA +1 -1
  54. {quasardb-3.14.1.dev5.dist-info → quasardb-3.14.2.dev0.dist-info}/RECORD +56 -52
  55. {quasardb-3.14.1.dev5.dist-info → quasardb-3.14.2.dev0.dist-info}/WHEEL +0 -0
  56. {quasardb-3.14.1.dev5.dist-info → quasardb-3.14.2.dev0.dist-info}/top_level.txt +0 -0
quasardb/CMakeLists.txt CHANGED
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9.4)
2
2
  project(quasardb)
3
3
  set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
4
4
  set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
5
- set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
5
+ set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
6
6
  set(CMAKE_VERBOSE_MAKEFILE FALSE)
7
7
 
8
8
  include(CheckIPOSupported)
@@ -325,6 +325,7 @@ set(QDB_FILES
325
325
  batch_inserter.hpp
326
326
  blob.hpp
327
327
  cluster.hpp
328
+ cluster.cpp
328
329
  concepts.hpp
329
330
  continuous.cpp
330
331
  continuous.hpp
@@ -333,9 +334,12 @@ set(QDB_FILES
333
334
  error.hpp
334
335
  entry.hpp
335
336
  handle.hpp
337
+ handle.cpp
336
338
  logger.hpp
337
339
  logger.cpp
338
340
  masked_array.hpp
341
+ metrics.hpp
342
+ metrics.cpp
339
343
  module.hpp
340
344
  module.cpp
341
345
  node.hpp
quasardb/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # pylint: disable=C0103,C0111,C0302,R0903
2
2
 
3
- # Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
3
+ # Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
quasardb/batch_column.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/blob.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/cluster.cpp ADDED
@@ -0,0 +1,89 @@
1
+ #include "cluster.hpp"
2
+ #include "metrics.hpp"
3
+ #include <chrono>
4
+ #include <thread>
5
+
6
+ namespace qdb
7
+ {
8
+
9
+ cluster::cluster(const std::string & uri,
10
+ const std::string & user_name,
11
+ const std::string & user_private_key,
12
+ const std::string & cluster_public_key,
13
+ const std::string & user_security_file,
14
+ const std::string & cluster_public_key_file,
15
+ std::chrono::milliseconds timeout,
16
+ bool do_version_check)
17
+ : _uri{uri}
18
+ , _handle{make_handle_ptr()}
19
+ , _json_loads{pybind11::module::import("json").attr("loads")}
20
+ , _logger("quasardb.cluster")
21
+ {
22
+ if (do_version_check == true)
23
+ {
24
+ _logger.warn(
25
+ "do_version_check parameter has been deprecated and a no-op. It will be removed from a "
26
+ "future release");
27
+ }
28
+
29
+ options().apply_credentials(user_name, user_private_key, cluster_public_key, //
30
+ user_security_file, cluster_public_key_file);
31
+
32
+ options().set_timeout(timeout);
33
+
34
+ // HACKS(leon): we need to ensure there is always one callback active
35
+ // for qdb. Callbacks can be lost when the last active session
36
+ // gets closed. As such, the most pragmatic place to 'check'
37
+ // for this callback is when establishing a new connection.
38
+ qdb::native::swap_callback();
39
+
40
+ _logger.info("Connecting to cluster %s", _uri);
41
+ _handle->connect(_uri);
42
+ }
43
+
44
+ void cluster::close()
45
+ {
46
+ _logger.info("Closing connection to cluster");
47
+
48
+ try
49
+ {
50
+ if (is_open() == true) [[likely]]
51
+ {
52
+ _handle->close();
53
+ }
54
+ }
55
+ catch (qdb::invalid_handle_exception const & e)
56
+ {
57
+ // This can happen if, for example, we call close() after an error occured; in those
58
+ // circumstances, we fully expect the connection to already be invalid, and we should
59
+ // not care if this specific exception is raised.
60
+ _logger.warn("Connection already closed");
61
+ }
62
+
63
+ _handle.reset();
64
+
65
+ assert(is_open() == false);
66
+ }
67
+
68
+ void cluster::wait_for_compaction()
69
+ {
70
+
71
+ // We define this function in the .cpp file so we can avoid including chrono and thread
72
+ // in the header file.
73
+
74
+ using namespace std::chrono_literals;
75
+
76
+ for (;;)
77
+ {
78
+ std::uint64_t progress = compact_progress();
79
+
80
+ if (progress == 0) [[unlikely]]
81
+ {
82
+ break;
83
+ }
84
+
85
+ std::this_thread::sleep_for(100ms);
86
+ }
87
+ }
88
+
89
+ }; // namespace qdb
quasardb/cluster.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -72,58 +72,10 @@ public:
72
72
  const std::string & user_security_file = {},
73
73
  const std::string & cluster_public_key_file = {},
74
74
  std::chrono::milliseconds timeout = std::chrono::minutes{1},
75
- bool do_version_check = false)
76
- : _uri{uri}
77
- , _handle{make_handle_ptr()}
78
- , _json_loads{pybind11::module::import("json").attr("loads")}
79
- , _logger("quasardb.cluster")
80
- {
81
- if (do_version_check == true)
82
- {
83
- _logger.warn(
84
- "do_version_check parameter has been deprecated and a no-op. It will be removed from a "
85
- "future release");
86
- }
87
-
88
- options().apply_credentials(user_name, user_private_key, cluster_public_key, //
89
- user_security_file, cluster_public_key_file);
90
-
91
- options().set_timeout(timeout);
92
-
93
- // HACKS(leon): we need to ensure there is always one callback active
94
- // for qdb. Callbacks can be lost when the last active session
95
- // gets closed. As such, the most pragmatic place to 'check'
96
- // for this callback is when establishing a new connection.
97
- qdb::native::swap_callback();
98
-
99
- _logger.info("Connecting to cluster %s", _uri);
100
- _handle->connect(_uri);
101
- }
75
+ bool do_version_check = false);
102
76
 
103
77
  public:
104
- void close()
105
- {
106
- _logger.info("Closing connection to cluster");
107
-
108
- try
109
- {
110
- if (is_open() == true) [[likely]]
111
- {
112
- _handle->close();
113
- }
114
- }
115
- catch (qdb::invalid_handle_exception const & e)
116
- {
117
- // This can happen if, for example, we call close() after an error occured; in those
118
- // circumstances, we fully expect the connection to already be invalid, and we should
119
- // not care if this specific exception is raised.
120
- _logger.warn("Connection already closed");
121
- }
122
-
123
- _handle.reset();
124
-
125
- assert(is_open() == false);
126
- }
78
+ void close();
127
79
 
128
80
  bool is_open() const
129
81
  {
@@ -463,6 +415,37 @@ public:
463
415
  static_cast<int>(timeout_ms.count())));
464
416
  }
465
417
 
418
+ void compact_full()
419
+ {
420
+ check_open();
421
+
422
+ qdb_compact_params_t params{};
423
+ params.options = qdb_compact_full;
424
+
425
+ qdb::qdb_throw_if_error(*_handle, qdb_cluster_compact(*_handle, &params));
426
+ }
427
+
428
+ // Returns 0 when finished / no compaction running
429
+ std::uint64_t compact_progress()
430
+ {
431
+ check_open();
432
+
433
+ std::uint64_t progress;
434
+
435
+ qdb::qdb_throw_if_error(*_handle, qdb_cluster_get_compact_progress(*_handle, &progress));
436
+
437
+ return progress;
438
+ }
439
+
440
+ void compact_abort()
441
+ {
442
+ check_open();
443
+
444
+ qdb::qdb_throw_if_error(*_handle, qdb_cluster_abort_compact(*_handle));
445
+ }
446
+
447
+ void wait_for_compaction();
448
+
466
449
  public:
467
450
  std::vector<std::string> endpoints()
468
451
  {
@@ -558,6 +541,10 @@ static inline void register_cluster(Module & m)
558
541
  .def("purge_all", &qdb::cluster::purge_all) //
559
542
  .def("trim_all", &qdb::cluster::trim_all) //
560
543
  .def("purge_cache", &qdb::cluster::purge_cache) //
544
+ .def("compact_full", &qdb::cluster::compact_full) //
545
+ .def("compact_progress", &qdb::cluster::compact_progress) //
546
+ .def("compact_abort", &qdb::cluster::compact_abort) //
547
+ .def("wait_for_compaction", &qdb::cluster::wait_for_compaction) //
561
548
  .def("endpoints", &qdb::cluster::endpoints); //
562
549
  }
563
550
 
quasardb/continuous.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/convert.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -104,6 +104,16 @@ public:
104
104
  return *p_;
105
105
  }
106
106
 
107
+ ValueType * operator->()
108
+ {
109
+ return p_;
110
+ }
111
+
112
+ constexpr ValueType const * operator->() const
113
+ {
114
+ return p_;
115
+ }
116
+
107
117
  constexpr ValueType const & operator*() const
108
118
  {
109
119
  return *p_;
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/direct_blob.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/double.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/entry.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/error.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/handle.cpp ADDED
@@ -0,0 +1,29 @@
1
+ #include "handle.hpp"
2
+ #include "metrics.hpp"
3
+
4
+ namespace qdb
5
+ {
6
+
7
+ void handle::connect(const std::string & uri)
8
+ {
9
+ qdb_error_t err;
10
+ {
11
+ metrics::scoped_capture{"qdb_connect"};
12
+ err = qdb_connect(handle_, uri.c_str());
13
+ }
14
+ qdb::qdb_throw_if_error(handle_, err);
15
+ }
16
+
17
+ void handle::close()
18
+ {
19
+ if (handle_ != nullptr)
20
+ {
21
+ metrics::scoped_capture{"qdb_close"};
22
+ qdb_close(handle_);
23
+ handle_ = nullptr;
24
+ }
25
+
26
+ assert(handle_ == nullptr);
27
+ }
28
+
29
+ }; // namespace qdb
quasardb/handle.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
@@ -54,26 +54,14 @@ public:
54
54
  close();
55
55
  }
56
56
 
57
- void connect(const std::string & uri)
58
- {
59
- qdb::qdb_throw_if_error(handle_, qdb_connect(handle_, uri.c_str()));
60
- }
57
+ void connect(const std::string & uri);
61
58
 
62
59
  operator qdb_handle_t() const noexcept
63
60
  {
64
61
  return handle_;
65
62
  }
66
63
 
67
- void close()
68
- {
69
- if (handle_ != nullptr)
70
- {
71
- qdb_close(handle_);
72
- handle_ = nullptr;
73
- }
74
-
75
- assert(handle_ == nullptr);
76
- }
64
+ void close();
77
65
 
78
66
  constexpr inline bool is_open() const
79
67
  {
quasardb/integer.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/logger.cpp CHANGED
@@ -11,6 +11,8 @@ void qdb::native::swap_callback()
11
11
  {
12
12
  // Potential race condition avoidance!
13
13
  std::lock_guard<std::mutex> guard(_buffer_lock);
14
+
15
+ #ifndef NDEBUG
14
16
  qdb_error_t error;
15
17
 
16
18
  error = qdb_log_remove_callback(local_callback_id);
@@ -26,6 +28,7 @@ void qdb::native::swap_callback()
26
28
  // fprintf(stderr, "unable to add new callback: %s (%#x)\n", qdb_error(error), error);
27
29
  // fflush(stderr);
28
30
  }
31
+ #endif
29
32
 
30
33
  _logger = qdb::logger("quasardb.native");
31
34
  }
quasardb/logger.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/masked_array.hpp CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Official Python API
4
4
  *
5
- * Copyright (c) 2009-2023, quasardb SAS. All rights reserved.
5
+ * Copyright (c) 2009-2024, quasardb SAS. All rights reserved.
6
6
  * All rights reserved.
7
7
  *
8
8
  * Redistribution and use in source and binary forms, with or without
quasardb/metrics.cpp ADDED
@@ -0,0 +1,103 @@
1
+ #include "metrics.hpp"
2
+ #include <mutex>
3
+
4
+ namespace qdb
5
+ {
6
+
7
+ static metrics_container_t metrics_totals_ = metrics_container_t{};
8
+ static std::mutex metrics_lock_ = std::mutex{};
9
+
10
+ metrics::scoped_capture::~scoped_capture()
11
+ {
12
+ using std::chrono::nanoseconds;
13
+
14
+ time_point_t stop = clock_t::now();
15
+
16
+ auto duration = std::chrono::duration_cast<nanoseconds>(stop - start_);
17
+
18
+ metrics::record(test_id_, duration.count());
19
+ }
20
+
21
+ metrics::measure::measure()
22
+ : start_{metrics::totals()}
23
+ {}
24
+
25
+ metrics_container_t metrics::measure::get() const
26
+ {
27
+ metrics_container_t cur = metrics::totals();
28
+
29
+ metrics_container_t ret{};
30
+
31
+ for (auto i : cur)
32
+ {
33
+ assert(ret.find(i.first) == ret.end());
34
+
35
+ metrics_container_t::const_iterator prev = start_.find(i.first);
36
+
37
+ if (prev == start_.end())
38
+ {
39
+ // Previously, metric didn't exist yet, as such it's entirely new
40
+ // and all accumulated time was within the scope.
41
+ ret.emplace(i.first, i.second);
42
+ }
43
+ else if (i.second > prev->second)
44
+ {
45
+ // Accumulated time actually increased, record difference
46
+ ret.emplace(i.first, i.second - prev->second);
47
+ }
48
+ else
49
+ {
50
+ // Integrity check: we can only increase totals over time, never decrease
51
+ assert(i.second == prev->second);
52
+ }
53
+ };
54
+
55
+ return ret;
56
+ };
57
+
58
+ /* static */ void metrics::record(std::string const & test_id, std::uint64_t nsec)
59
+ {
60
+ std::lock_guard<std::mutex> guard(metrics_lock_);
61
+
62
+ metrics_container_t::iterator pos = metrics_totals_.lower_bound(test_id);
63
+
64
+ if (pos == metrics_totals_.end() || pos->first != test_id) [[unlikely]]
65
+ {
66
+ pos = metrics_totals_.emplace_hint(pos, test_id, 0);
67
+
68
+ assert(pos->second == 0);
69
+ }
70
+
71
+ assert(pos->first == test_id);
72
+ pos->second += nsec;
73
+ }
74
+
75
+ /* static */ metrics_container_t metrics::totals()
76
+ {
77
+ std::lock_guard<std::mutex> guard(metrics_lock_);
78
+ return metrics_totals_;
79
+ }
80
+
81
+ /* static */ void metrics::clear()
82
+ {
83
+ std::lock_guard<std::mutex> guard(metrics_lock_);
84
+ metrics_totals_.clear();
85
+ }
86
+
87
+ void register_metrics(py::module_ & m)
88
+ {
89
+
90
+ py::module_ metrics_module =
91
+ m.def_submodule("metrics", "Keep track of low-level performance metrics")
92
+ .def("totals", &qdb::metrics::totals)
93
+ .def("clear", &qdb::metrics::clear);
94
+
95
+ auto metrics_measure = py::class_<qdb::metrics::measure>(
96
+ metrics_module, "Measure", "Track all metrics within a block of code")
97
+ .def(py::init())
98
+ .def("__enter__", &qdb::metrics::measure::enter)
99
+ .def("__exit__", &qdb::metrics::measure::exit)
100
+ .def("get", &qdb::metrics::measure::get);
101
+ };
102
+
103
+ }; // namespace qdb