aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/lwtrace/example3
diff options
context:
space:
mode:
authorserxa <serxa@yandex-team.ru>2022-02-10 16:49:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:08 +0300
commite5d4696304c6689379ac7ce334512404d4b7836c (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/lwtrace/example3
parentd6d7db348c2cc64e71243cab9940ee6778f4317d (diff)
downloadydb-e5d4696304c6689379ac7ce334512404d4b7836c.tar.gz
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/lwtrace/example3')
-rw-r--r--library/cpp/lwtrace/example3/example_query.tr8
-rw-r--r--library/cpp/lwtrace/example3/lwtrace_example3.cpp12
-rw-r--r--library/cpp/lwtrace/example3/my_action.h162
-rwxr-xr-xlibrary/cpp/lwtrace/example3/start_with_query.sh10
-rw-r--r--library/cpp/lwtrace/example3/ya.make6
5 files changed, 99 insertions, 99 deletions
diff --git a/library/cpp/lwtrace/example3/example_query.tr b/library/cpp/lwtrace/example3/example_query.tr
index e53c21c02d..1f841b0932 100644
--- a/library/cpp/lwtrace/example3/example_query.tr
+++ b/library/cpp/lwtrace/example3/example_query.tr
@@ -4,10 +4,10 @@ Blocks {
Provider: "LWTRACE_EXAMPLE_PROVIDER"
}
Action {
- CustomAction {
- Name: "MyAction"
- Opts: "/dev/stdout"
- }
+ CustomAction {
+ Name: "MyAction"
+ Opts: "/dev/stdout"
+ }
}
}
diff --git a/library/cpp/lwtrace/example3/lwtrace_example3.cpp b/library/cpp/lwtrace/example3/lwtrace_example3.cpp
index 2fa2976a69..4493dc0077 100644
--- a/library/cpp/lwtrace/example3/lwtrace_example3.cpp
+++ b/library/cpp/lwtrace/example3/lwtrace_example3.cpp
@@ -1,8 +1,8 @@
#include <library/cpp/lwtrace/all.h>
#include <google/protobuf/text_format.h>
-#include "my_action.h"
+#include "my_action.h"
-#define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \
+#define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \
PROBE(IterationProbe, GROUPS(), TYPES(i32, double), NAMES("n", "result")) \
/**/
@@ -10,12 +10,12 @@ LWTRACE_DECLARE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER)
LWTRACE_DEFINE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER)
void InitLWTrace() {
- NLWTrace::StartLwtraceFromEnv([=](NLWTrace::TManager& mngr) {
- mngr.RegisterCustomAction<TMyActionExecutor>();
- });
+ NLWTrace::StartLwtraceFromEnv([=](NLWTrace::TManager& mngr) {
+ mngr.RegisterCustomAction<TMyActionExecutor>();
+ });
}
-long double Fact(int n) {
+long double Fact(int n) {
if (n < 0) {
ythrow yexception() << "N! is undefined for negative N (" << n << ")";
}
diff --git a/library/cpp/lwtrace/example3/my_action.h b/library/cpp/lwtrace/example3/my_action.h
index 80a34ecca8..9a04293ba2 100644
--- a/library/cpp/lwtrace/example3/my_action.h
+++ b/library/cpp/lwtrace/example3/my_action.h
@@ -1,85 +1,85 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/lwtrace/all.h>
-#include <util/stream/file.h>
-
-// Example of custom state for custom executors
-// Holds file for output from TMyActionExecutor
-class TMyFile: public NLWTrace::IResource {
-private:
- TMutex Mutex;
+#include <util/stream/file.h>
+
+// Example of custom state for custom executors
+// Holds file for output from TMyActionExecutor
+class TMyFile: public NLWTrace::IResource {
+private:
+ TMutex Mutex;
THolder<TUnbufferedFileOutput> File;
-
-public:
- // Note that this class must have default ctor (it's declared here just for clearness)
- TMyFile() {
- }
-
- // Note that dtor will be called by TManager::Delete() after detachment and destruction of all executors
- ~TMyFile() {
- }
-
- // Some kind of state initialization
- // Can be called only from executor constructor, and should not be thread-safe
- void Open(const TString& path) {
- if (File) {
- // We must avoid double open because each executor will call Open() on the same object
- // if the same file was specified in Opts
- return;
- }
+
+public:
+ // Note that this class must have default ctor (it's declared here just for clearness)
+ TMyFile() {
+ }
+
+ // Note that dtor will be called by TManager::Delete() after detachment and destruction of all executors
+ ~TMyFile() {
+ }
+
+ // Some kind of state initialization
+ // Can be called only from executor constructor, and should not be thread-safe
+ void Open(const TString& path) {
+ if (File) {
+ // We must avoid double open because each executor will call Open() on the same object
+ // if the same file was specified in Opts
+ return;
+ }
File.Reset(new TUnbufferedFileOutput(path));
- }
-
- // Outputs a line to opened file
- // Can be called from DoExecute() and must be thread-safe
- void Output(const TString& line) {
- Y_VERIFY(File);
- TGuard<TMutex> g(Mutex); // Because DoExecute() call can come from any thread
- *File << line << Endl;
- }
-};
-
-// Action that prints events to specified file
-class TMyActionExecutor: public NLWTrace::TCustomActionExecutor {
-private:
- TMyFile& File;
-
-public:
- TMyActionExecutor(NLWTrace::TProbe* probe, const NLWTrace::TCustomAction& action, NLWTrace::TSession* session)
- : NLWTrace::TCustomActionExecutor(probe, false /* not destructive */)
- , File(session->Resources().Get<TMyFile>("FileHolder/" + action.GetOpts(0))) // unique state id must include your d
- {
- if (action.GetOpts().size() != 1) {
- yexception() << "wrong number of Opts in MyAction";
- }
- File.Open(action.GetOpts(0));
- }
-
- static const char* GetActionName() {
- static const char name[] = "MyAction";
- return name;
- }
-
-private:
- virtual bool DoExecute(NLWTrace::TOrbit&, const NLWTrace::TParams& params) {
- // Serialize param values to strings
+ }
+
+ // Outputs a line to opened file
+ // Can be called from DoExecute() and must be thread-safe
+ void Output(const TString& line) {
+ Y_VERIFY(File);
+ TGuard<TMutex> g(Mutex); // Because DoExecute() call can come from any thread
+ *File << line << Endl;
+ }
+};
+
+// Action that prints events to specified file
+class TMyActionExecutor: public NLWTrace::TCustomActionExecutor {
+private:
+ TMyFile& File;
+
+public:
+ TMyActionExecutor(NLWTrace::TProbe* probe, const NLWTrace::TCustomAction& action, NLWTrace::TSession* session)
+ : NLWTrace::TCustomActionExecutor(probe, false /* not destructive */)
+ , File(session->Resources().Get<TMyFile>("FileHolder/" + action.GetOpts(0))) // unique state id must include your d
+ {
+ if (action.GetOpts().size() != 1) {
+ yexception() << "wrong number of Opts in MyAction";
+ }
+ File.Open(action.GetOpts(0));
+ }
+
+ static const char* GetActionName() {
+ static const char name[] = "MyAction";
+ return name;
+ }
+
+private:
+ virtual bool DoExecute(NLWTrace::TOrbit&, const NLWTrace::TParams& params) {
+ // Serialize param values to strings
TString paramValues[LWTRACE_MAX_PARAMS];
- Probe->Event.Signature.SerializeParams(params, paramValues);
-
- // Generate output line
- TStringStream ss;
- ss << "TMyActionExecutor>>> ";
- ss << Probe->Event.Name;
- for (ui32 i = 0; i < Probe->Event.Signature.ParamCount; ++i) {
- ss << " " << Probe->Event.Signature.ParamNames[i] << "=" << paramValues[i];
- }
-
- // Write line to file
- File.Output(ss.Str());
-
- // Executors can chain if you specify multiple actions in one block (in trace query).
- // So return true to continue execution of actions for given trace query block (on current triggered event)
- // or return false if this action is the last for this block
- return true;
- }
-};
+ Probe->Event.Signature.SerializeParams(params, paramValues);
+
+ // Generate output line
+ TStringStream ss;
+ ss << "TMyActionExecutor>>> ";
+ ss << Probe->Event.Name;
+ for (ui32 i = 0; i < Probe->Event.Signature.ParamCount; ++i) {
+ ss << " " << Probe->Event.Signature.ParamNames[i] << "=" << paramValues[i];
+ }
+
+ // Write line to file
+ File.Output(ss.Str());
+
+ // Executors can chain if you specify multiple actions in one block (in trace query).
+ // So return true to continue execution of actions for given trace query block (on current triggered event)
+ // or return false if this action is the last for this block
+ return true;
+ }
+};
diff --git a/library/cpp/lwtrace/example3/start_with_query.sh b/library/cpp/lwtrace/example3/start_with_query.sh
index 09f4395f7c..5cd221856f 100755
--- a/library/cpp/lwtrace/example3/start_with_query.sh
+++ b/library/cpp/lwtrace/example3/start_with_query.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-echo "Executing program with following trace query:"
-cat example_query.tr
-echo -n "Press any key to start program"
-read
-LWTRACE="example_query.tr" ./lwtrace-example3
+echo "Executing program with following trace query:"
+cat example_query.tr
+echo -n "Press any key to start program"
+read
+LWTRACE="example_query.tr" ./lwtrace-example3
diff --git a/library/cpp/lwtrace/example3/ya.make b/library/cpp/lwtrace/example3/ya.make
index e3a16da2b2..c5b31586e9 100644
--- a/library/cpp/lwtrace/example3/ya.make
+++ b/library/cpp/lwtrace/example3/ya.make
@@ -1,9 +1,9 @@
-PROGRAM(lwtrace-example3)
+PROGRAM(lwtrace-example3)
-OWNER(serxa)
+OWNER(serxa)
SRCS(
- lwtrace_example3.cpp
+ lwtrace_example3.cpp
)
PEERDIR(