-
Notifications
You must be signed in to change notification settings - Fork 2
/
prov2synopsis
executable file
·48 lines (44 loc) · 1.59 KB
/
prov2synopsis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env tclsh8.6
if {$::argc != 1} {
puts "usage: [file tail [info script]] <provider>"
exit 1
} elseif {$::tcl_platform(user) != "root"} {
puts stderr "[file tail [info script]]: need to run as root"
exit 1
}
set fd [open "|dtrace -lv -P [lindex $::argv 0]"]
fconfigure $fd -buffering line
set header [gets $fd]
set provi [expr [string first "ID" $header] + 2]
set modi [expr [string first "PROVIDER" $header] + 8]
set funci [expr [string first "MODULE" $header] + 6]
set namei [expr [string first "NAME" $header] - 1]
set state findprobe
set args [list]
while {![eof $fd]} {
set line [gets $fd]
if {$state == "findprobe"} {
set len [string length $line]
set probe [list [string trim [string range $line $provi $modi]] \
[string trim [string range $line $modi $funci]] \
[string trim [string range $line $funci $namei]] \
[string trim [string range $line $namei [string length $line]]]]
if {[lindex $probe 1] == "kernel"} {
lset probe 1 ""
}
set state "findargs"
} elseif {$state == "findargs"} {
if {[string trim $line] == "Argument Types"} {
set state "args"
}
} elseif {$state == "args"} {
set arg [split $line ":"]
if {[llength $arg] != 2 && [string trim $line] != "None"} {
puts ".Fn [join $probe ":"] [join $args]"
set state "findprobe"
set args [list]
} elseif {[llength $arg] == 2} {
lappend args "\"[string trim [lindex $arg 1]]\""
}
}
}