次の例では、diskact.d
スクリプトは、sdt
カーネル・モジュールによって有効化されたio
プロバイダ・プローブを使用して、システム上のブロック・デバイスに対するI/Oスループットの分布を表示しています。
#pragma D option quiet /* diskact.d -- Display the distribution of I/O throughput for block devices */ io:::start { start[args[0]->b_edev, args[0]->b_blkno] = timestamp; } io:::done /start[args[0]->b_edev, args[0]->b_blkno]/ { /* You want to get an idea of our throughput to this device in KB/sec but you have values that are measured in bytes and nanoseconds. You want to calculate the following: bytes / 1024 ------------------------ nanoseconds / 1000000000 As DTrace uses integer arithmetic and the denominator is usually between 0 and 1 for most I/O, the calculation as shown will lose precision. So, restate the fraction as: bytes 1000000000 bytes * 976562 ----------- * ------------- = -------------- nanoseconds 1024 nanoseconds This is easy to calculate using integer arithmetic. */ this->elapsed = timestamp - start[args[0]->b_edev, args[0]->b_blkno]; @[args[1]->dev_statname, args[1]->dev_pathname] = quantize((args[0]->b_bcount * 976562) / this->elapsed); start[args[0]->b_edev, args[0]->b_blkno] = 0; } END { printa(" %s (%s)\n%@d\n", @); }
#pragma D option quiet
文は不要な出力を抑制するために使用され、printa()
関数は集計結果の表示に使用されます。
io:::start
およびio:::done
プローブの引数の詳細は、「Oracle® Linux: DTraceガイド」の「ioプロバイダ」を参照してください。
printa()
関数の詳細は、「Oracle® Linux: DTraceガイド」で「出力フォーマット」を参照してください。
プログラムを約1分間実行した後、Ctrl-C
と入力して結果を表示します:
#dtrace -s diskact.d
^C
xvda2 (<unknown>) value ------------- Distribution ------------- count -1 | 0 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 3 1 | 0 xvdc (<unknown>) value ------------- Distribution ------------- count -1 | 0 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 3 1 | 0 xvdc1 (<unknown>) value ------------- Distribution ------------- count -1 | 0 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 3 1 | 0 dm-0 (<unknown>) value ------------- Distribution ------------- count 256 | 0 512 |@@ 1 1024 |@@ 1 2048 |@@@@@@ 3 4096 |@@@@@@@@@@ 5 8192 |@@@@@@@@@@@@@@@@@ 9 16384 |@@@@ 2 32768 | 0