Repository navigation
Expand file tree
/
Copy pathdeterministic_time.cc
More file actions
70 lines (58 loc) · 2.32 KB
/
Copy pathdeterministic_time.cc
File metadata and controls
70 lines (58 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ortools/util/deterministic_time.h"
#ifdef OR_TOOLS_UTIL_DETERMINISTIC_TIME_PROFILING
#include <cstdint>
#include <iostream>
#include <memory>
#include <stack>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "absl/debugging/stacktrace.h"
#endif // OR_TOOLS_UTIL_DETERMINISTIC_TIME_PROFILING
namespace operations_research::sat {
#ifdef OR_TOOLS_UTIL_DETERMINISTIC_TIME_PROFILING
namespace profiling {
std::vector<void*> GetTimerStackTrace() {
constexpr int kMaxDepth = 50;
std::vector<void*> result(kMaxDepth);
int depth = absl::GetStackTrace(result.data(), kMaxDepth, /*skip_count=*/2);
for (int i = 0; i < depth; ++i) {
// This seems necessary to get the exact line number of the deterministic
// timer constructor in the profile (otherwise we get the line of the next
// statement, possibly after some local variable declarations).
result[i] =
reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(result[i]) - 1);
}
result.resize(depth);
return result;
}
} // namespace profiling
AllDeterministicTimeStats::~AllDeterministicTimeStats() {
for (const auto& [source_location, stats] : all_stats_) {
const auto& [file, line] = source_location;
std::cout << "dtime stats: " << file << "," << line << ","
<< stats.ToString() << std::endl;
}
for (const auto& [source_location, stats] : all_stats2_) {
const auto& [file, line] = source_location;
std::cout << "dtime2 stats: " << file << "," << line << ","
<< stats.ToString() << std::endl;
}
}
thread_local std::stack<AbstractDeterministicTimer*>
AbstractDeterministicTimer::timers_stack_;
#endif // OR_TOOLS_UTIL_DETERMINISTIC_TIME_PROFILING
} // namespace operations_research::sat