RDKit
Open-source cheminformatics and machine learning.
DebugTrace.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014 Novartis Institutes for BioMedical Research
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #include <RDGeneral/export.h>
11 #pragma once
12 #include <stdio.h>
13 #include <string.h>
14 #include <stddef.h>
15 #include <time.h>
16 #include <iostream>
17 #ifdef _MSC_VER
18 #define _CRT_SECURE_NO_WARNINGS
19 #include <Windows.h> // for Winmm.lib timeGetTime()
20 #ifdef _DEBUG // check memory leaks
21 #include <crtdbg.h>
22 #define _CRTDBG_MAP_ALLOC
23 #ifndef new
24 #define new new (_NORMAL_BLOCK, __FILE__, __LINE__)
25 #endif
26 #endif
27 #else
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <sys/time.h>
31 #ifndef _WIN32
32 #include <sys/resource.h>
33 #endif
34 #endif
35 
36 // SELECT ALGORITHM OPTIONS by comment some lines to exclude additional or
37 // experimental optimisations:
38 
39 #define SEED_GROW_DEEP // fast and works much times faster (but it can depend
40  // on molecules)
41 //#define EXCLUDE_WRONG_COMPOSITION // fast but with a little effect, because
42 // amount of external bonds usually is very small.
43 // Exclude mismatched bonds combinations during seed growing (2^N-1 stage)
44 
45 #define FAST_SUBSTRUCT_CACHE // based on a hash of Morgan code
46 #define DUP_SUBSTRUCT_CACHE // based on list of query atoms and bonds. For
47  // rings where seeds growing in both directions
48  // throw the same ring.
49 
50 #define FAST_INCREMENTAL_MATCH // fast and some time very usefull. request
51  // PRECOMPUTED_TABLES_MATCH
52 // previous match result based match checking without finding new matched
53 // substructure location in the target
54 
55 #define VERBOSE_STATISTICS_ON
56 
57 #ifdef _MSC_VER
58 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
59 
60 struct timezone {
61  int tz_minuteswest; // minutes W of Greenwich
62  int tz_dsttime; // type of dst correction
63 };
64 
65 static inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
66  FILETIME ft;
67  unsigned __int64 tmpres = 0;
68  static int tzflag;
69 
70  if (NULL != tv) {
71  GetSystemTimeAsFileTime(&ft);
72 
73  tmpres |= ft.dwHighDateTime;
74  tmpres <<= 32;
75  tmpres |= ft.dwLowDateTime;
76 
77  // converting file time to unix epoch
78  tmpres -= DELTA_EPOCH_IN_MICROSECS;
79  tmpres /= 10; // convert into microseconds
80  tv->tv_sec = (long)(tmpres / 1000000UL);
81  tv->tv_usec = (long)(tmpres % 1000000UL);
82  }
83 
84  if (NULL != tz) {
85  if (!tzflag) {
86  _tzset();
87  tzflag++;
88  }
89  tz->tz_minuteswest = _timezone / 60;
90  tz->tz_dsttime = _daylight;
91  }
92  return 0;
93 }
94 #endif
95 
96 static inline unsigned long long nanoClock(
97  void) { // actually returns microseconds
98  struct timeval t;
99  gettimeofday(&t, (struct timezone *)0);
100  return t.tv_usec + t.tv_sec * 1000000ULL;
101 }
102 
103 namespace RDKit {
104 namespace FMCS {
105 
106 #ifdef VERBOSE_STATISTICS_ON
107 
108 // compute statistics of really very very fast calls.
109 // It a bit decrease overal performance, but might be interested for
110 // investigation purpose (only)
111 //#define VERBOSE_STATISTICS_FASTCALLS_ON
112 
114  unsigned TotalSteps, MCSFoundStep;
115  unsigned long long MCSFoundTime;
116  unsigned InitialSeed, MismatchedInitialSeed;
117  unsigned Seed, RemainingSizeRejected;
118  unsigned SeedCheck, SingleBondExcluded;
119  unsigned MatchCall, MatchCallTrue;
120  unsigned FastMatchCall, FastMatchCallTrue, SlowMatchCallTrue;
121  unsigned ExactMatchCall, ExactMatchCallTrue; // hash cache
122  unsigned FindHashInCache, HashKeyFoundInCache;
123  unsigned AtomCompareCalls, BondCompareCalls; // long long
124  unsigned AtomFunctorCalls, BondFunctorCalls; // long long
125  unsigned WrongCompositionRejected, WrongCompositionDetected;
126  unsigned DupCacheFound, DupCacheFoundMatch;
127 
129  : TotalSteps(0),
130  MCSFoundStep(0),
131  MCSFoundTime(nanoClock()),
132  InitialSeed(0),
133  MismatchedInitialSeed(0),
134  Seed(0),
135  RemainingSizeRejected(0),
136  SeedCheck(0),
137  SingleBondExcluded(0),
138  MatchCall(0),
139  MatchCallTrue(0),
140  FastMatchCall(0),
141  FastMatchCallTrue(0),
142  SlowMatchCallTrue(0),
143  ExactMatchCall(0),
144  ExactMatchCallTrue(0),
145  FindHashInCache(0),
146  HashKeyFoundInCache(0),
147  AtomCompareCalls(0),
148  BondCompareCalls(0),
149  AtomFunctorCalls(0),
150  BondFunctorCalls(0),
151  WrongCompositionRejected(0),
152  WrongCompositionDetected(0),
153  DupCacheFound(0),
154  DupCacheFoundMatch(0) {}
155 };
156 #endif
157 }
158 }
static unsigned long long nanoClock(void)
Definition: DebugTrace.h:96
Std stuff.
Definition: Atom.h:30
unsigned long long MCSFoundTime
Definition: DebugTrace.h:115