lstopo is an excellent tool for generating intuitive, concise system topology diagrams. This article documents small issues I encountered while using it—it is not a comprehensive manual. For detailed options, refer to the official documentation: lstopo(1) - Linux man page.
The term “topo” in
lstopostands for “topology” (referring to computer system topology).
Many Linux distributions come with hwloc preinstalled. If your system lacks it (e.g., Ubuntu), install it with:
sudo apt install hwloc
lstopois responsible for visually displaying the topology detected byhwloc.
Alternatively, install it manually from Portable Hardware Locality (hwloc). Download from the “Sub-Projects” section, as highlighted in the red box below:
To print a nicely formatted system topology directly in the terminal, use this simple command:
lstopo --of ascii -p
--of ascii: Specifies ASCII output (uses ASCII art—characters arranged to form a diagram). For example, here’s an ASCII art door:
-p: Prints physical IDs (labeled as P#; use -l for logical IDs labeled L#).
The output shows the CPU’s three-level cache, processing units within each core, and PCI devices.
lstopo supports generating formats like PNG, JPG, SVG, PDF, and XML. Below is an example using SVG:
env LANG=zh_CN.UTF-8 lstopo --output-format svg > 1.svg
--output-formatis the full name of the shorthand--of.
The env LANG=zh_CN.UTF-8 prefix ensures Chinese characters render correctly (without it, Chinese text may appear as square boxes □):
You can also use this shorter command to generate files (automatically detects format from the extension):
env LANG=zh_CN.UTF-8 lstopo 1.svg
Add the -f flag to force overwrite existing files:
env LANG=zh_CN.UTF-8 lstopo 1.svg -f
Replace the file extension to generate other formats:
env LANG=zh_CN.UTF-8 lstopo 1.xmlenv LANG=zh_CN.UTF-8 lstopo 1.png -fFor all supported formats, see the “OUTPUT FORMATS” section in lstopo(1) - Linux man page.
Why did I show the longer
--output-formatcommand first? Many documents use it—likely for historical reasons. I prefer documenting multiple working methods; you never know when a specific scenario might require one over the other.
PNG and JPG are common formats (e.g., for blog posts), but they tend to be blurry (not due to compression). Smaller images may look acceptable, but larger ones suffer from poor clarity:
To get clear images:
The resulting image will be sharp:
On macOS, converting SVG to images often results in empty files for unknown reasons:
Third-party tools can fix this, but I prefer using built-in utilities when possible.
I hope these will help someone in need~
qlmanage (used for generating thumbnails). However, it produces square images, which may crop parts of the topology diagram.lstopo manual with useful examples.lstopo usage, library integration, and advanced features (for intermediate/advanced users).lstopo.