RDKit: DebugTrace.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
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 <cstdio>
13#include <cstring>
14#include <cstddef>
15#include <ctime>
16#ifdef _MSC_VER
17#define _CRT_SECURE_NO_WARNINGS
18#define NOMINMAX
19#include <Winsock2.h> // for timeval
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 useful. 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
60struct timezone {
61 int tz_minuteswest; // minutes W of Greenwich
62 int tz_dsttime; // type of dst correction
63};
64
65static inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
66 FILETIME ft;
67 unsigned __int64 tmpres = 0;
68 static int tzflag;
69
70 if (nullptr != 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 (nullptr != 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 *)nullptr);
100 return t.tv_usec + t.tv_sec * 1000000ULL;
101}
102
103namespace RDKit {
104namespace 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
113 struct ExecStatistics {
114 unsigned int TotalSteps{0}, MCSFoundStep{0};
115 unsigned long long MCSFoundTime;
116 unsigned int InitialSeed{0}, MismatchedInitialSeed{0};
117 unsigned int Seed{0}, RemainingSizeRejected{0};
118 unsigned int SeedCheck{0}, IndividualBondExcluded{0};
119 unsigned int MatchCall{0}, MatchCallTrue{0};
120 unsigned int FastMatchCall{0}, FastMatchCallTrue{0}, SlowMatchCallTrue{0};
121 unsigned int ExactMatchCall{0}, ExactMatchCallTrue{0}; // hash cache
122 unsigned int FindHashInCache{0}, HashKeyFoundInCache{0};
123 unsigned int AtomCompareCalls{0}, BondCompareCalls{0};
124 unsigned int AtomFunctorCalls{0}, BondFunctorCalls{0};
125 unsigned int WrongCompositionRejected{0}, WrongCompositionDetected{0};
126 unsigned int DupCacheFound{0}, DupCacheFoundMatch{0};
127
128 ExecStatistics() : MCSFoundTime(nanoClock()) {}
129};
130#endif
131} // namespace FMCS
132} // namespace RDKit
nanoClock
static unsigned long long nanoClock(void)
Definition DebugTrace.h:96
export.h
RDKit::FMCS
Definition Composition2N.h:13
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::FMCS::ExecStatistics::Seed
unsigned int Seed
Definition DebugTrace.h:117
RDKit::FMCS::ExecStatistics::MCSFoundTime
unsigned long long MCSFoundTime
Definition DebugTrace.h:115
RDKit::FMCS::ExecStatistics::DupCacheFound
unsigned int DupCacheFound
Definition DebugTrace.h:126
RDKit::FMCS::ExecStatistics::FastMatchCall
unsigned int FastMatchCall
Definition DebugTrace.h:120
RDKit::FMCS::ExecStatistics::SeedCheck
unsigned int SeedCheck
Definition DebugTrace.h:118
RDKit::FMCS::ExecStatistics::RemainingSizeRejected
unsigned int RemainingSizeRejected
Definition DebugTrace.h:117
RDKit::FMCS::ExecStatistics::BondCompareCalls
unsigned int BondCompareCalls
Definition DebugTrace.h:123
RDKit::FMCS::ExecStatistics::ExecStatistics
ExecStatistics()
Definition DebugTrace.h:128
RDKit::FMCS::ExecStatistics::MCSFoundStep
unsigned int MCSFoundStep
Definition DebugTrace.h:114
RDKit::FMCS::ExecStatistics::WrongCompositionDetected
unsigned int WrongCompositionDetected
Definition DebugTrace.h:125
RDKit::FMCS::ExecStatistics::FastMatchCallTrue
unsigned int FastMatchCallTrue
Definition DebugTrace.h:120
RDKit::FMCS::ExecStatistics::DupCacheFoundMatch
unsigned int DupCacheFoundMatch
Definition DebugTrace.h:126
RDKit::FMCS::ExecStatistics::MatchCall
unsigned int MatchCall
Definition DebugTrace.h:119
RDKit::FMCS::ExecStatistics::MismatchedInitialSeed
unsigned int MismatchedInitialSeed
Definition DebugTrace.h:116
RDKit::FMCS::ExecStatistics::FindHashInCache
unsigned int FindHashInCache
Definition DebugTrace.h:122
RDKit::FMCS::ExecStatistics::SlowMatchCallTrue
unsigned int SlowMatchCallTrue
Definition DebugTrace.h:120
RDKit::FMCS::ExecStatistics::InitialSeed
unsigned int InitialSeed
Definition DebugTrace.h:116
RDKit::FMCS::ExecStatistics::ExactMatchCallTrue
unsigned int ExactMatchCallTrue
Definition DebugTrace.h:121
RDKit::FMCS::ExecStatistics::AtomFunctorCalls
unsigned int AtomFunctorCalls
Definition DebugTrace.h:124
RDKit::FMCS::ExecStatistics::MatchCallTrue
unsigned int MatchCallTrue
Definition DebugTrace.h:119
RDKit::FMCS::ExecStatistics::IndividualBondExcluded
unsigned int IndividualBondExcluded
Definition DebugTrace.h:118
RDKit::FMCS::ExecStatistics::WrongCompositionRejected
unsigned int WrongCompositionRejected
Definition DebugTrace.h:125
RDKit::FMCS::ExecStatistics::HashKeyFoundInCache
unsigned int HashKeyFoundInCache
Definition DebugTrace.h:122
RDKit::FMCS::ExecStatistics::AtomCompareCalls
unsigned int AtomCompareCalls
Definition DebugTrace.h:123
RDKit::FMCS::ExecStatistics::BondFunctorCalls
unsigned int BondFunctorCalls
Definition DebugTrace.h:124
RDKit::FMCS::ExecStatistics::ExactMatchCall
unsigned int ExactMatchCall
Definition DebugTrace.h:121
RDKit::FMCS::ExecStatistics::TotalSteps
unsigned int TotalSteps
Definition DebugTrace.h:114