Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ansys/dpf/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@

SERVER = None
SERVER_CONFIGURATION = None
DEFAULT_SERVER_DEBUG = None

_server_instances = []

Expand Down
32 changes: 30 additions & 2 deletions src/ansys/dpf/core/server_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -709,6 +711,32 @@ def __del__(self):
except:
warnings.warn(traceback.format_exc())

def start_debug(self, folder_path: str | Path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it really be at the server API? Wouldn't it be better in core, close to load plugin...

Also, I would create a context manager (similar design to licensing context manager)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll put tests but I wanted to validate the API first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it at the Server level because it is a specific server you ask for its debug info.
I can make a context manager and also expose it at the ansys.dpf.core level as a global command which would take the global server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense here, as it is for a given server.

Just a question, I remember we had an issue in the past that was fixed for data sources when the client was in a OS (say Windows) and the server was another (say Linux), that there was some path adaptation. I think that was fixed. Is this affected by that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense here, as it is for a given server.

Just a question, I remember we had an issue in the past that was fixed for data sources when the client was in a OS (say Windows) and the server was another (say Linux), that there was some path adaptation. I think that was fixed. Is this affected by that?

yes you are right, I am now adding the same logic here.

"""Start writing server-side debug information within the given folder.

Parameters
----------
folder_path:
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,
)
api.data_processing_set_debug_trace(text=str(folder_path))

def stop_debug(self):
"""Stop writing server-side 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."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You miss a "/" or "" at the end

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,
Expand Down
Loading