xprof 2.22.2__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. xprof/__init__.py +23 -0
  2. xprof/api/continuous_profiling_snapshot.py +73 -0
  3. xprof/convert/_pywrap_profiler_plugin.py +506 -0
  4. xprof/convert/csv_writer.py +139 -0
  5. xprof/convert/profiler_plugin_c_api.pyd +0 -0
  6. xprof/convert/raw_to_tool_data.py +237 -0
  7. xprof/convert/trace_events_json.py +105 -0
  8. xprof/integration_tests/tf_mnist.py +100 -0
  9. xprof/integration_tests/tf_profiler_session.py +40 -0
  10. xprof/integration_tests/tpu/tensorflow/tpu_tf2_keras_test.py +183 -0
  11. xprof/profile_io.py +411 -0
  12. xprof/profile_plugin.py +1896 -0
  13. xprof/profile_plugin_loader.py +82 -0
  14. xprof/protobuf/dcn_collective_info_pb2.py +44 -0
  15. xprof/protobuf/dcn_slack_analysis_pb2.py +42 -0
  16. xprof/protobuf/diagnostics_pb2.py +36 -0
  17. xprof/protobuf/event_time_fraction_analyzer_pb2.py +54 -0
  18. xprof/protobuf/hardware_types_pb2.py +40 -0
  19. xprof/protobuf/hlo_stats_pb2.py +41 -0
  20. xprof/protobuf/inference_stats_pb2.py +86 -0
  21. xprof/protobuf/input_pipeline_pb2.py +52 -0
  22. xprof/protobuf/kernel_stats_pb2.py +38 -0
  23. xprof/protobuf/memory_profile_pb2.py +56 -0
  24. xprof/protobuf/memory_viewer_preprocess_pb2.py +49 -0
  25. xprof/protobuf/op_metrics_pb2.py +71 -0
  26. xprof/protobuf/op_profile_pb2.py +49 -0
  27. xprof/protobuf/op_stats_pb2.py +75 -0
  28. xprof/protobuf/overview_page_pb2.py +65 -0
  29. xprof/protobuf/pod_stats_pb2.py +45 -0
  30. xprof/protobuf/pod_viewer_pb2.py +61 -0
  31. xprof/protobuf/power_metrics_pb2.py +38 -0
  32. xprof/protobuf/roofline_model_pb2.py +44 -0
  33. xprof/protobuf/smart_suggestion_pb2.py +38 -0
  34. xprof/protobuf/source_info_pb2.py +36 -0
  35. xprof/protobuf/source_stats_pb2.py +50 -0
  36. xprof/protobuf/steps_db_pb2.py +76 -0
  37. xprof/protobuf/task_pb2.py +37 -0
  38. xprof/protobuf/tf_data_stats_pb2.py +72 -0
  39. xprof/protobuf/tf_function_pb2.py +52 -0
  40. xprof/protobuf/tf_stats_pb2.py +42 -0
  41. xprof/protobuf/tfstreamz_pb2.py +40 -0
  42. xprof/protobuf/topology_pb2.py +50 -0
  43. xprof/protobuf/tpu_input_pipeline_pb2.py +43 -0
  44. xprof/protobuf/trace_data_response_pb2.py +48 -0
  45. xprof/protobuf/trace_events_old_pb2.py +54 -0
  46. xprof/protobuf/trace_events_pb2.py +64 -0
  47. xprof/protobuf/trace_events_raw_pb2.py +45 -0
  48. xprof/protobuf/trace_filter_config_pb2.py +40 -0
  49. xprof/server.py +359 -0
  50. xprof/standalone/base_plugin.py +52 -0
  51. xprof/standalone/context.py +22 -0
  52. xprof/standalone/data_provider.py +32 -0
  53. xprof/standalone/plugin_asset_util.py +131 -0
  54. xprof/standalone/plugin_event_multiplexer.py +185 -0
  55. xprof/standalone/tensorboard_shim.py +31 -0
  56. xprof/static/bundle.js +137744 -0
  57. xprof/static/index.html +64 -0
  58. xprof/static/index.js +3 -0
  59. xprof/static/materialicons.woff2 +0 -0
  60. xprof/static/styles.css +1 -0
  61. xprof/static/trace_viewer_index.html +3935 -0
  62. xprof/static/trace_viewer_index.js +15946 -0
  63. xprof/static/trace_viewer_v2.js +8103 -0
  64. xprof/static/trace_viewer_v2.wasm +0 -0
  65. xprof/static/zone.js +3558 -0
  66. xprof/version.py +18 -0
  67. xprof-2.22.2.dist-info/METADATA +354 -0
  68. xprof-2.22.2.dist-info/RECORD +71 -0
  69. xprof-2.22.2.dist-info/WHEEL +5 -0
  70. xprof-2.22.2.dist-info/entry_points.txt +5 -0
  71. xprof-2.22.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: plugin/xprof/protobuf/trace_events.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'plugin/xprof/protobuf/trace_events.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+ from xprof.protobuf import task_pb2 as plugin_dot_xprof_dot_protobuf_dot_task__pb2
26
+
27
+
28
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(plugin/xprof/protobuf/trace_events.proto\x12\x13tensorflow.profiler\x1a plugin/xprof/protobuf/task.proto\"\xd2\x03\n\x05Trace\x12\x38\n\x07\x64\x65vices\x18\x01 \x03(\x0b\x32\'.tensorflow.profiler.Trace.DevicesEntry\x12\x34\n\x05tasks\x18\x06 \x03(\x0b\x32%.tensorflow.profiler.Trace.TasksEntry\x12\x18\n\x10min_timestamp_ps\x18\x04 \x01(\x04\x12\x18\n\x10max_timestamp_ps\x18\x05 \x01(\x04\x12\x12\n\nnum_events\x18\x07 \x01(\x04\x12=\n\nname_table\x18\x08 \x03(\x0b\x32).tensorflow.profiler.Trace.NameTableEntry\x1aK\n\x0c\x44\x65vicesEntry\x12\x0b\n\x03key\x18\x01 \x01(\r\x12*\n\x05value\x18\x02 \x01(\x0b\x32\x1b.tensorflow.profiler.Device:\x02\x38\x01\x1aG\n\nTasksEntry\x12\x0b\n\x03key\x18\x01 \x01(\r\x12(\n\x05value\x18\x02 \x01(\x0b\x32\x19.tensorflow.profiler.Task:\x02\x38\x01\x1a\x30\n\x0eNameTableEntry\x12\x0b\n\x03key\x18\x01 \x01(\x06\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01J\x04\x08\x02\x10\x03J\x04\x08\x03\x10\x04\"\xbf\x01\n\x06\x44\x65vice\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x11\n\tdevice_id\x18\x02 \x01(\r\x12=\n\tresources\x18\x03 \x03(\x0b\x32*.tensorflow.profiler.Device.ResourcesEntry\x1aO\n\x0eResourcesEntry\x12\x0b\n\x03key\x18\x01 \x01(\x04\x12,\n\x05value\x18\x02 \x01(\x0b\x32\x1d.tensorflow.profiler.Resource:\x02\x38\x01J\x04\x08\x04\x10\x05\"A\n\x08Resource\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0bresource_id\x18\x02 \x01(\x04\x12\x12\n\nnum_events\x18\x03 \x01(\r\"\xba\x04\n\nTraceEvent\x12\x37\n\x04type\x18\x0e \x01(\x0e\x32).tensorflow.profiler.TraceEvent.EventType\x12\x11\n\tdevice_id\x18\x01 \x01(\r\x12\x13\n\x0bresource_id\x18\x02 \x01(\x04\x12\x0e\n\x04name\x18\x03 \x01(\tH\x00\x12\x12\n\x08name_ref\x18\x0c \x01(\x06H\x00\x12\x14\n\x08group_id\x18\x05 \x01(\x03:\x02-1\x12\x14\n\x0ctimestamp_ps\x18\x06 \x01(\x04\x12\x13\n\x0b\x64uration_ps\x18\x07 \x01(\x04\x12\x10\n\x08raw_data\x18\x08 \x01(\x0c\x12\x0f\n\x07\x66low_id\x18\t \x01(\x04\x12\x46\n\x0f\x66low_entry_type\x18\n \x01(\x0e\x32-.tensorflow.profiler.TraceEvent.FlowEntryType\x12\x15\n\rflow_category\x18\x0b \x01(\r\x12\x0e\n\x06serial\x18\r \x01(\r\"t\n\tEventType\x12\x1a\n\x16\x45VENT_TYPE_UNSPECIFIED\x10\x00\x12\x17\n\x13\x45VENT_TYPE_COMPLETE\x10\x01\x12\x14\n\x10\x45VENT_TYPE_ASYNC\x10\x03\x12\x16\n\x12\x45VENT_TYPE_COUNTER\x10\x04\"\x04\x08\x02\x10\x02\"J\n\rFlowEntryType\x12\r\n\tFLOW_NONE\x10\x00\x12\x0e\n\nFLOW_START\x10\x01\x12\x0c\n\x08\x46LOW_MID\x10\x02\x12\x0c\n\x08\x46LOW_END\x10\x03\x42\x0c\n\nname_oneofJ\x04\x08\x04\x10\x05\x42\x03\xf8\x01\x01')
29
+
30
+ _globals = globals()
31
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
32
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'plugin.xprof.protobuf.trace_events_pb2', _globals)
33
+ if not _descriptor._USE_C_DESCRIPTORS:
34
+ _globals['DESCRIPTOR']._loaded_options = None
35
+ _globals['DESCRIPTOR']._serialized_options = b'\370\001\001'
36
+ _globals['_TRACE_DEVICESENTRY']._loaded_options = None
37
+ _globals['_TRACE_DEVICESENTRY']._serialized_options = b'8\001'
38
+ _globals['_TRACE_TASKSENTRY']._loaded_options = None
39
+ _globals['_TRACE_TASKSENTRY']._serialized_options = b'8\001'
40
+ _globals['_TRACE_NAMETABLEENTRY']._loaded_options = None
41
+ _globals['_TRACE_NAMETABLEENTRY']._serialized_options = b'8\001'
42
+ _globals['_DEVICE_RESOURCESENTRY']._loaded_options = None
43
+ _globals['_DEVICE_RESOURCESENTRY']._serialized_options = b'8\001'
44
+ _globals['_TRACE']._serialized_start=100
45
+ _globals['_TRACE']._serialized_end=566
46
+ _globals['_TRACE_DEVICESENTRY']._serialized_start=356
47
+ _globals['_TRACE_DEVICESENTRY']._serialized_end=431
48
+ _globals['_TRACE_TASKSENTRY']._serialized_start=433
49
+ _globals['_TRACE_TASKSENTRY']._serialized_end=504
50
+ _globals['_TRACE_NAMETABLEENTRY']._serialized_start=506
51
+ _globals['_TRACE_NAMETABLEENTRY']._serialized_end=554
52
+ _globals['_DEVICE']._serialized_start=569
53
+ _globals['_DEVICE']._serialized_end=760
54
+ _globals['_DEVICE_RESOURCESENTRY']._serialized_start=675
55
+ _globals['_DEVICE_RESOURCESENTRY']._serialized_end=754
56
+ _globals['_RESOURCE']._serialized_start=762
57
+ _globals['_RESOURCE']._serialized_end=827
58
+ _globals['_TRACEEVENT']._serialized_start=830
59
+ _globals['_TRACEEVENT']._serialized_end=1400
60
+ _globals['_TRACEEVENT_EVENTTYPE']._serialized_start=1188
61
+ _globals['_TRACEEVENT_EVENTTYPE']._serialized_end=1304
62
+ _globals['_TRACEEVENT_FLOWENTRYTYPE']._serialized_start=1306
63
+ _globals['_TRACEEVENT_FLOWENTRYTYPE']._serialized_end=1380
64
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: plugin/xprof/protobuf/trace_events_raw.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'plugin/xprof/protobuf/trace_events_raw.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,plugin/xprof/protobuf/trace_events_raw.proto\x12\x13tensorflow.profiler\"\xc0\x01\n\x07RawData\x12\x38\n\x0c\x64ma_activity\x18\x01 \x01(\x0b\x32 .tensorflow.profiler.DmaActivityH\x00\x12\x38\n\x04\x61rgs\x18\x02 \x01(\x0b\x32(.tensorflow.profiler.TraceEventArgumentsH\x00\x12\x35\n\x08tpu_data\x18\x03 \x01(\x0b\x32!.tensorflow.profiler.TpuTraceDataH\x00\x42\n\n\x08raw_data\"\xcf\x01\n\x0b\x44maActivity\x12\x19\n\x11start_time_cycles\x18\x01 \x01(\x04\x12\x17\n\x0f\x65nd_time_cycles\x18\x02 \x01(\x04\x12\x11\n\tkilobytes\x18\x04 \x01(\x04\x12\x14\n\x0cmesh_chip_id\x18\x05 \x01(\r\x12\x0f\n\x07\x63ore_id\x18\x0b \x01(\r\x12\x13\n\x0b\x64ma_address\x18\x06 \x01(\x04\x12\x11\n\tmulticast\x18\x08 \x01(\r\x12\x11\n\tsegmented\x18\t \x01(\r\x12\x11\n\ttemporary\x18\n \x01(\x04J\x04\x08\x03\x10\x04\"\xe6\x01\n\x13TraceEventArguments\x12>\n\x03\x61rg\x18\x01 \x03(\x0b\x32\x31.tensorflow.profiler.TraceEventArguments.Argument\x1a\x8e\x01\n\x08\x41rgument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\tstr_value\x18\x02 \x01(\tH\x00\x12\x14\n\nuint_value\x18\x03 \x01(\x04H\x00\x12\x13\n\tint_value\x18\x05 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x04 \x01(\x01H\x00\x12\x13\n\tref_value\x18\x06 \x01(\x06H\x00\x42\x07\n\x05value\"\x1d\n\x0cTpuTraceData\x12\r\n\x05\x64ummy\x18\x01 \x01(\rB\x03\xf8\x01\x01')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'plugin.xprof.protobuf.trace_events_raw_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ _globals['DESCRIPTOR']._loaded_options = None
34
+ _globals['DESCRIPTOR']._serialized_options = b'\370\001\001'
35
+ _globals['_RAWDATA']._serialized_start=70
36
+ _globals['_RAWDATA']._serialized_end=262
37
+ _globals['_DMAACTIVITY']._serialized_start=265
38
+ _globals['_DMAACTIVITY']._serialized_end=472
39
+ _globals['_TRACEEVENTARGUMENTS']._serialized_start=475
40
+ _globals['_TRACEEVENTARGUMENTS']._serialized_end=705
41
+ _globals['_TRACEEVENTARGUMENTS_ARGUMENT']._serialized_start=563
42
+ _globals['_TRACEEVENTARGUMENTS_ARGUMENT']._serialized_end=705
43
+ _globals['_TPUTRACEDATA']._serialized_start=707
44
+ _globals['_TPUTRACEDATA']._serialized_end=736
45
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: plugin/xprof/protobuf/trace_filter_config.proto
5
+ # Protobuf Python Version: 6.31.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 6,
15
+ 31,
16
+ 1,
17
+ '',
18
+ 'plugin/xprof/protobuf/trace_filter_config.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n/plugin/xprof/protobuf/trace_filter_config.proto\x12\x13tensorflow.profiler\"\xc0\x02\n\x10TraceEventFilter\x12\x12\n\nfield_name\x18\x05 \x01(\t\x12=\n\x05op_id\x18\x06 \x01(\x0e\x32..tensorflow.profiler.TraceEventFilter.Operator\x12\x10\n\x08negation\x18\x07 \x01(\x08\x12\x13\n\tstr_value\x18\x08 \x01(\tH\x00\x12\x15\n\x0bregex_value\x18\t \x01(\tH\x00\x12\x14\n\nuint_value\x18\n \x01(\x04H\x00\x12\x13\n\tint_value\x18\x0c \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x0b \x01(\x01H\x00\"O\n\x08Operator\x12\t\n\x05OP_EQ\x10\x00\x12\t\n\x05OP_LT\x10\x01\x12\t\n\x05OP_GT\x10\x02\x12\t\n\x05OP_LE\x10\x03\x12\t\n\x05OP_GE\x10\x04\x12\x0c\n\x08OP_REGEX\x10\x05\x42\x07\n\x05value\"\xa9\x02\n\x11TraceFilterConfig\x12\x16\n\x0e\x64\x65vice_regexes\x18\x01 \x03(\t\x12\x18\n\x10resource_regexes\x18\x02 \x03(\t\x12 \n\x18mandatory_device_regexes\x18\x06 \x03(\t\x12\"\n\x1amandatory_resource_regexes\x18\x07 \x03(\t\x12\x42\n\x13trace_event_filters\x18\x03 \x03(\x0b\x32%.tensorflow.profiler.TraceEventFilter\x12\x46\n\x17trace_event_arg_filters\x18\x04 \x03(\x0b\x32%.tensorflow.profiler.TraceEventFilter\x12\x10\n\x08negation\x18\x05 \x01(\x08\x62\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'plugin.xprof.protobuf.trace_filter_config_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ DESCRIPTOR._loaded_options = None
34
+ _globals['_TRACEEVENTFILTER']._serialized_start=73
35
+ _globals['_TRACEEVENTFILTER']._serialized_end=393
36
+ _globals['_TRACEEVENTFILTER_OPERATOR']._serialized_start=305
37
+ _globals['_TRACEEVENTFILTER_OPERATOR']._serialized_end=384
38
+ _globals['_TRACEFILTERCONFIG']._serialized_start=396
39
+ _globals['_TRACEFILTERCONFIG']._serialized_end=693
40
+ # @@protoc_insertion_point(module_scope)
xprof/server.py ADDED
@@ -0,0 +1,359 @@
1
+ # Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Utilities to start up a standalone webserver."""
16
+
17
+ import argparse
18
+ import collections
19
+ import dataclasses
20
+ import logging
21
+ import socket
22
+ import sys
23
+ from typing import Optional
24
+
25
+ from cheroot import wsgi
26
+ from etils import epath
27
+
28
+ from xprof import profile_plugin_loader
29
+ from xprof.standalone import base_plugin
30
+ from xprof.standalone import plugin_event_multiplexer
31
+ from xprof.convert import _pywrap_profiler_plugin
32
+
33
+ logger = logging.getLogger("tensorboard.plugins.profile")
34
+ logger.setLevel(logging.INFO)
35
+ if not logger.handlers:
36
+ log_handler = logging.StreamHandler(sys.stderr)
37
+ formatter = logging.Formatter(
38
+ "%(levelname)s %(asctime)s [%(filename)s:%(lineno)d] %(message)s"
39
+ )
40
+ log_handler.setFormatter(formatter)
41
+ logger.addHandler(log_handler)
42
+ logger.propagate = False
43
+
44
+ DataProvider = plugin_event_multiplexer.DataProvider
45
+ TBContext = base_plugin.TBContext
46
+ ProfilePluginLoader = profile_plugin_loader.ProfilePluginLoader
47
+
48
+
49
+ _DEFAULT_GRPC_PORT = 50051
50
+
51
+
52
+ @dataclasses.dataclass(frozen=True)
53
+ class ServerConfig:
54
+ """Configuration parameters for launching the XProf server.
55
+
56
+ This dataclass holds all the settings required to initialize and run the XProf
57
+ profiling server, including network ports, log locations, and feature flags.
58
+ """
59
+
60
+ logdir: Optional[str]
61
+ port: int
62
+ grpc_port: int
63
+ worker_service_address: str
64
+ hide_capture_profile_button: bool
65
+ src_prefix: Optional[str]
66
+ max_concurrent_worker_requests: int
67
+
68
+
69
+ def make_wsgi_app(plugin):
70
+ """Create a WSGI application for the standalone server."""
71
+
72
+ apps = plugin.get_plugin_apps()
73
+
74
+ prefix = "/data/plugin/profile"
75
+
76
+ def application(environ, start_response):
77
+ path = environ["PATH_INFO"]
78
+ if path.startswith(prefix):
79
+ path = path[len(prefix) :]
80
+ if path != "/" and path.endswith("/"):
81
+ path = path[:-1]
82
+ handler = apps.get(path, plugin.default_handler)
83
+ return handler(environ, start_response)
84
+
85
+ return application
86
+
87
+
88
+ def run_server(plugin, host, port):
89
+ """Starts a webserver for the standalone server."""
90
+
91
+ app = make_wsgi_app(plugin)
92
+
93
+ server = wsgi.Server((host, port), app)
94
+
95
+ try:
96
+ logger.info("XProf at http://localhost:%d/ (Press CTRL+C to quit)", port)
97
+ server.start()
98
+ except KeyboardInterrupt:
99
+ server.stop()
100
+
101
+
102
+ def _get_wildcard_address(port) -> str:
103
+ """Returns a wildcard address for the port in question.
104
+
105
+ This will attempt to follow the best practice of calling
106
+ getaddrinfo() with a null host and AI_PASSIVE to request a
107
+ server-side socket wildcard address. If that succeeds, this
108
+ returns the first IPv6 address found, or if none, then returns
109
+ the first IPv4 address. If that fails, then this returns the
110
+ hardcoded address "::" if socket.has_ipv6 is True, else
111
+ "0.0.0.0".
112
+
113
+ Args:
114
+ port: The port number.
115
+
116
+ Returns:
117
+ The wildcard address.
118
+ """
119
+ fallback_address = "::" if socket.has_ipv6 else "0.0.0.0"
120
+ if hasattr(socket, "AI_PASSIVE"):
121
+ try:
122
+ addrinfos = socket.getaddrinfo(
123
+ None,
124
+ port,
125
+ socket.AF_UNSPEC,
126
+ socket.SOCK_STREAM,
127
+ socket.IPPROTO_TCP,
128
+ socket.AI_PASSIVE,
129
+ )
130
+ except socket.gaierror:
131
+ return fallback_address
132
+ addrs_by_family = collections.defaultdict(list)
133
+ for family, _, _, _, sockaddr in addrinfos:
134
+ # Format of the "sockaddr" socket address varies by address family,
135
+ # but [0] is always the IP address portion.
136
+ addrs_by_family[family].append(sockaddr[0])
137
+ if hasattr(socket, "AF_INET6") and addrs_by_family[socket.AF_INET6]:
138
+ return addrs_by_family[socket.AF_INET6][0]
139
+ if hasattr(socket, "AF_INET") and addrs_by_family[socket.AF_INET]:
140
+ return addrs_by_family[socket.AF_INET][0]
141
+ return fallback_address
142
+
143
+
144
+ def _launch_server(
145
+ config: ServerConfig,
146
+ ):
147
+ """Initializes and launches the main XProf server.
148
+
149
+ This function sets up the necessary components for the XProf server based on
150
+ the provided configuration. It starts the gRPC worker service if distributed
151
+ processing is enabled, creates the TensorBoard context, loads the profile
152
+ plugin, and finally starts the web server to handle HTTP requests.
153
+
154
+ Args:
155
+ config: The ServerConfig object containing all server settings.
156
+ """
157
+ _pywrap_profiler_plugin.initialize_stubs(config.worker_service_address)
158
+ _pywrap_profiler_plugin.start_grpc_server(
159
+ config.grpc_port, config.max_concurrent_worker_requests
160
+ )
161
+
162
+ context = TBContext(
163
+ config.logdir, DataProvider(config.logdir), TBContext.Flags(False)
164
+ )
165
+ context.hide_capture_profile_button = config.hide_capture_profile_button
166
+ context.src_prefix = config.src_prefix
167
+ loader = ProfilePluginLoader()
168
+ plugin = loader.load(context)
169
+ run_server(plugin, _get_wildcard_address(config.port), config.port)
170
+
171
+
172
+ def get_abs_path(logdir: str) -> str:
173
+ """Gets the absolute path for a given log directory string.
174
+
175
+ This function correctly handles both Google Cloud Storage (GCS) paths and
176
+ local filesystem paths.
177
+
178
+ - GCS paths (e.g., "gs://bucket/log") are returned as is.
179
+ - Local filesystem paths (e.g., "~/logs", "log", ".") are made absolute.
180
+
181
+ Args:
182
+ logdir: The path string.
183
+
184
+ Returns:
185
+ The corresponding absolute path as a string.
186
+ """
187
+ if logdir.startswith("gs://"):
188
+ return logdir
189
+
190
+ return str(epath.Path(logdir).expanduser().resolve())
191
+
192
+
193
+ def _create_argument_parser() -> argparse.ArgumentParser:
194
+ """Creates and configures the argument parser for the XProf server CLI.
195
+
196
+ This function sets up argparse to handle command-line flags for specifying
197
+ the log directory, server port, and other operational modes.
198
+
199
+ Returns:
200
+ The configured argument parser.
201
+ """
202
+ parser = argparse.ArgumentParser(
203
+ prog="xprof",
204
+ description="Launch the XProf profiling server.",
205
+ formatter_class=argparse.RawDescriptionHelpFormatter,
206
+ epilog=(
207
+ "Examples:\n"
208
+ "\txprof ~/jax/profile-logs -p 8080\n"
209
+ "\txprof --logdir ~/jax/profile-logs -p 8080"
210
+ ),
211
+ )
212
+
213
+ logdir_group = parser.add_mutually_exclusive_group(required=False)
214
+
215
+ logdir_group.add_argument(
216
+ "-l",
217
+ "--logdir",
218
+ dest="logdir_opt",
219
+ metavar="<logdir>",
220
+ type=str,
221
+ help="The directory where profile files will be stored.",
222
+ )
223
+
224
+ logdir_group.add_argument(
225
+ "logdir_pos",
226
+ nargs="?",
227
+ metavar="logdir",
228
+ type=str,
229
+ default=None,
230
+ help="Positional argument for the profile log directory.",
231
+ )
232
+
233
+ parser.add_argument(
234
+ "-p",
235
+ "--port",
236
+ metavar="<port>",
237
+ type=int,
238
+ default=8791,
239
+ help="The port number for the server (default: %(default)s).",
240
+ )
241
+
242
+ parser.add_argument(
243
+ "-hcpb",
244
+ "--hide_capture_profile_button",
245
+ action="store_true",
246
+ default=False,
247
+ help="Hides the 'Capture Profile' button in the UI.",
248
+ )
249
+
250
+ parser.add_argument(
251
+ "-wsa",
252
+ "--worker_service_address",
253
+ type=str,
254
+ default=None,
255
+ help=(
256
+ "A comma-separated list of worker service addresses (IPs or FQDNs)"
257
+ " with their gRPC ports, used in distributed profiling. Example:"
258
+ " 'worker-a.project.internal:50051,worker-b.project.internal:50051'."
259
+ " If not provided, it will use 0.0.0.0 with the gRPC port."
260
+ ),
261
+ )
262
+
263
+ parser.add_argument(
264
+ "-gp",
265
+ "--grpc_port",
266
+ type=int,
267
+ default=_DEFAULT_GRPC_PORT,
268
+ help=(
269
+ "The port for the gRPC server, which runs alongside the main HTTP"
270
+ " server for distributed profiling. This must be different from the"
271
+ " main server port (--port)."
272
+ ),
273
+ )
274
+
275
+ parser.add_argument(
276
+ "-spp",
277
+ "--src_prefix",
278
+ type=str,
279
+ default=None,
280
+ help="The path prefix for the source code being profiled.",
281
+ )
282
+
283
+ parser.add_argument(
284
+ "--max_concurrent_worker_requests",
285
+ type=int,
286
+ default=1,
287
+ help="The maximum number of concurrent requests the worker can process.",
288
+ )
289
+ return parser
290
+
291
+
292
+ def main() -> int:
293
+ """Parses command-line arguments and launches the XProf server.
294
+
295
+ This is the main entry point for the XProf server application. It parses
296
+ command-line arguments, creates a ServerConfig, and then launches the
297
+ server.
298
+
299
+ Returns:
300
+ An exit code, 0 for success and non-zero for errors.
301
+ """
302
+ parser = _create_argument_parser()
303
+ try:
304
+ args = parser.parse_args()
305
+ except SystemExit as e:
306
+ return e.code
307
+
308
+ logdir = (
309
+ get_abs_path(args.logdir_opt or args.logdir_pos)
310
+ if args.logdir_opt or args.logdir_pos
311
+ else None
312
+ )
313
+
314
+ worker_service_address = args.worker_service_address
315
+ if worker_service_address is None:
316
+ worker_service_address = f"0.0.0.0:{args.grpc_port}"
317
+
318
+ config = ServerConfig(
319
+ logdir=logdir,
320
+ port=args.port,
321
+ grpc_port=args.grpc_port,
322
+ worker_service_address=worker_service_address,
323
+ hide_capture_profile_button=args.hide_capture_profile_button,
324
+ src_prefix=args.src_prefix,
325
+ max_concurrent_worker_requests=args.max_concurrent_worker_requests,
326
+ )
327
+
328
+ logger.info(
329
+ "Attempting to start XProf server:\n"
330
+ " Log Directory: %s\n"
331
+ " Port: %d\n"
332
+ " Worker Service Address: %s\n"
333
+ " Hide Capture Button: %s",
334
+ logdir,
335
+ config.port,
336
+ config.worker_service_address,
337
+ config.hide_capture_profile_button,
338
+ )
339
+
340
+ if logdir and not epath.Path(logdir).exists():
341
+ print(
342
+ f"Error: Log directory '{logdir}' does not exist or is not a"
343
+ " directory.",
344
+ file=sys.stderr,
345
+ )
346
+ return 1
347
+
348
+ if config.port == config.grpc_port:
349
+ print(
350
+ "Error: The main server port (--port) and the gRPC port (--grpc_port)"
351
+ " must be different.",
352
+ file=sys.stderr,
353
+ )
354
+ return 1
355
+
356
+ _launch_server(
357
+ config,
358
+ )
359
+ return 0
@@ -0,0 +1,52 @@
1
+ # Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Base plugin classes and context for the TensorBoard free plugin."""
16
+
17
+ from typing import Any
18
+
19
+ from xprof.standalone import plugin_event_multiplexer
20
+
21
+
22
+ class TBPlugin:
23
+ pass
24
+
25
+
26
+ class FrontendMetadata:
27
+ def __init__(self, es_module_path: str):
28
+ self.es_module_path = es_module_path
29
+
30
+
31
+ class TBLoader:
32
+ pass
33
+
34
+
35
+ class TBContext():
36
+ """https://github.com/tensorflow/tensorboard/blob/a7178f4f622a786463d23ef645e0f16f6ea7a1cb/tensorboard/plugins/base_plugin.py#L229."""
37
+
38
+ class Flags():
39
+ def __init__(self, master_tpu_unsecure_channel):
40
+ self.master_tpu_unsecure_channel = master_tpu_unsecure_channel
41
+
42
+ def __init__(
43
+ self,
44
+ logdir: str,
45
+ data_provider: plugin_event_multiplexer.DataProvider,
46
+ flags: dict[str, Any],
47
+ multiplexer=None,
48
+ ):
49
+ self.logdir = logdir
50
+ self.data_provider = data_provider
51
+ self.flags = flags
52
+ self.multiplexer = multiplexer
@@ -0,0 +1,22 @@
1
+ # Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """A standalone version of Tensorboard's context and utils."""
16
+
17
+
18
+ class RequestContext:
19
+ """Overload of tensorboard/context.py:RequestContext."""
20
+
21
+ def __init__(self):
22
+ pass
@@ -0,0 +1,32 @@
1
+ # Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """A standalone version of Tensorboard's context and utils."""
16
+
17
+
18
+ class MultiplexerDataProvider:
19
+ """Data provider that reads data from a multiplexer."""
20
+
21
+ def __init__(self, multiplexer, logdir):
22
+ """Creates a new MultiplexerDataProvider.
23
+
24
+ Args:
25
+ multiplexer: A multiplexer object.
26
+ logdir: The log directory.
27
+ """
28
+ self.multiplexer = multiplexer
29
+ self.logdir = logdir
30
+
31
+ def list_runs(self, *args, **kwargs): # pylint: disable=invalid-name
32
+ return self.multiplexer.list_runs(*args, **kwargs)