diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/lwtrace/example1 | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/lwtrace/example1')
-rw-r--r-- | library/cpp/lwtrace/example1/example_query.tr | 10 | ||||
-rw-r--r-- | library/cpp/lwtrace/example1/lwtrace_example1.cpp | 39 | ||||
-rwxr-xr-x | library/cpp/lwtrace/example1/start_with_query.sh | 3 | ||||
-rw-r--r-- | library/cpp/lwtrace/example1/ya.make | 13 |
4 files changed, 65 insertions, 0 deletions
diff --git a/library/cpp/lwtrace/example1/example_query.tr b/library/cpp/lwtrace/example1/example_query.tr new file mode 100644 index 0000000000..a06e2a922d --- /dev/null +++ b/library/cpp/lwtrace/example1/example_query.tr @@ -0,0 +1,10 @@ +Blocks { + ProbeDesc { + Name: "IterationProbe" + Provider: "LWTRACE_EXAMPLE_PROVIDER" + } + Action { + PrintToStderrAction { } + } +} + diff --git a/library/cpp/lwtrace/example1/lwtrace_example1.cpp b/library/cpp/lwtrace/example1/lwtrace_example1.cpp new file mode 100644 index 0000000000..6b32c405ee --- /dev/null +++ b/library/cpp/lwtrace/example1/lwtrace_example1.cpp @@ -0,0 +1,39 @@ +#include <library/cpp/lwtrace/all.h> + +#define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ + PROBE(IterationProbe, GROUPS(), TYPES(i32, double), NAMES("n", "result")) \ + /**/ + +LWTRACE_DECLARE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER) +LWTRACE_DEFINE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER) + +void InitLWTrace() { + NLWTrace::StartLwtraceFromEnv(); +} + +long double Fact(int n) { + if (n < 0) { + ythrow yexception() << "N! is undefined for negative N (" << n << ")"; + } + double result = 1; + for (; n > 1; --n) { + GLOBAL_LWPROBE(LWTRACE_EXAMPLE_PROVIDER, IterationProbe, n, result); + result *= n; + } + return result; +} + +void FactorialCalculator() { + i32 n; + Cout << "Enter a number: "; + TString str; + Cin >> n; + double factN = Fact(n); + Cout << n << "! = " << factN << Endl << Endl; +} + +int main() { + InitLWTrace(); + FactorialCalculator(); + return 0; +} diff --git a/library/cpp/lwtrace/example1/start_with_query.sh b/library/cpp/lwtrace/example1/start_with_query.sh new file mode 100755 index 0000000000..2b456d7be7 --- /dev/null +++ b/library/cpp/lwtrace/example1/start_with_query.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export LWTRACE="example_query.tr" +./lwtrace-example1 diff --git a/library/cpp/lwtrace/example1/ya.make b/library/cpp/lwtrace/example1/ya.make new file mode 100644 index 0000000000..5ae8c4a48e --- /dev/null +++ b/library/cpp/lwtrace/example1/ya.make @@ -0,0 +1,13 @@ +PROGRAM(lwtrace-example1) + +OWNER(cthulhu) + +SRCS( + lwtrace_example1.cpp +) + +PEERDIR( + library/cpp/lwtrace +) + +END() |