ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_profile.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#ifndef CADICAL_QUIET
4
5#include "internal.hpp"
6
8
9namespace CaDiCaL {
10
11// Initialize all profile counters with constant name and profiling level.
12
13Profiles::Profiles (Internal *s)
14 : internal (s)
15#define PROFILE(NAME, LEVEL) , NAME (#NAME, LEVEL)
16 PROFILES
17#undef PROFILE
18{
19}
20
21void Internal::start_profiling (Profile &profile, double s) {
22 CADICAL_assert (profile.level <= opts.profile);
23 CADICAL_assert (!profile.active);
24 profile.started = s;
25 profile.active = true;
26}
27
28void Internal::stop_profiling (Profile &profile, double s) {
29 CADICAL_assert (profile.level <= opts.profile);
30 CADICAL_assert (profile.active);
31 profile.value += s - profile.started;
32 profile.active = false;
33}
34
35double Internal::update_profiles () {
36 double now = time ();
37#define PROFILE(NAME, LEVEL) \
38 do { \
39 Profile &profile = profiles.NAME; \
40 if (profile.active) { \
41 CADICAL_assert (profile.level <= opts.profile); \
42 profile.value += now - profile.started; \
43 profile.started = now; \
44 } \
45 } while (0);
46 PROFILES
47#undef PROFILE
48 return now;
49}
50
51double Internal::solve_time () {
52 (void) update_profiles ();
53 return profiles.solve.value;
54}
55
56#define PRT(S, T) \
57 MSG ("%s" S "%s", tout.magenta_code (), T, tout.normal_code ())
58
59void Internal::print_profile () {
60 double now = update_profiles ();
61 const char *time_type = opts.realtime ? "real" : "process";
62 SECTION ("run-time profiling");
63 PRT ("%s time taken by individual solving procedures", time_type);
64 PRT ("(percentage relative to %s time for solving)", time_type);
65 LINE ();
66 const size_t size = sizeof profiles / sizeof (Profile);
67 struct Profile *profs[size];
68 size_t n = 0;
69#define PROFILE(NAME, LEVEL) \
70 do { \
71 if (LEVEL > opts.profile) \
72 break; \
73 Profile *p = &profiles.NAME; \
74 if (p == &profiles.solve) \
75 break; \
76 if (!profiles.NAME.value && p != &profiles.parse && \
77 p != &profiles.search && p != &profiles.simplify) \
78 break; \
79 profs[n++] = p; \
80 } while (0);
81 PROFILES
82#undef PROFILE
83
84 CADICAL_assert (n <= size);
85
86 // Explicit bubble sort to avoid heap allocation since 'print_profile'
87 // is also called during catching a signal after out of heap memory.
88 // This only makes sense if 'profs' is allocated on the stack, and
89 // not the heap, which should be the case.
90
91 double solve = profiles.solve.value;
92
93 for (size_t i = 0; i < n; i++) {
94 for (size_t j = i + 1; j < n; j++)
95 if (profs[j]->value > profs[i]->value)
96 swap (profs[i], profs[j]);
97 MSG ("%12.2f %7.2f%% %s", profs[i]->value,
98 percent (profs[i]->value, solve), profs[i]->name);
99 }
100
101 MSG (" =================================");
102 MSG ("%12.2f %7.2f%% solve", solve, percent (solve, now));
103
104 LINE ();
105 PRT ("last line shows %s time for solving", time_type);
106 PRT ("(percentage relative to total %s time)", time_type);
107}
108
109} // namespace CaDiCaL
110
112
113#endif // ifndef CADICAL_QUIET
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define LEVEL(LIT)
Definition assign.h:34
#define CADICAL_assert(ignore)
Definition global.h:14
ABC_NAMESPACE_IMPL_START typedef signed char value
#define PRT(FMT,...)
@ NAME
Definition inflate.h:29
#define MSG(...)
Definition message.hpp:49
#define LINE()
Definition message.hpp:46
#define SECTION(...)
Definition message.hpp:55
char * name
Definition main.h:24
unsigned long long size
Definition giaNewBdd.h:39