ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
resources.c
Go to the documentation of this file.
1#include "resources.h"
2
3//#include <sys/time.h>
4
6
7/* double kissat_wall_clock_time (void) { */
8/* struct timeval tv; */
9/* if (gettimeofday (&tv, 0)) */
10/* return 0; */
11/* return 1e-6 * tv.tv_usec + tv.tv_sec; */
12/* } */
13
14#ifndef KISSAT_QUIET
15
16#include "internal.h"
17#include "statistics.h"
18#include "utilities.h"
19
20#include <inttypes.h>
21#include <stdio.h>
22#include <string.h>
23#include <sys/resource.h>
24#include <sys/types.h>
25#include <unistd.h>
26
27double kissat_process_time (void) {
28 struct rusage u;
29 double res;
30 if (getrusage (RUSAGE_SELF, &u))
31 return 0;
32 res = u.ru_utime.tv_sec + 1e-6 * u.ru_utime.tv_usec;
33 res += u.ru_stime.tv_sec + 1e-6 * u.ru_stime.tv_usec;
34 return res;
35}
36
37uint64_t kissat_maximum_resident_set_size (void) {
38 struct rusage u;
39 if (getrusage (RUSAGE_SELF, &u))
40 return 0;
41 return ((uint64_t) u.ru_maxrss) << 10;
42}
43
44#ifdef __APPLE__
45
46#include <mach/task.h>
47mach_port_t mach_task_self (void);
48
49uint64_t kissat_current_resident_set_size (void) {
50 struct task_basic_info info;
51 mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
52 if (KERN_SUCCESS != task_info (mach_task_self (), TASK_BASIC_INFO,
53 (task_info_t) &info, &count))
54 return 0;
55 return info.resident_size;
56}
57
58#else
59
60uint64_t kissat_current_resident_set_size (void) {
61 char path[48];
62 sprintf (path, "/proc/%" PRIu64 "/statm", (uint64_t) getpid ());
63 FILE *file = fopen (path, "r");
64 if (!file)
65 return 0;
66 uint64_t dummy, rss;
67 int scanned = fscanf (file, "%" PRIu64 " %" PRIu64 "", &dummy, &rss);
68 fclose (file);
69 return scanned == 2 ? rss * sysconf (_SC_PAGESIZE) : 0;
70}
71
72#endif
73
74void kissat_print_resources (kissat *solver) {
75 uint64_t rss = kissat_maximum_resident_set_size ();
76 double t = kissat_time (solver);
77 printf ("%s"
78 "%-" SFW1 "s "
79 "%" SFW2 PRIu64 " "
80 "%-" SFW3 "s "
81 "%" SFW4 ".0f "
82 "MB\n",
83 solver->prefix, "maximum-resident-set-size:", rss, "bytes",
84 rss / (double) (1 << 20));
85#ifdef METRICS
86 statistics *statistics = &solver->statistics;
87 uint64_t max_allocated = statistics->allocated_max + sizeof (kissat);
88 printf ("%s"
89 "%-" SFW1 "s "
90 "%" SFW2 PRIu64 " "
91 "%-" SFW3 "s "
92 "%" SFW4 ".0f "
93 "%%\n",
94 solver->prefix, "max-allocated:", max_allocated, "bytes",
95 kissat_percent (max_allocated, rss));
96#endif
97 {
98 format buffer;
99 memset (&buffer, 0, sizeof buffer);
100 printf ("%sprocess-time: %30s %18.2f seconds\n", solver->prefix,
101 kissat_format_time (&buffer, t), t);
102 }
103 fflush (stdout);
104}
105
106#endif
107
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
const char * kissat_format_time(kormat *format, double seconds)
Definition format.c:75
#define solver
Definition kitten.c:211
Definition file.h:23
char * memset()
char * sprintf()