1 /****************************************** 2 Copyright (c) 2016, Mate Soos 3 4 Permission is hereby granted, free of charge, to any person obtaining a copy 5 of this software and associated documentation files (the "Software"), to deal 6 in the Software without restriction, including without limitation the rights 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 copies of the Software, and to permit persons to whom the Software is 9 furnished to do so, subject to the following conditions: 10 11 The above copyright notice and this permission notice shall be included in 12 all copies or substantial portions of the Software. 13 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 THE SOFTWARE. 21 ***********************************************/ 22 23 #include "sqlstats.h" 24 #include "satzilla_features.h" 25 #include <sqlite3.h> 26 27 namespace CMSat { 28 29 class SQLiteStats: public SQLStats 30 { 31 public: 32 virtual ~SQLiteStats() override; 33 explicit SQLiteStats(std::string _filename); 34 35 void end_transaction() override; 36 void begin_transaction() override; 37 38 void time_passed( 39 const Solver* solver 40 , const string& name 41 , double time_passed 42 , bool time_out 43 , double percent_time_remain 44 ) override; 45 46 void time_passed_min( 47 const Solver* solver 48 , const string& name 49 , double time_passed 50 ) override; 51 52 void mem_used( 53 const Solver* solver 54 , const string& name 55 , double given_time 56 , uint64_t mem_used_mb 57 ) override; 58 59 void satzilla_features( 60 const Solver* solver 61 , const Searcher* search 62 , const SatZillaFeatures& satzilla_feat 63 ) override; 64 65 #ifdef STATS_NEEDED 66 void restart( 67 const uint32_t restartID 68 , const Restart rest_type 69 , const PropStats& thisPropStats 70 , const SearchStats& thisStats 71 , const Solver* solver 72 , const Searcher* searcher 73 , const rst_dat_type type 74 , const int64_t clauseID 75 ) override; 76 77 void reduceDB( 78 const Solver* solver 79 , const bool locked 80 , const Clause* cl 81 , const string& cur_restart_type 82 , const uint32_t act_ranking_top_10 83 , const uint32_t act_ranking 84 , const uint32_t tot_cls_in_db 85 ) override; 86 87 virtual void cl_last_in_solver( 88 const Solver* solver 89 , const uint64_t clid 90 ) override; 91 92 void dump_clause_stats( 93 const Solver* solver 94 , uint64_t clid 95 , const uint64_t restartID 96 , uint32_t orig_glue 97 , uint32_t glue_before_minim 98 , const uint32_t backtrack_level 99 , uint32_t size 100 , AtecedentData<uint16_t> resoltypes 101 , size_t decision_level 102 , size_t trail_depth 103 , uint64_t conflicts_this_restart 104 , const std::string& rest_type 105 , const SearchHist& hist 106 , const bool is_decision 107 ) override; 108 109 #ifdef STATS_NEEDED_BRANCH 110 void var_data_picktime( 111 const Solver* solver 112 , const uint32_t var 113 , const VarData& vardata 114 , const double rel_activity 115 ) override; 116 117 void var_data_fintime( 118 const Solver* solver 119 , const uint32_t var 120 , const VarData& vardata 121 , const double rel_activity 122 ) override; 123 124 void dec_var_clid( 125 const uint32_t var 126 , const uint64_t sumConflicts_at_picktime 127 , const uint64_t clid 128 ) override; 129 130 void var_dist( 131 const uint32_t var 132 , const VarData2& data 133 , const Solver* solver 134 ) override; 135 #endif 136 #endif 137 138 bool setup(const Solver* solver) override; 139 void finishup(lbool status) override; 140 void add_tag(const std::pair<std::string, std::string>& tag) override; 141 142 private: 143 144 bool connectServer(const Solver* solver); 145 bool add_solverrun(const Solver* solver); 146 void init(const char* name, sqlite3_stmt** stmt); 147 vector<string> get_columns(const char* tablename); 148 149 void addStartupData(); 150 void del_prepared_stmt(sqlite3_stmt* stmt); 151 void initRestartSTMT(const char* tablename, sqlite3_stmt** stmt); 152 void initTimePassedSTMT(); 153 void init_cl_last_in_solver_STMT(); 154 void initMemUsedSTMT(); 155 void init_clause_stats_STMT(); 156 void init_var_data_picktime_STMT(); 157 void init_var_data_fintime_STMT(); 158 void init_dec_var_clid_STMT(); 159 void run_sqlite_step(sqlite3_stmt* stmt, const char* name); 160 161 void writeQuestionMarks(size_t num, std::stringstream& ss); 162 void initReduceDBSTMT(); 163 164 sqlite3_stmt *stmtTimePassed = NULL; 165 sqlite3_stmt *stmtMemUsed = NULL; 166 sqlite3_stmt *stmtReduceDB = NULL; 167 sqlite3_stmt *stmtRst = NULL; 168 sqlite3_stmt *stmtVarRst = NULL; 169 sqlite3_stmt *stmtClRst = NULL; 170 sqlite3_stmt *stmtFeat = NULL; 171 sqlite3_stmt *stmt_clause_stats = NULL; 172 sqlite3_stmt *stmt_delete_cl = NULL; 173 sqlite3_stmt *stmt_var_data_fintime = NULL; 174 sqlite3_stmt *stmt_var_data_picktime = NULL; 175 sqlite3_stmt *stmt_dec_var_clid = NULL; 176 sqlite3_stmt *stmt_var_dist = NULL; 177 178 sqlite3 *db = NULL; 179 bool setup_ok = false; 180 const string filename; 181 }; 182 183 } 184