5353 }
5454
5555#if openPMD_HAVE_ADIOS2
56+
57+ /*
58+ * Logging helper for ADIOS2 API calls to enable quick construction of
59+ * reproducers for bug reports. Output is formatted as C++ code.
60+ * Controlled by environment variable OPENPMD_ADIOS2_LOG_API_CALLS
61+ */
62+ namespace
63+ {
64+ inline bool shouldLogADIOS2ApiCalls ()
65+ {
66+ static int cached_result = -1 ;
67+ if (cached_result == -1 )
68+ {
69+ cached_result =
70+ openPMD::auxiliary::getEnvNum (" OPENPMD_ADIOS2_LOG_API_CALLS" , 0 );
71+ }
72+ return cached_result != 0 ;
73+ }
74+ } // namespace
75+
76+ #define ADIOS2_LOG_API_CALL (...) \
77+ do \
78+ { \
79+ if (::shouldLogADIOS2ApiCalls ()) \
80+ { \
81+ std::cerr << " [ADIOS2 API] " << __VA_ARGS__ << std::endl; \
82+ } \
83+ } while (false )
84+
5685namespace openPMD ::detail
5786{
5887template <typename T>
@@ -81,6 +110,7 @@ void DatasetReader::call(
81110 }
82111 auto ptr = std::static_pointer_cast<T>(bp.param .data ).get ();
83112 engine.Get (var, ptr);
113+ ADIOS2_LOG_API_CALL (" engine.Get(var, ptr);" );
84114}
85115
86116template <class >
@@ -111,6 +141,7 @@ void WriteDataset::call(ADIOS2File &ba, detail::BufferedPut &bp)
111141 ba.variables ());
112142
113143 engine.Put (var, ptr);
144+ ADIOS2_LOG_API_CALL (" engine.Put(var, ptr);" );
114145 }
115146 else if constexpr (std::is_same_v<
116147 ptr_type,
@@ -182,6 +213,7 @@ struct RunUniquePtrPut
182213 std::nullopt ,
183214 ba.variables ());
184215 engine.Put (var, ptr);
216+ ADIOS2_LOG_API_CALL (" engine.Put(var, ptr);" );
185217 }
186218
187219 static constexpr char const *errorMsg = " RunUniquePtrPut" ;
@@ -262,6 +294,7 @@ void ADIOS2File::finalize()
262294 if (streamStatus == StreamStatus::DuringStep)
263295 {
264296 engine.EndStep ();
297+ ADIOS2_LOG_API_CALL (" engine.EndStep();" );
265298 }
266299 engine.Close ();
267300 m_ADIOS.RemoveIO (m_IOName);
@@ -809,6 +842,7 @@ adios2::Engine &ADIOS2File::getEngine()
809842 m_engine =
810843 std::make_optional (adios2::Engine (m_IO.Open (m_file, tempMode)));
811844 m_engine->BeginStep ();
845+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
812846 streamStatus = StreamStatus::DuringStep;
813847 break ;
814848 }
@@ -833,10 +867,12 @@ adios2::Engine &ADIOS2File::getEngine()
833867 */
834868 if (m_engine->BeginStep () != adios2::StepStatus::OK)
835869 {
870+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
836871 throw std::runtime_error (
837872 " [ADIOS2] Unexpected step status when "
838873 " opening file/stream." );
839874 }
875+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
840876 openedANewStep = true ;
841877 }
842878
@@ -930,10 +966,15 @@ adios2::Engine &ADIOS2File::getEngine()
930966 m_engine.value ().BeginStep () !=
931967 adios2::StepStatus::OK)
932968 {
969+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
933970 throw std::runtime_error (
934971 " [ADIOS2] Unexpected step status when "
935972 " opening file/stream." );
936973 }
974+ if (!openedANewStep)
975+ {
976+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
977+ }
937978 streamStatus = StreamStatus::DuringStep;
938979 }
939980 }
@@ -1136,11 +1177,13 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11361177 entry.run (*this );
11371178 }
11381179 engine.PerformDataWrite ();
1180+ ADIOS2_LOG_API_CALL (" engine.PerformDataWrite();" );
11391181 m_uniquePtrPuts.clear ();
11401182 m_updateSpans.clear ();
11411183 break ;
11421184 case CleanedFlushTarget::Buffer:
11431185 engine.PerformPuts ();
1186+ ADIOS2_LOG_API_CALL (" engine.PerformPuts();" );
11441187 break ;
11451188 case CleanedFlushTarget::Step:
11461189 if (streamStatus != StreamStatus::DuringStep)
@@ -1158,7 +1201,9 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11581201 entry.run (*this );
11591202 }
11601203 engine.EndStep ();
1204+ ADIOS2_LOG_API_CALL (" engine.EndStep();" );
11611205 engine.BeginStep ();
1206+ ADIOS2_LOG_API_CALL (" engine.BeginStep();" );
11621207 m_uniquePtrPuts.clear ();
11631208 uncommittedAttributes.clear ();
11641209 m_updateSpans.clear ();
@@ -1182,6 +1227,7 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11821227 else
11831228 {
11841229 eng.PerformGets ();
1230+ ADIOS2_LOG_API_CALL (" engine.PerformGets();" );
11851231 }
11861232 },
11871233 writeLatePuts,
0 commit comments