lwtrace_example4.cpp 1.1 KB

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