You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
5.4 KiB

  1. /*
  2. * Copyright 2011-2016 Formal Methods and Tools, University of Twente
  3. * Copyright 2016-2017 Tom van Dijk, Johannes Kepler University Linz
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* Do not include this file directly. Instead, include sylvan.h */
  18. #ifndef SYLVAN_STATS_H
  19. #define SYLVAN_STATS_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif /* __cplusplus */
  23. #define OPCOUNTER(NAME) NAME, NAME ## _CACHEDPUT, NAME ## _CACHED
  24. typedef enum {
  25. /* Creating nodes */
  26. BDD_NODES_CREATED,
  27. BDD_NODES_REUSED,
  28. LDD_NODES_CREATED,
  29. LDD_NODES_REUSED,
  30. /* BDD operations */
  31. OPCOUNTER(BDD_ITE),
  32. OPCOUNTER(BDD_AND),
  33. OPCOUNTER(BDD_XOR),
  34. OPCOUNTER(BDD_EXISTS),
  35. OPCOUNTER(BDD_PROJECT),
  36. OPCOUNTER(BDD_AND_EXISTS),
  37. OPCOUNTER(BDD_AND_PROJECT),
  38. OPCOUNTER(BDD_RELNEXT),
  39. OPCOUNTER(BDD_RELPREV),
  40. OPCOUNTER(BDD_SATCOUNT),
  41. OPCOUNTER(BDD_COMPOSE),
  42. OPCOUNTER(BDD_RESTRICT),
  43. OPCOUNTER(BDD_CONSTRAIN),
  44. OPCOUNTER(BDD_CLOSURE),
  45. OPCOUNTER(BDD_ISBDD),
  46. OPCOUNTER(BDD_SUPPORT),
  47. OPCOUNTER(BDD_PATHCOUNT),
  48. /* MTBDD operations */
  49. OPCOUNTER(MTBDD_APPLY),
  50. OPCOUNTER(MTBDD_UAPPLY),
  51. OPCOUNTER(MTBDD_ABSTRACT),
  52. OPCOUNTER(MTBDD_ITE),
  53. OPCOUNTER(MTBDD_EQUAL_NORM),
  54. OPCOUNTER(MTBDD_EQUAL_NORM_REL),
  55. OPCOUNTER(MTBDD_LEQ),
  56. OPCOUNTER(MTBDD_LESS),
  57. OPCOUNTER(MTBDD_GEQ),
  58. OPCOUNTER(MTBDD_GREATER),
  59. OPCOUNTER(MTBDD_AND_ABSTRACT_PLUS),
  60. OPCOUNTER(MTBDD_AND_ABSTRACT_MAX),
  61. OPCOUNTER(MTBDD_COMPOSE),
  62. OPCOUNTER(MTBDD_MINIMUM),
  63. OPCOUNTER(MTBDD_MAXIMUM),
  64. OPCOUNTER(MTBDD_EVAL_COMPOSE),
  65. /* LDD operations */
  66. OPCOUNTER(LDD_UNION),
  67. OPCOUNTER(LDD_MINUS),
  68. OPCOUNTER(LDD_INTERSECT),
  69. OPCOUNTER(LDD_RELPROD),
  70. OPCOUNTER(LDD_RELPREV),
  71. OPCOUNTER(LDD_PROJECT),
  72. OPCOUNTER(LDD_JOIN),
  73. OPCOUNTER(LDD_MATCH),
  74. OPCOUNTER(LDD_SATCOUNT),
  75. OPCOUNTER(LDD_SATCOUNTL),
  76. OPCOUNTER(LDD_ZIP),
  77. OPCOUNTER(LDD_RELPROD_UNION),
  78. OPCOUNTER(LDD_PROJECT_MINUS),
  79. /* Other counters */
  80. SYLVAN_GC_COUNT,
  81. LLMSSET_LOOKUP,
  82. SYLVAN_COUNTER_COUNTER
  83. } Sylvan_Counters;
  84. #undef OPCOUNTER
  85. typedef enum
  86. {
  87. SYLVAN_GC,
  88. SYLVAN_TIMER_COUNTER
  89. } Sylvan_Timers;
  90. typedef struct
  91. {
  92. uint64_t counters[SYLVAN_COUNTER_COUNTER];
  93. /* the timers are in ns */
  94. uint64_t timers[SYLVAN_TIMER_COUNTER];
  95. /* startstop is for internal use */
  96. uint64_t timers_startstop[SYLVAN_TIMER_COUNTER];
  97. } sylvan_stats_t;
  98. /**
  99. * Initialize stats system (done by sylvan_init_package)
  100. */
  101. VOID_TASK_DECL_0(sylvan_stats_init);
  102. #define sylvan_stats_init() CALL(sylvan_stats_init)
  103. /**
  104. * Reset all counters (for statistics)
  105. */
  106. VOID_TASK_DECL_0(sylvan_stats_reset);
  107. #define sylvan_stats_reset() CALL(sylvan_stats_reset)
  108. /**
  109. * Obtain current counts (this stops the world during counting)
  110. */
  111. VOID_TASK_DECL_1(sylvan_stats_snapshot, sylvan_stats_t*);
  112. #define sylvan_stats_snapshot(target) CALL(sylvan_stats_snapshot, target)
  113. /**
  114. * Write statistic report to file (stdout, stderr, etc)
  115. */
  116. void sylvan_stats_report(FILE* target);
  117. #if SYLVAN_STATS
  118. #ifdef __MACH__
  119. #define getabstime() mach_absolute_time()
  120. #else
  121. static uint64_t
  122. getabstime(void)
  123. {
  124. struct timespec ts;
  125. clock_gettime(CLOCK_MONOTONIC, &ts);
  126. uint64_t t = ts.tv_sec;
  127. t *= 1000000000UL;
  128. t += ts.tv_nsec;
  129. return t;
  130. }
  131. #endif
  132. #ifdef __ELF__
  133. extern __thread sylvan_stats_t sylvan_stats;
  134. #else
  135. extern pthread_key_t sylvan_stats_key;
  136. #endif
  137. static inline void
  138. sylvan_stats_count(size_t counter)
  139. {
  140. #ifdef __ELF__
  141. sylvan_stats.counters[counter]++;
  142. #else
  143. sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
  144. sylvan_stats->counters[counter]++;
  145. #endif
  146. }
  147. static inline void
  148. sylvan_stats_add(size_t counter, size_t amount)
  149. {
  150. #ifdef __ELF__
  151. sylvan_stats.counters[counter]+=amount;
  152. #else
  153. sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
  154. sylvan_stats->counters[counter]+=amount;
  155. #endif
  156. }
  157. static inline void
  158. sylvan_timer_start(size_t timer)
  159. {
  160. uint64_t t = getabstime();
  161. #ifdef __ELF__
  162. sylvan_stats.timers_startstop[timer] = t;
  163. #else
  164. sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
  165. sylvan_stats->timers_startstop[timer] = t;
  166. #endif
  167. }
  168. static inline void
  169. sylvan_timer_stop(size_t timer)
  170. {
  171. uint64_t t = getabstime();
  172. #ifdef __ELF__
  173. sylvan_stats.timers[timer] += (t - sylvan_stats.timers_startstop[timer]);
  174. #else
  175. sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
  176. sylvan_stats->timers[timer] += (t - sylvan_stats->timers_startstop[timer]);
  177. #endif
  178. }
  179. #else
  180. static inline void
  181. sylvan_stats_count(size_t counter)
  182. {
  183. (void)counter;
  184. }
  185. static inline void
  186. sylvan_stats_add(size_t counter, size_t amount)
  187. {
  188. (void)counter;
  189. (void)amount;
  190. }
  191. static inline void
  192. sylvan_timer_start(size_t timer)
  193. {
  194. (void)timer;
  195. }
  196. static inline void
  197. sylvan_timer_stop(size_t timer)
  198. {
  199. (void)timer;
  200. }
  201. #endif
  202. #ifdef __cplusplus
  203. }
  204. #endif /* __cplusplus */
  205. #endif