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
6 changes: 3 additions & 3 deletions frontend/app/services/data_service_v2/data_service_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ export class DataServiceV2 implements DataServiceV2Interface {
/** Methods below are for 3P only */
getRuns(): Observable<string[]|null> {
const searchParams = this.getSearchParams();
const session = searchParams.get('session');
const sessionPath = searchParams.get('session_path');
const runPath = searchParams.get('run_path');
let params = new HttpParams();
if (session) {
params = params.set('session', session);
if (sessionPath) {
params = params.set('session_path', sessionPath);
}
if (runPath) {
params = params.set('run_path', runPath);
Expand Down
39 changes: 21 additions & 18 deletions plugin/xprof/profile_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def __init__(self, context):
"""
self.logdir = context.logdir
self.basedir = context.logdir
self.custom_session = None
self.custom_session_path = None
self.custom_run_path = None
self.data_provider = context.data_provider
self.master_tpu_unsecure_channel = context.flags.master_tpu_unsecure_channel
Expand Down Expand Up @@ -595,14 +595,16 @@ def runs_imp(self, request: Optional[wrappers.Request] = None) -> list[str]:
request: Optional; werkzeug request used for grabbing ctx and experiment
id for other host implementations
"""
session = request.args.get('session') if request else None
run_path = request.args.get('run_path') if request and not session else None
self.custom_session = session
session_path = request.args.get('session_path') if request else None
run_path = (
request.args.get('run_path') if request and not session_path else None
)
self.custom_session_path = session_path
self.custom_run_path = run_path
self.logdir = session if session else self.basedir
if self.custom_session or self.custom_run_path:
self.logdir = session_path if session_path else self.basedir
if self.custom_session_path or self.custom_run_path:
runs_generator = self._generate_runs_from_path_params(
session=self.custom_session, run_path=self.custom_run_path
session_path=self.custom_session_path, run_path=self.custom_run_path
)
else:
runs_generator = self.generate_runs()
Expand Down Expand Up @@ -1071,30 +1073,31 @@ def _run_dir(self, run: str) -> str:
tb_run_directory = _tb_run_directory(self.logdir, tb_run_name)
if not self.logdir or not epath.Path(tb_run_directory).is_dir():
raise RuntimeError('No matching run directory for run %s' % run)
if self.custom_session or self.custom_run_path:
if self.custom_session_path or self.custom_run_path:
return os.path.join(tb_run_directory, profile_run_name)
plugin_directory = plugin_asset_util.PluginDirectory(
tb_run_directory, PLUGIN_NAME
)
return os.path.join(plugin_directory, profile_run_name)

def _generate_runs_from_path_params(
self, session: Optional[str] = None, run_path: Optional[str] = None
self, session_path: Optional[str] = None, run_path: Optional[str] = None
) -> Iterator[str]:
"""Generator for a list of runs from path parameters.

This function handles two specific scenarios for specifying profile data
locations:
1. `session`: A direct path to a directory containing XPlane files for a
1. `session_path`: A direct path to a directory containing XPlane files for
a
single profiling session. The directory's name becomes the run name.
2. `run_path`: A path to a directory that contains multiple session
directories. Each subdirectory that contains XPlane files is treated
as a profiling session, and its name becomes a run name.

Example Directory Structures:

Scenario 1: Using `session`
If `session` is `/path/to/my_session_dir`:
Scenario 1: Using `session_path`
If `session_path` is `/path/to/my_session_dir`:
```
/path/to/
my_session_dir/
Expand All @@ -1117,7 +1120,7 @@ def _generate_runs_from_path_params(
This would yield runs: "session_alpha", "session_beta".

Args:
session: An optional path string to a specific profiling session
session_path: An optional path string to a specific profiling session
directory.
run_path: An optional path string to a directory containing multiple
profiling session subdirectories.
Expand All @@ -1127,11 +1130,11 @@ def _generate_runs_from_path_params(
provided path parameters.
"""

if session:
session = epath.Path(session)
run_name = session.name
self.logdir = str(session.parent)
self._run_to_profile_run_dir[run_name] = str(session)
if session_path:
session_path = epath.Path(session_path)
run_name = session_path.name
self.logdir = str(session_path.parent)
self._run_to_profile_run_dir[run_name] = str(session_path)
yield run_name
elif run_path:
run_path = epath.Path(run_path)
Expand Down
24 changes: 13 additions & 11 deletions plugin/xprof/profile_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,13 @@ def wait_for_thread():
self.assertTrue(self.plugin.is_active())

def test_generate_runs_from_path_params_with_session(self):
session = os.path.join(self.logdir, 'session_run')
os.mkdir(session)
with open(os.path.join(session, 'host.xplane.pb'), 'w') as f:
session_path = os.path.join(self.logdir, 'session_run')
os.mkdir(session_path)
with open(os.path.join(session_path, 'host.xplane.pb'), 'w') as f:
f.write('dummy xplane data')
runs = list(self.plugin._generate_runs_from_path_params(session=session))
runs = list(
self.plugin._generate_runs_from_path_params(session_path=session_path)
)
self.assertListEqual(['session_run'], runs)
self.assertEqual(self.logdir, self.plugin.logdir)

Expand Down Expand Up @@ -549,16 +551,16 @@ def test_generate_runs_from_path_params_with_run_path(self):
self.assertEqual(run_path, self.plugin.logdir)

def test_runs_impl_with_session(self):
session = os.path.join(self.logdir, 'session_run')
os.mkdir(session)
with open(os.path.join(session, 'host.xplane.pb'), 'w') as f:
session_path = os.path.join(self.logdir, 'session_run')
os.mkdir(session_path)
with open(os.path.join(session_path, 'host.xplane.pb'), 'w') as f:
f.write('dummy xplane data')
request = utils.make_data_request(
utils.DataRequestOptions(session=session)
utils.DataRequestOptions(session_path=session_path)
)
runs = self.plugin.runs_imp(request)
self.assertListEqual(['session_run'], runs)
self.assertEqual(os.path.dirname(session), self.plugin.logdir)
self.assertEqual(os.path.dirname(session_path), self.plugin.logdir)

def test_runs_impl_with_run_path(self):
run_path = os.path.join(self.logdir, 'base')
Expand Down Expand Up @@ -598,8 +600,8 @@ def test_run_dir_invalid_tb_run_directory(self):
self.plugin._run_dir('non_existent_tb_run/run1')

def test_run_dir_with_custom_session(self):
self.plugin.custom_session = os.path.join(self.logdir, 'session_run')
os.mkdir(self.plugin.custom_session)
self.plugin.custom_session_path = os.path.join(self.logdir, 'session_run')
os.mkdir(self.plugin.custom_session_path)
run_dir = self.plugin._run_dir('session_run')
self.assertEqual(
run_dir, os.path.join(self.logdir, 'session_run')
Expand Down
8 changes: 4 additions & 4 deletions plugin/xprof/profile_plugin_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DataRequestOptions:
resolution: Trace resolution.
start_time_ms: Start time in milliseconds.
end_time_ms: End time in milliseconds.
session: Path to a single session.
session_path: Path to a single session.
run_path: Path to a directory containing multiple sessions.
"""

Expand All @@ -85,7 +85,7 @@ class DataRequestOptions:
resolution: int | None = None
start_time_ms: int | None = None
end_time_ms: int | None = None
session: str | None = None
session_path: str | None = None
run_path: str | None = None


Expand Down Expand Up @@ -116,8 +116,8 @@ def make_data_request(options: DataRequestOptions) -> Request:
req.args['start_time_ms'] = options.start_time_ms
if options.end_time_ms is not None:
req.args['end_time_ms'] = options.end_time_ms
if options.session:
req.args['session'] = options.session
if options.session_path:
req.args['session_path'] = options.session_path
if options.run_path:
req.args['run_path'] = options.run_path
return req