aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-11-13 15:41:49 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-11-13 16:21:50 +0300
commit57c8de46af8f8840637688fe93275b6305b5b137 (patch)
treefd541dc9eb6b2152774249d8e3b05088eaf6fa32
parentb264c6d1c435e288127653ac488a517a397f3eed (diff)
downloadydb-57c8de46af8f8840637688fe93275b6305b5b137.tar.gz
KIKIMR-20084: processes tracing
-rw-r--r--.mapping.json15
-rw-r--r--ydb/core/tx/CMakeLists.darwin-x86_64.txt1
-rw-r--r--ydb/core/tx/CMakeLists.linux-aarch64.txt1
-rw-r--r--ydb/core/tx/CMakeLists.linux-x86_64.txt1
-rw-r--r--ydb/core/tx/CMakeLists.windows-x86_64.txt1
-rw-r--r--ydb/core/tx/tracing/CMakeLists.darwin-x86_64.txt18
-rw-r--r--ydb/core/tx/tracing/CMakeLists.linux-aarch64.txt19
-rw-r--r--ydb/core/tx/tracing/CMakeLists.linux-x86_64.txt19
-rw-r--r--ydb/core/tx/tracing/CMakeLists.txt17
-rw-r--r--ydb/core/tx/tracing/CMakeLists.windows-x86_64.txt18
-rw-r--r--ydb/core/tx/tracing/service/CMakeLists.darwin-x86_64.txt20
-rw-r--r--ydb/core/tx/tracing/service/CMakeLists.linux-aarch64.txt21
-rw-r--r--ydb/core/tx/tracing/service/CMakeLists.linux-x86_64.txt21
-rw-r--r--ydb/core/tx/tracing/service/CMakeLists.txt17
-rw-r--r--ydb/core/tx/tracing/service/CMakeLists.windows-x86_64.txt20
-rw-r--r--ydb/core/tx/tracing/service/actor.cpp5
-rw-r--r--ydb/core/tx/tracing/service/actor.h32
-rw-r--r--ydb/core/tx/tracing/service/global.cpp43
-rw-r--r--ydb/core/tx/tracing/service/global.h27
-rw-r--r--ydb/core/tx/tracing/service/ya.make13
-rw-r--r--ydb/core/tx/tracing/usage/CMakeLists.darwin-x86_64.txt19
-rw-r--r--ydb/core/tx/tracing/usage/CMakeLists.linux-aarch64.txt20
-rw-r--r--ydb/core/tx/tracing/usage/CMakeLists.linux-x86_64.txt20
-rw-r--r--ydb/core/tx/tracing/usage/CMakeLists.txt17
-rw-r--r--ydb/core/tx/tracing/usage/CMakeLists.windows-x86_64.txt19
-rw-r--r--ydb/core/tx/tracing/usage/tracing.cpp159
-rw-r--r--ydb/core/tx/tracing/usage/tracing.h181
-rw-r--r--ydb/core/tx/tracing/usage/ya.make12
-rw-r--r--ydb/core/tx/tracing/ya.make11
-rw-r--r--ydb/core/tx/ya.make1
30 files changed, 788 insertions, 0 deletions
diff --git a/.mapping.json b/.mapping.json
index 5735b225fd..eea167a8b7 100644
--- a/.mapping.json
+++ b/.mapping.json
@@ -6162,6 +6162,21 @@
"ydb/core/tx/time_cast/ut/CMakeLists.linux-x86_64.txt":"",
"ydb/core/tx/time_cast/ut/CMakeLists.txt":"",
"ydb/core/tx/time_cast/ut/CMakeLists.windows-x86_64.txt":"",
+ "ydb/core/tx/tracing/CMakeLists.darwin-x86_64.txt":"",
+ "ydb/core/tx/tracing/CMakeLists.linux-aarch64.txt":"",
+ "ydb/core/tx/tracing/CMakeLists.linux-x86_64.txt":"",
+ "ydb/core/tx/tracing/CMakeLists.txt":"",
+ "ydb/core/tx/tracing/CMakeLists.windows-x86_64.txt":"",
+ "ydb/core/tx/tracing/service/CMakeLists.darwin-x86_64.txt":"",
+ "ydb/core/tx/tracing/service/CMakeLists.linux-aarch64.txt":"",
+ "ydb/core/tx/tracing/service/CMakeLists.linux-x86_64.txt":"",
+ "ydb/core/tx/tracing/service/CMakeLists.txt":"",
+ "ydb/core/tx/tracing/service/CMakeLists.windows-x86_64.txt":"",
+ "ydb/core/tx/tracing/usage/CMakeLists.darwin-x86_64.txt":"",
+ "ydb/core/tx/tracing/usage/CMakeLists.linux-aarch64.txt":"",
+ "ydb/core/tx/tracing/usage/CMakeLists.linux-x86_64.txt":"",
+ "ydb/core/tx/tracing/usage/CMakeLists.txt":"",
+ "ydb/core/tx/tracing/usage/CMakeLists.windows-x86_64.txt":"",
"ydb/core/tx/tx_allocator/CMakeLists.darwin-x86_64.txt":"",
"ydb/core/tx/tx_allocator/CMakeLists.linux-aarch64.txt":"",
"ydb/core/tx/tx_allocator/CMakeLists.linux-x86_64.txt":"",
diff --git a/ydb/core/tx/CMakeLists.darwin-x86_64.txt b/ydb/core/tx/CMakeLists.darwin-x86_64.txt
index 583c9270a9..856e2ca8e4 100644
--- a/ydb/core/tx/CMakeLists.darwin-x86_64.txt
+++ b/ydb/core/tx/CMakeLists.darwin-x86_64.txt
@@ -24,6 +24,7 @@ add_subdirectory(sequenceshard)
add_subdirectory(sharding)
add_subdirectory(tiering)
add_subdirectory(time_cast)
+add_subdirectory(tracing)
add_subdirectory(tx_allocator)
add_subdirectory(tx_allocator_client)
add_subdirectory(tx_proxy)
diff --git a/ydb/core/tx/CMakeLists.linux-aarch64.txt b/ydb/core/tx/CMakeLists.linux-aarch64.txt
index 8fbaff3fc6..a3d4f7a61b 100644
--- a/ydb/core/tx/CMakeLists.linux-aarch64.txt
+++ b/ydb/core/tx/CMakeLists.linux-aarch64.txt
@@ -24,6 +24,7 @@ add_subdirectory(sequenceshard)
add_subdirectory(sharding)
add_subdirectory(tiering)
add_subdirectory(time_cast)
+add_subdirectory(tracing)
add_subdirectory(tx_allocator)
add_subdirectory(tx_allocator_client)
add_subdirectory(tx_proxy)
diff --git a/ydb/core/tx/CMakeLists.linux-x86_64.txt b/ydb/core/tx/CMakeLists.linux-x86_64.txt
index 8fbaff3fc6..a3d4f7a61b 100644
--- a/ydb/core/tx/CMakeLists.linux-x86_64.txt
+++ b/ydb/core/tx/CMakeLists.linux-x86_64.txt
@@ -24,6 +24,7 @@ add_subdirectory(sequenceshard)
add_subdirectory(sharding)
add_subdirectory(tiering)
add_subdirectory(time_cast)
+add_subdirectory(tracing)
add_subdirectory(tx_allocator)
add_subdirectory(tx_allocator_client)
add_subdirectory(tx_proxy)
diff --git a/ydb/core/tx/CMakeLists.windows-x86_64.txt b/ydb/core/tx/CMakeLists.windows-x86_64.txt
index 583c9270a9..856e2ca8e4 100644
--- a/ydb/core/tx/CMakeLists.windows-x86_64.txt
+++ b/ydb/core/tx/CMakeLists.windows-x86_64.txt
@@ -24,6 +24,7 @@ add_subdirectory(sequenceshard)
add_subdirectory(sharding)
add_subdirectory(tiering)
add_subdirectory(time_cast)
+add_subdirectory(tracing)
add_subdirectory(tx_allocator)
add_subdirectory(tx_allocator_client)
add_subdirectory(tx_proxy)
diff --git a/ydb/core/tx/tracing/CMakeLists.darwin-x86_64.txt b/ydb/core/tx/tracing/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..efa4f51b2f
--- /dev/null
+++ b/ydb/core/tx/tracing/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,18 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+add_subdirectory(service)
+add_subdirectory(usage)
+
+add_library(core-tx-tracing INTERFACE)
+target_link_libraries(core-tx-tracing INTERFACE
+ contrib-libs-cxxsupp
+ yutil
+ tx-tracing-service
+ tx-tracing-usage
+)
diff --git a/ydb/core/tx/tracing/CMakeLists.linux-aarch64.txt b/ydb/core/tx/tracing/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..b4e2ac09b5
--- /dev/null
+++ b/ydb/core/tx/tracing/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+add_subdirectory(service)
+add_subdirectory(usage)
+
+add_library(core-tx-tracing INTERFACE)
+target_link_libraries(core-tx-tracing INTERFACE
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ tx-tracing-service
+ tx-tracing-usage
+)
diff --git a/ydb/core/tx/tracing/CMakeLists.linux-x86_64.txt b/ydb/core/tx/tracing/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..b4e2ac09b5
--- /dev/null
+++ b/ydb/core/tx/tracing/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+add_subdirectory(service)
+add_subdirectory(usage)
+
+add_library(core-tx-tracing INTERFACE)
+target_link_libraries(core-tx-tracing INTERFACE
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ tx-tracing-service
+ tx-tracing-usage
+)
diff --git a/ydb/core/tx/tracing/CMakeLists.txt b/ydb/core/tx/tracing/CMakeLists.txt
new file mode 100644
index 0000000000..f8b31df0c1
--- /dev/null
+++ b/ydb/core/tx/tracing/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/core/tx/tracing/CMakeLists.windows-x86_64.txt b/ydb/core/tx/tracing/CMakeLists.windows-x86_64.txt
new file mode 100644
index 0000000000..efa4f51b2f
--- /dev/null
+++ b/ydb/core/tx/tracing/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,18 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+add_subdirectory(service)
+add_subdirectory(usage)
+
+add_library(core-tx-tracing INTERFACE)
+target_link_libraries(core-tx-tracing INTERFACE
+ contrib-libs-cxxsupp
+ yutil
+ tx-tracing-service
+ tx-tracing-usage
+)
diff --git a/ydb/core/tx/tracing/service/CMakeLists.darwin-x86_64.txt b/ydb/core/tx/tracing/service/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..c8c59647f3
--- /dev/null
+++ b/ydb/core/tx/tracing/service/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-service)
+target_link_libraries(tx-tracing-service PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ tx-tracing-usage
+)
+target_sources(tx-tracing-service PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/global.cpp
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/actor.cpp
+)
diff --git a/ydb/core/tx/tracing/service/CMakeLists.linux-aarch64.txt b/ydb/core/tx/tracing/service/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..31102a7dd1
--- /dev/null
+++ b/ydb/core/tx/tracing/service/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,21 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-service)
+target_link_libraries(tx-tracing-service PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ tx-tracing-usage
+)
+target_sources(tx-tracing-service PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/global.cpp
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/actor.cpp
+)
diff --git a/ydb/core/tx/tracing/service/CMakeLists.linux-x86_64.txt b/ydb/core/tx/tracing/service/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..31102a7dd1
--- /dev/null
+++ b/ydb/core/tx/tracing/service/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,21 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-service)
+target_link_libraries(tx-tracing-service PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ tx-tracing-usage
+)
+target_sources(tx-tracing-service PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/global.cpp
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/actor.cpp
+)
diff --git a/ydb/core/tx/tracing/service/CMakeLists.txt b/ydb/core/tx/tracing/service/CMakeLists.txt
new file mode 100644
index 0000000000..f8b31df0c1
--- /dev/null
+++ b/ydb/core/tx/tracing/service/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/core/tx/tracing/service/CMakeLists.windows-x86_64.txt b/ydb/core/tx/tracing/service/CMakeLists.windows-x86_64.txt
new file mode 100644
index 0000000000..c8c59647f3
--- /dev/null
+++ b/ydb/core/tx/tracing/service/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-service)
+target_link_libraries(tx-tracing-service PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ tx-tracing-usage
+)
+target_sources(tx-tracing-service PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/global.cpp
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/service/actor.cpp
+)
diff --git a/ydb/core/tx/tracing/service/actor.cpp b/ydb/core/tx/tracing/service/actor.cpp
new file mode 100644
index 0000000000..c2839d35d0
--- /dev/null
+++ b/ydb/core/tx/tracing/service/actor.cpp
@@ -0,0 +1,5 @@
+#include "actor.h"
+
+namespace NKikimr::NTracing {
+
+}
diff --git a/ydb/core/tx/tracing/service/actor.h b/ydb/core/tx/tracing/service/actor.h
new file mode 100644
index 0000000000..4323278a03
--- /dev/null
+++ b/ydb/core/tx/tracing/service/actor.h
@@ -0,0 +1,32 @@
+#pragma once
+#include "global.h"
+#include <library/cpp/actors/core/actor_bootstrapped.h>
+
+namespace NKikimr::NTracing {
+
+class TRegularTracesCleanerActor: public NActors::TActorBootstrapped<TRegularTracesCleanerActor> {
+private:
+ void Handle(NActors::TEvents::TEvWakeup::TPtr& /*ev*/) {
+ Singleton<TTracing>()->Clean();
+ Schedule(TDuration::Seconds(5), new NActors::TEvents::TEvWakeup);
+ }
+public:
+ TRegularTracesCleanerActor() {
+
+ }
+
+ void Bootstrap() {
+ Schedule(TDuration::Seconds(5), new NActors::TEvents::TEvWakeup);
+ Become(&TRegularTracesCleanerActor::StateMain);
+ }
+
+ STATEFN(StateMain) {
+ switch (ev->GetTypeRewrite()) {
+ hFunc(NActors::TEvents::TEvWakeup, Handle);
+ default:
+ break;
+ }
+ }
+};
+
+}
diff --git a/ydb/core/tx/tracing/service/global.cpp b/ydb/core/tx/tracing/service/global.cpp
new file mode 100644
index 0000000000..94e24ecf1d
--- /dev/null
+++ b/ydb/core/tx/tracing/service/global.cpp
@@ -0,0 +1,43 @@
+#include "global.h"
+#include "actor.h"
+#include <ydb/library/services/services.pb.h>
+
+namespace NKikimr::NTracing {
+
+std::shared_ptr<NKikimr::NTracing::TTraceClient> TTracing::GetClient(const TString& type, const TString& clientId, const TString& parentId) {
+ TGuard<TMutex> g(Mutex);
+ auto parent = CreateOrGetClient(parentId, "");
+ auto client = CreateOrGetClient(clientId, parentId);
+ AFL_VERIFY(client->GetParentId() == parentId);
+ client->SetType(type);
+ parent->RegisterChildren(client);
+ return client;
+}
+
+TTracing::TTracing() {
+ if (NActors::TlsActivationContext) {
+ NActors::TActivationContext::Register(new TRegularTracesCleanerActor());
+ }
+}
+
+void TTracing::Clean() {
+ THashMap<TString, std::shared_ptr<TTraceClient>> idsToRemove;
+ {
+ TGuard<TMutex> g(Mutex);
+ for (auto&& i : Clients) {
+ AFL_NOTICE(NKikimrServices::TX_COLUMNSHARD)("name", i.first)("count", i.second.use_count())("children", i.second->CheckChildrenFree());
+ if (i.second.use_count() == 1 && i.second->CheckChildrenFree()) {
+ idsToRemove.emplace(i.first, i.second);
+ }
+ }
+ for (auto&& i : idsToRemove) {
+ Clients.erase(i.first);
+ }
+ }
+ for (auto&& i : idsToRemove) {
+ AFL_NOTICE(NKikimrServices::TX_COLUMNSHARD)("event", "dump")("name", i.first)("parent", i.second->GetParentId());
+ i.second->Dump();
+ }
+}
+
+}
diff --git a/ydb/core/tx/tracing/service/global.h b/ydb/core/tx/tracing/service/global.h
new file mode 100644
index 0000000000..5cfec596fd
--- /dev/null
+++ b/ydb/core/tx/tracing/service/global.h
@@ -0,0 +1,27 @@
+#pragma once
+#include <util/generic/hash.h>
+#include <ydb/core/tx/tracing/usage/tracing.h>
+#include <util/system/mutex.h>
+
+namespace NKikimr::NTracing {
+
+class TTracing {
+private:
+ THashMap<TString, std::shared_ptr<TTraceClient>> Clients;
+ std::shared_ptr<TTraceClient> CreateOrGetClient(const TString& clientId, const TString& parentId) {
+ auto it = Clients.find(clientId);
+ if (it == Clients.end()) {
+ it = Clients.emplace(clientId, std::make_shared<TTraceClient>(clientId, parentId)).first;
+ }
+ return it->second;
+ }
+ TMutex Mutex;
+public:
+ TTracing();
+
+ void Clean();
+
+ std::shared_ptr<TTraceClient> GetClient(const TString& type, const TString& clientId, const TString& parentId);
+};
+
+}
diff --git a/ydb/core/tx/tracing/service/ya.make b/ydb/core/tx/tracing/service/ya.make
new file mode 100644
index 0000000000..377252289d
--- /dev/null
+++ b/ydb/core/tx/tracing/service/ya.make
@@ -0,0 +1,13 @@
+LIBRARY()
+
+SRCS(
+ global.cpp
+ actor.cpp
+)
+
+PEERDIR(
+ ydb/core/protos
+ ydb/core/tx/tracing/usage
+)
+
+END()
diff --git a/ydb/core/tx/tracing/usage/CMakeLists.darwin-x86_64.txt b/ydb/core/tx/tracing/usage/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..315c512254
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-usage)
+target_link_libraries(tx-tracing-usage PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ cpp-actors-core
+)
+target_sources(tx-tracing-usage PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/usage/tracing.cpp
+)
diff --git a/ydb/core/tx/tracing/usage/CMakeLists.linux-aarch64.txt b/ydb/core/tx/tracing/usage/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..b4ad271960
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-usage)
+target_link_libraries(tx-tracing-usage PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ cpp-actors-core
+)
+target_sources(tx-tracing-usage PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/usage/tracing.cpp
+)
diff --git a/ydb/core/tx/tracing/usage/CMakeLists.linux-x86_64.txt b/ydb/core/tx/tracing/usage/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..b4ad271960
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-usage)
+target_link_libraries(tx-tracing-usage PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ cpp-actors-core
+)
+target_sources(tx-tracing-usage PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/usage/tracing.cpp
+)
diff --git a/ydb/core/tx/tracing/usage/CMakeLists.txt b/ydb/core/tx/tracing/usage/CMakeLists.txt
new file mode 100644
index 0000000000..f8b31df0c1
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/core/tx/tracing/usage/CMakeLists.windows-x86_64.txt b/ydb/core/tx/tracing/usage/CMakeLists.windows-x86_64.txt
new file mode 100644
index 0000000000..315c512254
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(tx-tracing-usage)
+target_link_libraries(tx-tracing-usage PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ cpp-actors-core
+)
+target_sources(tx-tracing-usage PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/tx/tracing/usage/tracing.cpp
+)
diff --git a/ydb/core/tx/tracing/usage/tracing.cpp b/ydb/core/tx/tracing/usage/tracing.cpp
new file mode 100644
index 0000000000..0834f8ad0d
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/tracing.cpp
@@ -0,0 +1,159 @@
+#include "tracing.h"
+#include <ydb/core/tx/tracing/service/global.h>
+#include <util/string/join.h>
+#include <util/stream/buffered.h>
+#include <util/stream/fwd.h>
+#include <util/stream/file.h>
+#include <util/system/tls.h>
+
+namespace NKikimr::NTracing {
+
+TTraceClientGuard TTraceClient::GetClient(const TString& type, const TString& clientId, const TString& parentId) {
+ return Singleton<TTracing>()->GetClient(type, clientId, parentId);
+}
+
+namespace {
+
+static TAtomicCounter ClientsCounter = 0;
+NTls::TValue<std::vector<TTraceClient*>> GuardedClients;
+NTls::TValue<std::vector<TTraceClient::TDurationGuard*>> Guards;
+}
+
+TTraceClient::TDurationGuard TTraceClient::MakeContextGuard(const TString& id) {
+ if (GuardedClients.Get().size()) {
+ return GuardedClients.Get().back()->MakeGuard(id);
+ } else {
+ return TTraceClient::TDurationGuard(id);
+ }
+}
+
+TTraceClient::TDurationGuard* TTraceClient::GetContextGuard() {
+ if (GuardedClients.Get().size()) {
+ return Guards.Get().back();
+ } else {
+ return nullptr;
+ }
+}
+
+TTraceClient::TDurationGuard::TDurationGuard(TTraceClient& owner, const TString& id)
+ : Owner(&owner)
+ , Id(id)
+{
+ GuardedClients.Get().emplace_back(Owner);
+ Guards.Get().emplace_back(this);
+ auto it = Owner->Stats.find(Id);
+ if (it == Owner->Stats.end()) {
+ it = Owner->Stats.emplace(Id, TStatInfo()).first;
+ }
+ Stat = &it->second;
+ Stat->Start(StartInstant);
+}
+
+TTraceClient::TDurationGuard::TDurationGuard(const TString& id)
+ : Id(id) {
+}
+
+TTraceClient::TDurationGuard::~TDurationGuard() {
+ if (!Owner) {
+ return;
+ }
+ AFL_VERIFY(GuardedClients.Get().size() && GuardedClients.Get().back()->GetClientId() == Owner->GetClientId());
+ GuardedClients.Get().pop_back();
+ Guards.Get().pop_back();
+ Stat->Finish(TInstant::Now());
+}
+
+TTraceClientGuard TTraceClient::GetClientUnique(const TString& type, const TString& clientId, const TString& parentId) {
+ return Singleton<TTracing>()->GetClient(type, clientId + "::" + ::ToString(ClientsCounter.Inc()), parentId);
+}
+
+TTraceClientGuard TTraceClient::GetTypeUnique(const TString& type, const TString& parentId) {
+ return Singleton<TTracing>()->GetClient(type, type + "::" + ::ToString(ClientsCounter.Inc()), parentId);
+}
+
+NJson::TJsonValue TTraceClient::ToJsonImpl(THashSet<TString>& readyIds) const {
+ if (!readyIds.emplace(ClientId).second || readyIds.size() > 10) {
+ NJson::TJsonValue result = NJson::JSON_MAP;
+ result.InsertValue("problem", "LOOP_FOUND_OR_LARGE");
+ result.InsertValue("ids", JoinSeq(",", readyIds));
+ return result;
+ }
+ const TInstant finishInstant = GetFinishInstant();
+ NJson::TJsonValue result = NJson::JSON_MAP;
+ result.InsertValue("id", ClientId);
+ result.InsertValue("full", ActualStat.ToJson("_full_task", finishInstant));
+ if (ParentId) {
+ result.InsertValue("parent_id", ParentId);
+ }
+ if (Stats.size()) {
+ const TInstant startInstant = ActualStat.GetFirstVerified();
+ std::map<ui64, std::vector<TString>> points;
+ for (auto&& i : Stats) {
+ points[(i.second.GetFirstVerified() - startInstant).MilliSeconds()].emplace_back("f_" + i.first);
+ if (i.second.InProgress()) {
+ points[(finishInstant - startInstant).MilliSeconds()].emplace_back("l_" + i.first);
+ } else {
+ points[(i.second.GetLastVerified() - startInstant).MilliSeconds()].emplace_back("l_" + i.first);
+ }
+ }
+ auto& jsonArrayPoints = result.InsertValue("p", NJson::JSON_ARRAY);
+ for (auto&& i : points) {
+ auto& jsonMap = jsonArrayPoints.AppendValue(NJson::JSON_MAP);
+ jsonMap.InsertValue("t", (double)(0.001 * i.first));
+ auto& jsonEvents = jsonMap.InsertValue("events", NJson::JSON_ARRAY);
+ for (auto&& e : i.second) {
+ jsonEvents.AppendValue(e);
+ }
+ }
+ auto& jsonArrayDurations = result.InsertValue("events", NJson::JSON_ARRAY);
+ for (auto&& i : Stats) {
+ jsonArrayDurations.AppendValue(i.second.ToJson(i.first, finishInstant));
+ }
+ }
+ if (Children.size()) {
+ THashMap<TString, std::vector<std::shared_ptr<TTraceClient>>> clientsByType;
+ for (auto&& i : Children) {
+ clientsByType[i.second->GetType()].emplace_back(i.second);
+ }
+ auto& jsonChild = result.InsertValue("child", NJson::JSON_MAP);
+ for (auto&& [type, clients] : clientsByType) {
+ auto& jsonChildWithType = jsonChild.InsertValue(type, NJson::JSON_ARRAY);
+ for (auto&& c : clients) {
+ jsonChildWithType.AppendValue(c->ToJsonImpl(readyIds));
+ }
+ }
+ }
+ readyIds.erase(ClientId);
+ return result;
+}
+
+void TTraceClient::Dump() const {
+ if (!ParentId) {
+ TFileOutput fOutput("/tmp/" + ClientId + ".json.txt");
+ fOutput << ToJson();
+ }
+}
+
+bool TTraceClient::CheckChildrenFree() const {
+ for (auto&& i : Children) {
+ if (i.second.use_count() > 2) {
+ return false;
+ }
+ if (!i.second->CheckChildrenFree()) {
+ return false;
+ }
+ }
+ return true;
+}
+
+TInstant TStatInfo::GetFirstVerified() const {
+ AFL_VERIFY(First);
+ return *First;
+}
+
+TInstant TStatInfo::GetLastVerified() const {
+ AFL_VERIFY(Last);
+ return *Last;
+}
+
+}
diff --git a/ydb/core/tx/tracing/usage/tracing.h b/ydb/core/tx/tracing/usage/tracing.h
new file mode 100644
index 0000000000..7954190174
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/tracing.h
@@ -0,0 +1,181 @@
+#pragma once
+#include <ydb/library/accessor/accessor.h>
+#include <util/datetime/base.h>
+#include <memory>
+#include <optional>
+#include <library/cpp/actors/core/log.h>
+#include <library/cpp/json/writer/json_value.h>
+
+namespace NKikimr::NTracing {
+
+class TStatInfo {
+private:
+ YDB_ACCESSOR_DEF(TDuration, Duration);
+ YDB_ACCESSOR(ui32, Count, 0);
+ YDB_ACCESSOR(ui32, StatCount, 0);
+ YDB_ACCESSOR_DEF(std::optional<TInstant>, First);
+ YDB_ACCESSOR_DEF(std::optional<TInstant>, Last);
+ YDB_ACCESSOR_DEF(std::optional<TInstant>, ActualStart);
+public:
+ TStatInfo() = default;
+
+ NJson::TJsonValue ToJson(const TString& name, const TInstant finishInstant) const {
+ NJson::TJsonValue result = NJson::JSON_MAP;
+ result.InsertValue("name", name);
+ result.InsertValue("d_finished", Duration.MicroSeconds());
+ if (First) {
+ result.InsertValue("f", First->MicroSeconds());
+ }
+ if (Last) {
+ result.InsertValue("l", Last->MicroSeconds());
+ } else {
+ result.InsertValue("l", finishInstant.MicroSeconds());
+ }
+ if (ActualStart) {
+ result.InsertValue("a", ActualStart->MicroSeconds());
+ }
+ result.InsertValue("d", (Duration + GetCurrentDuration(finishInstant)).MicroSeconds());
+ result.InsertValue("c", Count);
+ if (StatCount) {
+ result.InsertValue("sc", StatCount);
+ }
+ return result;
+ }
+ TInstant GetLastVerified() const;
+
+ TInstant GetFirstVerified() const;
+
+ TDuration GetCurrentDuration(const TInstant now) const {
+ return ActualStart ? now - *ActualStart : TDuration::Zero();
+ }
+
+ bool InProgress() const {
+ return !!ActualStart;
+ }
+
+ void Start(const TInstant start) {
+ if (!First || *First > start) {
+ First = start;
+ }
+ AFL_VERIFY(!ActualStart);
+ ActualStart = start;
+ }
+
+ void Finish(const TInstant value) {
+ if (!Last || *Last < value) {
+ Last = value;
+ }
+ AFL_VERIFY(ActualStart);
+ Duration += value - *ActualStart;
+ ++Count;
+ ActualStart.reset();
+ }
+};
+
+class TTraceClientGuard;
+
+class TTraceClient {
+private:
+ YDB_READONLY_DEF(TString, Type);
+ YDB_READONLY_DEF(TString, ClientId);
+ YDB_READONLY_DEF(TString, ParentId);
+ THashMap<TString, std::shared_ptr<TTraceClient>> Children;
+ THashMap<TString, TStatInfo> Stats;
+ TStatInfo ActualStat;
+ TInstant GetFinishInstant() const {
+ return ActualStat.GetLast().value_or(TInstant::Now());
+ }
+
+ NJson::TJsonValue ToJsonImpl(THashSet<TString>& readyIds) const;
+public:
+ void SetType(const TString& value) {
+ AFL_VERIFY(!Type || Type == value);
+ Type = value;
+ }
+
+ bool CheckChildrenFree() const;
+
+ void Finish() {
+ ActualStat.Finish(TInstant::Now());
+ }
+
+ TTraceClient(const TString& id, const TString& parentId)
+ : ClientId(id)
+ , ParentId(parentId)
+ {
+ ActualStat.Start(TInstant::Now());
+ }
+
+ void Dump() const;
+
+ NJson::TJsonValue ToJson() const {
+ THashSet<TString> readyIds;
+ return ToJsonImpl(readyIds);
+ }
+
+ void RegisterChildren(const std::shared_ptr<TTraceClient>& client) {
+ AFL_VERIFY(client->GetParentId() == ClientId);
+ auto it = Children.find(client->GetClientId());
+ if (it == Children.end()) {
+ Children.emplace(client->GetClientId(), client);
+ }
+ }
+
+ const std::shared_ptr<TTraceClient>& GetChildrenVerified(const TString& id) const {
+ auto it = Children.find(id);
+ AFL_VERIFY(it != Children.end());
+ return it->second;
+ }
+
+ class TDurationGuard: TNonCopyable {
+ private:
+ const TInstant StartInstant = TInstant::Now();
+ TTraceClient* Owner = nullptr;
+ const TString Id;
+ TStatInfo* Stat;
+ public:
+ TDurationGuard(TTraceClient& owner, const TString& id);
+ TDurationGuard(const TString& id);
+ TStatInfo& GetStatInfo() {
+ AFL_VERIFY(Stat);
+ return *Stat;
+ }
+ ~TDurationGuard();
+ };
+
+ static TTraceClient::TDurationGuard MakeContextGuard(const TString& id);
+ static TTraceClient::TDurationGuard* GetContextGuard();
+
+ TDurationGuard MakeGuard(const TString& id) {
+ return TDurationGuard(*this, id);
+ }
+
+ static TTraceClientGuard GetClient(const TString& type, const TString& clientId, const TString& parentId);
+ static TTraceClientGuard GetClientUnique(const TString& type, const TString& clientId, const TString& parentId);
+ static TTraceClientGuard GetTypeUnique(const TString& type, const TString& parentId);
+};
+
+class TTraceClientGuard: public TNonCopyable {
+private:
+ std::shared_ptr<TTraceClient> Client;
+public:
+ TTraceClientGuard(const std::shared_ptr<TTraceClient>& client)
+ : Client(client)
+ {
+
+ }
+
+ ~TTraceClientGuard() {
+ Client->Finish();
+ }
+
+ TTraceClient* operator->() {
+ return Client.get();
+ }
+
+ const TTraceClient* operator->() const {
+ return Client.get();
+ }
+};
+
+}
diff --git a/ydb/core/tx/tracing/usage/ya.make b/ydb/core/tx/tracing/usage/ya.make
new file mode 100644
index 0000000000..e1f3dc0f69
--- /dev/null
+++ b/ydb/core/tx/tracing/usage/ya.make
@@ -0,0 +1,12 @@
+LIBRARY()
+
+SRCS(
+ tracing.cpp
+)
+
+PEERDIR(
+ ydb/core/protos
+ library/cpp/actors/core
+)
+
+END()
diff --git a/ydb/core/tx/tracing/ya.make b/ydb/core/tx/tracing/ya.make
new file mode 100644
index 0000000000..d7f2b0c852
--- /dev/null
+++ b/ydb/core/tx/tracing/ya.make
@@ -0,0 +1,11 @@
+LIBRARY()
+
+SRCS(
+)
+
+PEERDIR(
+ ydb/core/tx/tracing/service
+ ydb/core/tx/tracing/usage
+)
+
+END()
diff --git a/ydb/core/tx/ya.make b/ydb/core/tx/ya.make
index d0674c7943..ef90637846 100644
--- a/ydb/core/tx/ya.make
+++ b/ydb/core/tx/ya.make
@@ -41,4 +41,5 @@ RECURSE(
tx_proxy
tiering
sharding
+ tracing
)