Implement SQLite stats logging#13124
Open
artemigkh wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements a more performant and structurally robust alternative to the existing CSV logging paradigm that drastically reduces the overhead of creating and managing hundreds of file handles, massively speeds up logging by reducing the raw amount of bytes needed to be written to disk, and structurally enforces a schema to avoid inconsistencies and escape character bugs in existing CSV logging.
The intended use-case is to speed up AI-only automation games as well as massively simplify downstream analysis of AI autoplay data by removing the need for parsing and aggregating hundreds of GB of logs into tabular data. Though of course the community may find other uses for this framework, as well as lower the barrier to entry for DLL modders to implement stats they may want tracked over autoplay runs.
Usage
Clear and straightforward instructions for getting started using this framework, as well as examples and other important information are thoroughly documented at the top of
CvGameCoreDLL_Expansion2/SqliteLogger.hand this is the intended starting point for anyone wanting to understand or start using the logger.Enabling
Logging is gated behind the
SQLITE_LOGGINGcustom mod option and is off by default. Enable it by setting the option in the database:As a quick simplified example of how the logger is invoked:
Implementation Details
CvGameobject in order to identify and persist game instances, potentially across game saves and loadsuuid_dictionarytable whichCvGameresolves and caches whenMOD_SQLITE_LOGGINGis enabled. Each game's UUID is stored there as a 32-char uppercase hex string (dashes stripped) in a TEXT column, keyed to the compact integer id that stat rows reference.SqliteLoggersingleton, which is accessed viaGET_SQLITE_LOGGER()and is responsible for creating tables, storing/managing/verifying table schemas, and handling the validation and inserts for row writesstats.dbis created in thecachedirectory alongside the other SQLite filesSqliteLoggermanager also caches prepared insert statements for each table and reuses them to speed up writesstats.dbit is recreated with the new registered schema.CvGameCoreDLL_Expansion2/SqliteLogger.hSqliteLoggeroperations are gated behindMOD_SQLITE_LOGGINGand do not depend onGC.getLogging()being enabled. No cost when the flag is disabled asstats.dbis lazily opened on first writeCurrently Implemented Logging
Currently, the following game information is logged to
stats.db:MilitarySummary.csvWorldState_Log.csvFuture Work
Naturally this PR represents only a starting point, and much more work around this is planned in the future: