From ba0940141fe09a6673623b98b18b03bc6af0c90e Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 3 Oct 2025 14:49:30 +0200 Subject: [PATCH 1/5] Create in ansys.dpf.core.debug --- src/ansys/dpf/core/debug.py | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/ansys/dpf/core/debug.py diff --git a/src/ansys/dpf/core/debug.py b/src/ansys/dpf/core/debug.py new file mode 100644 index 0000000000..a9247b2d30 --- /dev/null +++ b/src/ansys/dpf/core/debug.py @@ -0,0 +1,46 @@ +# Copyright (C) 2020 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from __future__ import annotations + +from pathlib import Path + +import ansys.dpf.core as dpf +from ansys.dpf.gate import data_processing_capi, data_processing_grpcapi + + +def start_debug_trace(path: str | Path, server: dpf.AnyServerType = None): + server = dpf.server.get_or_create_server(server) + api = server.get_api_for_type( + capi=data_processing_capi.DataProcessingCAPI, + grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, + ) + api.data_processing_set_debug_trace(text=str(path)) + + +def stop_debug_trace(server: dpf.AnyServerType = None): + server = dpf.server.get_or_create_server(server) + api = server.get_api_for_type( + capi=data_processing_capi.DataProcessingCAPI, + grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, + ) + api.data_processing_set_debug_trace(text="") From 654e0ec8a8fcf8fa4005b5b965f12dfd401db1f4 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 3 Oct 2025 15:00:21 +0200 Subject: [PATCH 2/5] Switch to BaseServer.start_debug and BaseServer.stop_debug --- src/ansys/dpf/core/debug.py | 46 ------------------------------ src/ansys/dpf/core/server_types.py | 25 +++++++++++++++- 2 files changed, 24 insertions(+), 47 deletions(-) delete mode 100644 src/ansys/dpf/core/debug.py diff --git a/src/ansys/dpf/core/debug.py b/src/ansys/dpf/core/debug.py deleted file mode 100644 index a9247b2d30..0000000000 --- a/src/ansys/dpf/core/debug.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) 2020 - 2025 ANSYS, Inc. and/or its affiliates. -# SPDX-License-Identifier: MIT -# -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -from __future__ import annotations - -from pathlib import Path - -import ansys.dpf.core as dpf -from ansys.dpf.gate import data_processing_capi, data_processing_grpcapi - - -def start_debug_trace(path: str | Path, server: dpf.AnyServerType = None): - server = dpf.server.get_or_create_server(server) - api = server.get_api_for_type( - capi=data_processing_capi.DataProcessingCAPI, - grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, - ) - api.data_processing_set_debug_trace(text=str(path)) - - -def stop_debug_trace(server: dpf.AnyServerType = None): - server = dpf.server.get_or_create_server(server) - api = server.get_api_for_type( - capi=data_processing_capi.DataProcessingCAPI, - grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, - ) - api.data_processing_set_debug_trace(text="") diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index 0596417150..58b9341d79 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -51,7 +51,7 @@ from ansys.dpf.core._version import min_server_version, server_to_ansys_version from ansys.dpf.core.check_version import get_server_version, meets_version, version_requires from ansys.dpf.core.server_context import AvailableServerContexts, ServerContext -from ansys.dpf.gate import data_processing_grpcapi, load_api +from ansys.dpf.gate import data_processing_capi, data_processing_grpcapi, load_api if TYPE_CHECKING: # pragma: no cover from ansys.dpf.core.server_factory import DockerConfig @@ -709,6 +709,29 @@ def __del__(self): except: warnings.warn(traceback.format_exc()) + def start_debug(self, folder_path: str | Path): + """Start writing server debug information within the given folder. + + Parameters + ---------- + folder_path: + Path to a folder where to write server debug info. + + """ + api = self.get_api_for_type( + capi=data_processing_capi.DataProcessingCAPI, + grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, + ) + api.data_processing_set_debug_trace(text=str(folder_path)) + + def stop_debug(self): + """Stop writing server debug information.""" + api = self.get_api_for_type( + capi=data_processing_capi.DataProcessingCAPI, + grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, + ) + api.data_processing_set_debug_trace(text="") + class CServer(BaseServer, ABC): """Abstract class for servers going through the DPFClientAPI.""" From f5e9ff868a0d228232b73627cbfe2a58e57911c9 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Mon, 6 Oct 2025 15:37:53 +0200 Subject: [PATCH 3/5] Adapt path to server os --- src/ansys/dpf/core/server_types.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index 58b9341d79..398e5623aa 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -34,7 +34,7 @@ import ctypes import io import os -from pathlib import Path +from pathlib import Path, PurePosixPath, PureWindowsPath import socket import subprocess import sys @@ -710,14 +710,17 @@ def __del__(self): warnings.warn(traceback.format_exc()) def start_debug(self, folder_path: str | Path): - """Start writing server debug information within the given folder. + """Start writing server-side debug information within the given folder. Parameters ---------- folder_path: - Path to a folder where to write server debug info. + Path to a folder server-side where to write debug info. """ + folder_path = ( + PurePosixPath(folder_path) if self.os == "posix" else PureWindowsPath(folder_path) + ) api = self.get_api_for_type( capi=data_processing_capi.DataProcessingCAPI, grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, @@ -725,7 +728,7 @@ def start_debug(self, folder_path: str | Path): api.data_processing_set_debug_trace(text=str(folder_path)) def stop_debug(self): - """Stop writing server debug information.""" + """Stop writing server-side debug information.""" api = self.get_api_for_type( capi=data_processing_capi.DataProcessingCAPI, grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI, From 9d14f3fdd6452e1d68d398f4164085888fc1156c Mon Sep 17 00:00:00 2001 From: PProfizi Date: Mon, 6 Oct 2025 16:14:33 +0200 Subject: [PATCH 4/5] Add a DEFAULT_SERVER_DEBUG global variable --- src/ansys/dpf/core/__init__.py | 1 + src/ansys/dpf/core/server_types.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/ansys/dpf/core/__init__.py b/src/ansys/dpf/core/__init__.py index 08a256525f..98fdbfb43b 100644 --- a/src/ansys/dpf/core/__init__.py +++ b/src/ansys/dpf/core/__init__.py @@ -128,6 +128,7 @@ SERVER = None SERVER_CONFIGURATION = None +DEFAULT_SERVER_DEBUG = None _server_instances = [] diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index 398e5623aa..6d114d8c3e 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -445,6 +445,8 @@ def __init__(self): self._info_instance = None self._docker_config = server_factory.RunningDockerConfig() self._server_meet_version = {} + if core.DEFAULT_SERVER_DEBUG is not None: + self.start_debug(folder_path=core.DEFAULT_SERVER_DEBUG) def set_as_global(self, as_global=True): """Set the current server as global if necessary. From 414a4ed81344773a231881c21d50d3cbb000040d Mon Sep 17 00:00:00 2001 From: PProfizi Date: Tue, 7 Oct 2025 10:28:51 +0200 Subject: [PATCH 5/5] Add a test --- tests/test_server.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_server.py b/tests/test_server.py index b7ff9a4459..3b4543409f 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -179,6 +179,20 @@ def test_server_plugins(self, server_config): assert isinstance(server_plugins, dict) assert "native" in server_plugins.keys() + def test_server_debug(self, server_config, tmp_path): + from pathlib import Path + + server_instance = start_local_server(config=server_config) + server_instance.start_debug(tmp_path / Path("DEBUG_TEST_")) + f = dpf.core.field_from_array([1.0], server=server_instance) + fwd = dpf.core.operators.utility.forward(any=f, server=server_instance) + fwd.run() + server_instance.stop_debug() + debug_folder = sorted(tmp_path.glob("DEBUG_TEST_*")) + assert len(debug_folder) == 1 + init_path = debug_folder[0] / Path("init.log") + assert init_path.exists() + @pytest.mark.skipif( os.name == "posix" or running_docker,