diff options
author | yvt <i@yvt.jp> | 2021-07-19 00:50:04 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-19 00:57:48 +0900 |
commit | 41b372627161c8473222d0cd83e5d904ba8c1799 (patch) | |
tree | 9d447d591a4f8f311cef1664aa7df9ee46862e06 /components/url/lib.rs | |
parent | e8cb9f56e3fd0273d8984bc89639723c4f1d5482 (diff) | |
download | servo-41b372627161c8473222d0cd83e5d904ba8c1799.tar.gz servo-41b372627161c8473222d0cd83e5d904ba8c1799.zip |
feat: shorten thread names
The Linux kernel imposes a 15-byte limit on thread names[1]. This means
information that does not fit in this limit, e.g., the pipeline ID of
layout and script threads, is lost in a debugger and profiler (see the
first column of the table below).
This commit shortens the thread names used in Servo to maximize the
amount of information conveyed. It also rectifies some inconsistencies
in the names.
| Before | After |
|-------------------|-------------------|
| `BluetoothThread` | `Bluetooth` |
| `CanvasThread` | `Canvas` |
| `display alert d` | `AlertDialog` |
| `FontCacheThread` | `FontCache` |
| `GLPlayerThread` | `GLPlayer` |
| `HTML Parser` | `Parse:www.examp` |
| `LayoutThread Pi` | `Layout(1,1)` |
| `Memory profiler` | `MemoryProfiler` |
| `Memory profiler` | `MemoryProfTimer` |
| `OfflineAudioCon` | `OfflineACResolv` |
| `PullTimelineMar` | `PullTimelineDat` |
| `ScriptThread Pi` | `Script(1,1)` |
| `WebWorker for h` | `WW:www.example.` |
| `ServiceWorker f` | `SW:www.example.` |
| `ServiceWorkerMa` | `SvcWorkerManage` |
| `Time profiler t` | `TimeProfTimer` |
| `Time profiler` | `TimeProfiler` |
| `WebGL thread` | `WebGL` |
| `Choose a device` | `DevicePicker` |
| `Pick a file` | `FilePicker` |
| `Pick files` | `FilePicker` |
[1]: https://stackoverflow.com/questions/5026531/thread-name-longer-than-15-chars
Diffstat (limited to 'components/url/lib.rs')
-rw-r--r-- | components/url/lib.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/components/url/lib.rs b/components/url/lib.rs index 944d02f29f7..a19159ef031 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -179,6 +179,39 @@ impl ServoUrl { Ok(Self::from_url(Url::from_file_path(path)?)) } + /// Return a non-standard shortened form of the URL. Mainly intended to be + /// used for debug printing in a constrained space (e.g., thread names). + pub fn debug_compact(&self) -> impl std::fmt::Display + '_ { + match self.scheme() { + "http" | "https" => { + // Strip `scheme://`, which is hardly useful for identifying websites + let mut st = self.as_str(); + st = st.strip_prefix(self.scheme()).unwrap_or(st); + st = st.strip_prefix(":").unwrap_or(st); + st = st.trim_start_matches('/'); + + // Don't want to return an empty string + if st.is_empty() { + st = self.as_str(); + } + + st + }, + "file" => { + // The only useful part in a `file` URL is usually only the last + // few components + let path = self.path(); + let i = path.rfind('/'); + let i = i.map(|i| path[..i].rfind('/').unwrap_or(i)); + match i { + None | Some(0) => path, + Some(i) => &path[i + 1..], + } + }, + _ => self.as_str(), + } + } + /// <https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-url> pub fn is_potentially_trustworthy(&self) -> bool { // Step 1 |