xscope : 分析 X Protocol 的工具
最近給許多社群的朋友作了無償的演講,雖然連車馬費都要自己搞定,但是獲得的啟發可不是金錢能衡量的。至少我能從互動中大致知道新書撰寫的方向,並透過潛在的讀者群對 slides 作了 review,最重要的是認識許多新朋友。 (補充一下,如果能帶我到處亂走更好 :P)
上週六應邀去台灣,給了一場 [
演講:綜觀 X Window System 新發展 (台中場次)],在議程中途,Ted Chang 問了我一個有趣的問題,他希望能對 X Protocol 作出類似 sniffer 的監控動作,雖然我發展 Xorz 時做過類似的動作,不過一時之間忘記了,只好事後寫信給他:
寄件者: Jim Huang
收件者: Ted Chang
日期: 2005/10/23 上午 10:24
主旨: Greetings & Peep X Protocol
Hi Ted,
Nice to meet you in last Sat, and you asked me an interesting question if X clients could peep the traffic behind X Protocol. There are many ways to meet your thoughts, and I suggest you to use XLab(1):
http://mvertes.free.fr/xlab/xlab.html
And the paper:
http://graphics.stanford.edu/papers/profiling/
I will make a new blog entry about the above. (Google "XLab x11", and you will know where to download XLab.)
Have Fun!
-jserv
現在就補上一份介紹。
[
XLab] 是以 xscope 為基礎的一個應用程式,可以扮演 proxy X server 的機制,這樣一來如下面的示意圖:

因為 X Protocol 是 X Window System 的精髓,如果讓 xscope 居中斡旋,就有機會監看 X client 與 X server 之間的 traffic,以 xclock 做範例可參考以下執行畫面: (click to enlarge)

上圖可以看出 GC 的配置情況,當 focus 離開 X client (xclock running in DISPLAY=:1),除了要維護 Context 的 event loop,還額外作了 REQUEST: CopyArea,這只是一個操作,事實上光一個 xclock 這麼簡單的 X client,我們就可以看到 X Protocol 的變化。
因為 xscope 是個沒有維護的老程式,我剛剛重新打包過,並施加一些 patch,作了非正式的版本 [
xscope-1.1.0],捨棄 imake,而改用 autotools,所以可以很容易用 ./configure ; make 一類的方式來建構。以上的測試方式為:
- 允許 TCP connection,使用 xhost +localhost 來避免 xauth 問題
- 打開新的 X Terminal,比方說 rxvt,在裡面打 xscope -i1
- 另外打開新的 X Terminal,假設您用 bash,在裡面打 DISPLAY=:1 xclock
- 等 xclock 跳出來後,觀看前面的 X Terminal 變化
不過 xscope 或 [
XLab] 都必須在 proxy X server 模式下使用,如果要更完善的動態追蹤,就得用 Dtrace 一類的新設計,這後面的學問頗複雜,詳細的議題,可參考 John Danskin 與 Pat Hanrahan 共同撰寫的 [
Profiling the X Protocol]。
由 jserv 發表於 October 24, 2005 02:07 PM