lwtrace_example1.cpp 932 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <library/cpp/lwtrace/all.h>
  2. #define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \
  3. PROBE(IterationProbe, GROUPS(), TYPES(i32, double), NAMES("n", "result")) \
  4. /**/
  5. LWTRACE_DECLARE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER)
  6. LWTRACE_DEFINE_PROVIDER(LWTRACE_EXAMPLE_PROVIDER)
  7. void InitLWTrace() {
  8. NLWTrace::StartLwtraceFromEnv();
  9. }
  10. long double Fact(int n) {
  11. if (n < 0) {
  12. ythrow yexception() << "N! is undefined for negative N (" << n << ")";
  13. }
  14. double result = 1;
  15. for (; n > 1; --n) {
  16. GLOBAL_LWPROBE(LWTRACE_EXAMPLE_PROVIDER, IterationProbe, n, result);
  17. result *= n;
  18. }
  19. return result;
  20. }
  21. void FactorialCalculator() {
  22. i32 n;
  23. Cout << "Enter a number: ";
  24. TString str;
  25. Cin >> n;
  26. double factN = Fact(n);
  27. Cout << n << "! = " << factN << Endl << Endl;
  28. }
  29. int main() {
  30. InitLWTrace();
  31. FactorialCalculator();
  32. return 0;
  33. }