| 1 |
// This script tracks time between packet queue and transmit. The |
| 2 |
// information is provided to userspace via procfs in JSON format. |
| 3 |
|
| 4 |
global net_devices |
| 5 |
|
| 6 |
probe json_data |
| 7 |
{ |
| 8 |
@json_output_data_start |
| 9 |
|
| 10 |
foreach (dev in net_devices) { |
| 11 |
if (@count(skb_queue_t[dev])) { |
| 12 |
@json_output_array_numeric_value("net_xmit_data", dev, "xmit_count", |
| 13 |
@sum(skb_queue_t[dev])) |
| 14 |
@json_output_array_numeric_value("net_xmit_data", dev, "xmit_latency", |
| 15 |
@count(skb_queue_t[dev])) |
| 16 |
} |
| 17 |
else { |
| 18 |
@json_output_array_numeric_value("net_xmit_data", dev, "xmit_count", 0) |
| 19 |
@json_output_array_numeric_value("net_xmit_data", dev, "xmit_latency", 0) |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
@json_output_data_end |
| 24 |
} |
| 25 |
|
| 26 |
// Set up the metrics |
| 27 |
probe begin |
| 28 |
{ |
| 29 |
// fallback instance device "eth0" if none specified |
| 30 |
if (argc == 0) { |
| 31 |
argv[1] = "eth0" |
| 32 |
argc = 1 |
| 33 |
} |
| 34 |
|
| 35 |
// remember all the network devices |
| 36 |
for (i = 1; i <= argc; i++) { |
| 37 |
dev = argv[i] |
| 38 |
net_devices[dev] = i - 1 |
| 39 |
} |
| 40 |
|
| 41 |
// Set the prefix to be used instead of the module name. |
| 42 |
json_set_prefix("net_xmit") |
| 43 |
|
| 44 |
// Add the metrics |
| 45 |
json_add_array("net_xmit_data", |
| 46 |
"Network transmit data indexed by ethernet device") |
| 47 |
json_add_array_numeric_metric("net_xmit_data", "xmit_count", |
| 48 |
"number of packets for xmit device", "count") |
| 49 |
json_add_array_numeric_metric("net_xmit_data", "xmit_latency", |
| 50 |
"sum of latency for xmit device", "") |
| 51 |
} |
| 52 |
|
| 53 |
// probes to track the information |
| 54 |
|
| 55 |
global skb_queue_start_t, skb_queue_t |
| 56 |
|
| 57 |
probe kernel.trace("net_dev_queue") { |
| 58 |
skb_queue_start_t[$skb] = gettimeofday_ns(); |
| 59 |
} |
| 60 |
|
| 61 |
probe kernel.trace("net_dev_start_xmit") ?, kernel.trace("net_dev_xmit") { |
| 62 |
t = gettimeofday_ns(); |
| 63 |
st = skb_queue_start_t[$skb] |
| 64 |
if (st){ |
| 65 |
skb_queue_t[kernel_string($dev->name)] <<< t - st |
| 66 |
delete skb_queue_start_t[$skb] |
| 67 |
} |
| 68 |
} |