File: jtime

package info (click to toggle)
jimtcl 0.83-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,432 kB
  • sloc: ansic: 207,301; tcl: 5,862; sh: 4,834; cpp: 1,671; makefile: 288
file content (53 lines) | stat: -rwxr-xr-x 1,026 bytes parent folder | download | duplicates (4)
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
49
50
51
52
53
#!/usr/bin/env jimsh
# vim:se syntax=tcl:

# Experimental code coverage for Jim Tcl

set auto_path [linsert $auto_path 0 [file dirname $argv0]/jimlib]

set argv [lassign $argv argv0]

set jtime::fileinfo($argv0) {}
set jtime::last [clock micros]

proc jtime::xtrace {type file line result name arglist} {
	variable fileinfo
	variable last
	set now [clock micros]

	if {![exists fileinfo($file)]} {
		set info {}
	} else {
		set info $fileinfo($file)
	}
	incr info($line) $($now - $last)
	set fileinfo($file) $info

	set last $now
}

xtrace jtime::xtrace

# Catch exit but not error
set rc [catch -noerror -exit {source $argv0} msg opts]

xtrace {}

set info $jtime::fileinfo($argv0)

set f [open $argv0]
set n 0
while {[$f gets buf] >= 0} {
	incr n
	if {[info exists info($n)]} {
		set prefix [format "%8d: " $info($n)]
	} else {
		set b [string trimleft $buf]
		if {$b eq "" || [string match "#*" $b] || [string match "\}*" $b]} {
			set prefix "       -: "
		} else {
			set prefix "    ####: "
		}
	}
	puts "$prefix$buf"
}