add debug option to log all SQL commands (#8324)

This commit is contained in:
Arvid Norberg 2021-09-03 23:13:45 +02:00 committed by GitHub
parent 2db9944687
commit 6d60bfd58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -58,6 +58,7 @@ from chia.util.ints import uint8, uint32, uint64, uint128
from chia.util.path import mkdir, path_from_root
from chia.util.safe_cancel_task import cancel_task_safe
from chia.util.profiler import profile_task
from datetime import datetime
class FullNode:
@ -121,6 +122,17 @@ class FullNode:
self.new_peak_sem = asyncio.Semaphore(8)
# create the store (db) and full node instance
self.connection = await aiosqlite.connect(self.db_path)
if self.config.get("log_sqlite_cmds", False):
sql_log_path = path_from_root(self.root_path, "log/sql.log")
self.log.info(f"logging SQL commands to {sql_log_path}")
def sql_trace_callback(req: str):
timestamp = datetime.now().strftime("%H:%M:%S.%f")
log = open(sql_log_path, "a")
log.write(timestamp + " " + req + "\n")
log.close()
await self.connection.set_trace_callback(sql_trace_callback)
self.db_wrapper = DBWrapper(self.connection)
self.block_store = await BlockStore.create(self.db_wrapper)
self.sync_store = await SyncStore.create()

View File

@ -304,6 +304,10 @@ full_node:
# analyze with chia/utils/profiler.py
enable_profiler: False
# this is a debug and profiling facility that logs all SQLite commands to a
# separate log file (under logging/sql.log).
log_sqlite_cmds: False
# List of trusted DNS seeders to bootstrap from.
# If you modify this, please change the hardcode as well from FullNode.set_server()
dns_servers: