Skip to content

Commit 2b33445

Browse files
chen-harrisonazeey
andauthored
First Draft of Changes to Profiler Tutorial (#711)
- Explicitly create new project directory called profiler_example - Download profiler.cc into directory using wget - Remove unnecessary grep dependency - Clarify the CMakeLists is being created, not modified - Separate the different options for running the profiler visualization into multiple blocks, with the conditions described more clearly - Would like confirmation on what IP address http.server broadcasts to; tutorial says it's the container's IP address, but it always showed up as 0.0.0.0 (localhost) for me in my container Signed-off-by: Harrison Chen <[email protected]> Co-authored-by: Addisu Z. Taddese <[email protected]>
1 parent 62c11ec commit 2b33445

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

tutorials/profiler.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ In order to use the profiler, inspection points must be added to the source code
2525
and the application or library must be linked to the `gz-common::profiler`
2626
component.
2727

28-
To start, download the [profiler.cc](https://github.com/gazebosim/gz-common/raw/gz-common7/examples/profiler.cc) example.
28+
To start, create a new CMake project directory and navigate to it:
29+
30+
```{.sh}
31+
mkdir -p ~/profiler_example && cd ~/profiler_example
32+
```
33+
34+
Next, download the [profiler.cc](https://github.com/gazebosim/gz-common/raw/gz-common7/examples/profiler.cc) example into the project:
35+
36+
```{.sh}
37+
wget https://raw.githubusercontent.com/gazebosim/gz-common/gz-common7/examples/profiler.cc
38+
```
2939

3040
The relevant corresponding C++ would be as follows:
3141

@@ -53,7 +63,7 @@ void thread(const char *_thread_name)
5363
}
5464
```
5565

56-
Update your CMakeLists.txt to the following. Note that the profiler must be
66+
Create a new `CMakeLists.txt` at the root of the project directory (`~/profiler_example`). Note that the profiler must be
5767
enabled at compile time in order to function.
5868

5969
```{.cpp}
@@ -71,46 +81,49 @@ target_compile_definitions(profiler_example PUBLIC "GZ_PROFILER_ENABLE=1")
7181
Run `cmake` and build the example
7282

7383
```{.sh}
74-
cd build
84+
mkdir -p build && cd build
7585
cmake ..
7686
make profiler_example
7787
```
7888

79-
Then execute the example and the profiler visualization:
89+
Then use two terminals to execute the example and the profiler visualization:
8090

81-
From terminal 1:
91+
From terminal 1, inside `~/profiler_example/build`:
8292

8393
```{.sh}
8494
./profiler_example
8595
```
8696

87-
From terminal 2, open the visualizer using one of the following commands
97+
From terminal 2, use one of the following commands, depending on your configuration:
8898

89-
```{.sh}
90-
# Find the launcher script and use it (Linux and macOS)
91-
find /usr | grep gz_remotery_vis
92-
...
99+
- If you installed `gz-common` as a package/binary:
100+
- Open the HTML file directly via a convenience script:
93101

94-
/usr/<path_to>/gz_remotery_vis
102+
```{.sh}
103+
$(find /usr -type f -name 'gz_remotery_vis')
104+
```
95105

96-
# Use the source path (Linux)
97-
# Substitute the path to your gz-common source checkout
98-
xdg-open $SOURCE_DIR/gz-common/profiler/src/Remotery/vis/index.html
106+
- Or, if you're running inside a Docker container, start a server:
99107

100-
# Use the installation path (Linux)
101-
# This may vary depending on where you have choosen to install
102-
xdg-open /usr/share/gz/gz-common/profiler_vis/index.html
108+
```{.sh}
109+
python3 -m http.server -d $(find / -type d -name 'profiler_vis')
110+
```
103111
104-
# Use the installation path (macOS)
105-
open /usr/share/gz/gz-common/profiler_vis/index.html
112+
- If you installed `gz-common` from source, we assume it is located at `$SOURCE_DIR/gz-common`, where `$SOURCE_DIR` is a variable representing a file path
113+
- Open the HTML file directly:
106114
107-
# Inside a Docker container with port 8000 exposed
108-
# 1. Find your container's IP with 'ifconfig'
109-
# 2. Start a basic web server:
110-
python3 -m http.server $SOURCE_DIR/gz-common/profiler/src/Remotery/vis/index.html
111-
# 3. Open URL "http://<container IP>:8000/" with a browser on the host.
112-
```
115+
```{.sh}
116+
xdg-open $SOURCE_DIR/gz-common/profiler/src/Remotery/vis/index.html
117+
```
118+
119+
- Or, if you're running inside a Docker container, start a server:
120+
121+
```{.sh}
122+
python3 -m http.server -d $SOURCE_DIR/gz-common/profiler/src/Remotery/vis
123+
```
113124
125+
If you are running the profiler visualization as a server, the command will display an output `Serving HTTP on [IP_ADDRESS]
126+
port 8000 (http://[IP_ADDRESS]:8000/) ...` - navigate to that URL in your browser and you should see the profiler displayed.
114127
### On Gazebo library
115128
116129
If you want to use profiler on any other Gazebo library, enable the profiler at compile time with ``ENABLE_PROFILER`` cmake argument.

0 commit comments

Comments
 (0)