Fixes so that DDS_AB_STATS will work when it's set.#195
Conversation
Including debug.h from thread_data.hpp exposed a global named counter that conflicts with pybind11 on MSVC when warnings are treated as errors. Co-authored-by: Cursor <cursoragent@cursor.com>
|
I think we should prefer |
|
I will give this a more careful review once I have a bit more time. We are out of Copilot cycles for the month of June. |
|
There's no hurry! In any case, I suggest the |
There was a problem hiding this comment.
Pull request overview
This PR fixes build/runtime behavior when compiling DDS with DDS_AB_STATS enabled by making the AB-stats code linkable via Bazel targets and by reworking how debug/stat output files are named/opened/closed via SolverContext/ThreadData.
Changes:
- Adds a dedicated
ab_statsBazel target and wires it intodds/systembuilds. - Introduces a
Filehelper for lazy debug/stat file creation and integrates it intoThreadData. - Moves debug file lifecycle to
SolverContext(open/init on bind, close on destruction) and removes unused debug counter declarations.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| library/src/utility/debug.h | Removes unused performance counter declarations. |
| library/src/system/thread_data.hpp | Includes debug/file headers and conditionally enables debug file support. |
| library/src/system/file.hpp | Adds dds::File interface for lazy debug/stat logging output streams. |
| library/src/system/file.cpp | Implements File open/close/reset behavior. |
| library/src/system/BUILD.bazel | Adds ab_stats dependency to system libraries. |
| library/src/solver_context/solver_context.hpp | Refactors constructor to bind thread data via helper. |
| library/src/solver_context/solver_context.cpp | Implements debug-file suffixing and ties debug file lifecycle to SolverContext. |
| library/src/init.cpp | Removes legacy debug-file close loop (now handled by SolverContext). |
| library/src/BUILD.bazel | Adds ab_stats library target and updates source glob exclusions/deps. |
Only owning SolverContext instances should open or close per-thread debug files; helper contexts that wrap existing ThreadData must not reassign names mid-solve or close streams still in use by the primary context. Co-authored-by: Cursor <cursoragent@cursor.com>
Track whether debug files were opened on ThreadData and defer close until ~SolverContext() sees use_count() == 1, so shared/helper contexts do not close streams while another context is still writing. Co-authored-by: Cursor <cursoragent@cursor.com>
Reset() previously cleared the filename and file_open_ flag without closing an already-open ofstream, which could leak handles and leave stale streams. Co-authored-by: Cursor <cursoragent@cursor.com>
SetName() previously updated fname_ while leaving an open ofstream on the old path, so later writes could go to the wrong file. Co-authored-by: Cursor <cursoragent@cursor.com>
GetStream() previously set file_open_ even when open() failed, leaving the object stuck with a closed but supposedly-open stream; skip open on empty names and rely on is_open() for lazy open and close. Co-authored-by: Cursor <cursoragent@cursor.com>
Per-context debug files are closed in ~SolverContext(); the empty CloseDebugFiles() stub and library unload calls are no longer needed. Co-authored-by: Cursor <cursoragent@cursor.com>
Drop the global using alias from file.hpp so File stays in namespace dds and callers reference it explicitly. Co-authored-by: Cursor <cursoragent@cursor.com>
Document that SolverContext passes "<serial>.txt" rather than a thread-id suffix, so debug output filenames are easier to trace. Co-authored-by: Cursor <cursoragent@cursor.com>
SearchContext kept a second shared_ptr, so use_count() was never 1 during destruction and close_debug_files() never ran; release that reference first. Co-authored-by: Cursor <cursoragent@cursor.com>
Add direct headers for std::min and std::snprintf instead of relying on transitive includes from other headers. Co-authored-by: Cursor <cursoragent@cursor.com>
Document that wrapper contexts skip init but may close debug files when they are the last shared_ptr holder of the ThreadData. Co-authored-by: Cursor <cursoragent@cursor.com>
| "//library/src/trans_table", | ||
| "//library/src/moves:moves", | ||
| "//library/src:ab_stats", | ||
| "//library/src/system", | ||
| "//library/src/solver_context:solver_context", |
Exclude ab_stats.cpp from testable_dds_sources and link //library/src:ab_stats explicitly, matching :dds and preventing duplicate ABstats symbols. Co-authored-by: Cursor <cursoragent@cursor.com>
I've tested this locally with
bazel build //library/tests:dtest --cxxopt=-DDDS_AB_STATS. A dtest run then produces ABstats*.txt files, as it ought to. The build fails without this PR.We should either merge this PR or else remove the DDS_AB_STATS code entirely.
Another possible enhancement would be to mirror the DDS_SCHEDULER pattern, so that we can use
--define=ab_stats=trueinstead of--cxxopt.