Coverage Report

Created: 2026-06-15 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libtorrent/src/session_call.cpp
Line
Count
Source
1
/*
2
3
Copyright (c) 2014-2019, Steven Siloti
4
Copyright (c) 2014, 2016, 2019-2021, Arvid Norberg
5
Copyright (c) 2016, 2022, Alden Torres
6
All rights reserved.
7
8
You may use, distribute and modify this code under the terms of the BSD license,
9
see LICENSE file.
10
*/
11
12
#include "libtorrent/aux_/session_call.hpp"
13
14
namespace libtorrent::aux {
15
16
#ifdef TORRENT_PROFILE_CALLS
17
static std::mutex g_calls_mutex;
18
static std::unordered_map<std::string, int> g_blocking_calls;
19
#endif
20
21
void blocking_call()
22
2.42k
{
23
#ifdef TORRENT_PROFILE_CALLS
24
  char stack[2048];
25
  print_backtrace(stack, sizeof(stack), 20);
26
  std::unique_lock<std::mutex> l(g_calls_mutex);
27
  g_blocking_calls[stack] += 1;
28
#endif
29
2.42k
}
30
31
void dump_call_profile()
32
12
{
33
#ifdef TORRENT_PROFILE_CALLS
34
  FILE* out = fopen("blocking_calls.txt", "w+");
35
36
  std::map<int, std::string> profile;
37
38
  std::unique_lock<std::mutex> l(g_calls_mutex);
39
  for (auto const& c : g_blocking_calls)
40
  {
41
    profile[c.second] = c.first;
42
  }
43
  for (std::map<int, std::string>::const_reverse_iterator i = profile.rbegin()
44
    , end(profile.rend()); i != end; ++i)
45
  {
46
    std::fprintf(out, "\n\n%d\n%s\n", i->first, i->second.c_str());
47
  }
48
  fclose(out);
49
#endif
50
12
}
51
52
void torrent_wait(bool& done, aux::session_impl& ses)
53
2.42k
{
54
2.42k
  blocking_call();
55
2.42k
  std::unique_lock<std::mutex> l(ses.mut);
56
4.85k
  while (!done) { ses.cond.wait(l); }
57
2.42k
}
58
59
} // namespace libtorrent::aux