From e1c04807d4b4a62bdbecb53c462cca2700404f5f Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 12 Dec 2020 02:02:25 +0100 Subject: [PATCH] tracefile fixed: https://gitlab.com/ole.tange/tangetools/-/issues/9 --- Makefile | 17 ++++---- README | 8 ++++ find-first-fail/testsuite | 3 ++ plotpipe/plotpipe | 6 +-- tracefile/test.sh | 3 ++ tracefile/tracefile | 81 +++++++++++++++++++++++++++++---------- transpose/transpose | 2 +- 7 files changed, 87 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 81284ac..8cf9ea1 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ CMD = blink 2grep 2search burncpu drac duplicate-packets em emoticons \ - encdir field find-first-fail forever fxkill G gitnext gitundo \ - goodpasswd histogram Loffice mtrr mirrorpdf neno not off \ - pdfman pidcmd pidtree plotpipe puniq ramusage rand rclean \ - rina rn rrm seekmaniac shython sound-reload splitvideo stdout \ - swapout T teetime timestamp tracefile transpose upsidedown \ - vid w4it-for-port-open whitehash wifi-reload wssh ytv \ - yyyymmdd + encdir fanspeed field find-first-fail forever fxkill G \ + gitnext gitundo goodpasswd histogram Loffice mtrr mirrorpdf \ + neno not off pdfman pidcmd pidtree plotpipe puniq ramusage \ + rand rclean rina rn rrm seekmaniac shython sound-reload \ + splitvideo stdout swapout T teetime timestamp tracefile \ + transpose upsidedown vid w4it-for-port-open whitehash \ + wifi-reload wssh ytv yyyymmdd all: blink/blink.1 2search/2grep.1 2search/2search.1 \ - burncpu/burncpu.1 drac/drac.1 encdir/encdir.1 field/field.1 \ + burncpu/burncpu.1 drac/drac.1 encdir/encdir.1 \ + fanspeed/fanspeed.1 field/field.1 \ find-first-fail/find-first-fail.1 G/G.1 gitnext/gitnext.1 \ gitundo/gitundo.1 goodpasswd/goodpasswd.1 \ histogram/histogram.1 mirrorpdf/mirrorpdf.1 neno/neno.1 \ diff --git a/README b/README index 5ff4ad3..6daa66c 100644 --- a/README +++ b/README @@ -4,6 +4,8 @@ Probably not useful for you, but then again you never now. 2search - binary search through sorted text files. +burncpu - use 100% of some CPU threads. + blink - blink disks in a disk enclosure. decrypt-root-with-usb - patch for cryptroot to decrypt root with key on USB. @@ -12,6 +14,10 @@ duplicate-packets - duplicate packets on an interface. Useful if wifi is bad. em - force emacs to run in terminal. Use xemacs if installed. +encdir - mount encfs dir or create it if missing. + +fanspeed - set fanspeed using IPMI on Dell R815. + field - split on whitespace. Give the given field number. Supports syntax 1-3,6- find-first-fail - find the lowest argument that makes a command fail. @@ -64,6 +70,8 @@ swapout - force swapping out. T - tee stdout to and from temporary files. +teetime - Save stdin including timing. + timestamp - prepend timestamp to output. tracefile - list files/dirs being accessed by program. diff --git a/find-first-fail/testsuite b/find-first-fail/testsuite index e3c1b32..154a040 100644 --- a/find-first-fail/testsuite +++ b/find-first-fail/testsuite @@ -41,6 +41,9 @@ test_file() { tmp=`tempfile` echo Header > $tmp seq 100 >> $tmp + echo 10 >> $tmp + echo 12 >> $tmp + echo 15 >> $tmp 10_to_15() { grep ^10$ $1 && grep ^15$ $1; } export -f 10_to_15 echo 10..15 diff --git a/plotpipe/plotpipe b/plotpipe/plotpipe index 2b15e46..59c12c8 100755 --- a/plotpipe/plotpipe +++ b/plotpipe/plotpipe @@ -154,7 +154,7 @@ B uses B. =head1 SEE ALSO -B +B, B =cut @@ -182,12 +182,12 @@ sub version() { # Returns: N/A print join ("\n", - "GNU $Global::progname $Global::version", + "$Global::progname $Global::version", "Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software", "Foundation, Inc.", "License GPLv3+: GNU GPL version 3 or later ", "This is free software: you are free to change and redistribute it.", - "GNU $Global::progname comes with no warranty.", + "$Global::progname comes with no warranty.", "", "Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n", "", diff --git a/tracefile/test.sh b/tracefile/test.sh index 1a470db..b4282cb 100644 --- a/tracefile/test.sh +++ b/tracefile/test.sh @@ -22,3 +22,6 @@ parallel -vj1 doit \ # opening file relative to file descriptor of openat tracefile lscpu | grep /sys/devices/system/cpu/cpu0/cache/index0/level + +echo "should be 635 lines" +tracefile -u perl -e 'for(1..4) { `parallel echo ::: 1 2 3` }' |wc diff --git a/tracefile/tracefile b/tracefile/tracefile index e064109..1366b80 100755 --- a/tracefile/tracefile +++ b/tracefile/tracefile @@ -245,17 +245,20 @@ B(1) =cut use Getopt::Long; - +sub version(); $Global::progname = "tracefile"; +$Global::version = 20201211; Getopt::Long::Configure("bundling","require_order"); get_options_from_array(\@ARGV) || die_usage(); +if($opt::version) { version(); exit(0); } init_functions(); my @cmd = shell_quote(@ARGV); my $dir = "."; my $pid = $opt::pid ? "-p $opt::pid" : ""; my %seen; +my $multithreading_printed; # BUG: If command gives output on stderr that can confuse the strace output open(IN, "-|", "strace -ff $pid -e trace=file @cmd 2>&1 >/dev/null") || die; @@ -265,20 +268,21 @@ while() { } # [pid 30817] stat("t/tar.gz", {st_mode=S_IFREG|0644, st_size=140853248, ...}) = 0 # openat(AT_FDCWD, "/tmp/a", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3 - if(/^(\[[^]]+\])? # Match pid - \s*([^\" ]+) # function e.g. openat - [(] # ( - ([^",]*) # E.g. AT_FDCWD or 4 - [^"]* # E.g. , - " # " - (([^\\"]|\\[\\"nt])*) # content of string with \n \" \t \\ - "(.*)/x) # Rest + if(/^(?:[<]*)? # , O_RDONLY|O_CLOEXEC + (?:\[[^]]+\])? # Match pid: [pid 46932] + \s*([^\" ]+) # function e.g. openat + [(] # ( + ([^",]*) # E.g. AT_FDCWD or 4 + [^"]* # E.g. , + " # " + ((?:[^\\"]|\\[\\"nt])*) # content of string with \n \" \t \\ + "(.*)/x) # Rest { # Matches the strace structure for a file - my $function = $2; - my $first_arg = $3; - my $file = shell_unquote($4); - my $addinfo = $6; + my $function = $1; + my $first_arg = $2; + my $file = shell_unquote($3); + my $addinfo = $4; if($function eq "openat" or $function eq "faccessat") { @@ -287,14 +291,24 @@ while() { # faccessat(4, "cpu0/cache/index4", F_OK) = -1 ENOENT # openat can open a file descriptor # openat/faccessat can open relative to a file descriptor - $addinfo =~ /= (-?\d+)(\s[^=]*)?$/ || die $addinfo,$_; - my $fd = $1; - if($first_arg eq "AT_FDCWD") { + if($addinfo =~ /= (-?\d+)(\s[^=]*)?$/) { + my $fd = $1; + if($first_arg eq "AT_FDCWD") { + $fd{$fd} = $file; + } elsif($first_arg =~ /^\d+$/) { + $file = $fd{$first_arg}."/".$file; + } else { die "Bug: ",$first_arg,$_; } $fd{$fd} = $file; - } elsif($first_arg =~ /^\d+$/) { - $file = $fd{$first_arg}."/".$file; - } else { die $first_arg,$_; } - $fd{$fd} = $file; + } else { + if($addinfo =~ / + if(not $opt::quiet and not $multithreading_printed++) { + warning("Multi-threading not supported. Output may be wrong."); + } + } else { + die("Wrong format:",$addinfo,$_); + } + } } # Relative to $dir $file =~ s:^([^/]):$dir/$1:; @@ -323,7 +337,14 @@ while() { $print = 0; } $print and print $file,"\n"; - } + } else { + $opt::debug || next; + /^strace: Process .* attached/ && next; + /^(?:.pid \d+. )?<... \S+ resumed>/ && next; + /^(?:.pid \d+. )?... exited with / && next; + /^(?:.pid \d+. )?--- SIG/ && next; + warn "W:",$_; + } } { @@ -392,6 +413,8 @@ sub options_hash { # Returns a hash of the GetOptions config return ("debug|D" => \$opt::debug, + "quiet|q" => \$opt::quiet, + "version|V" => \$opt::version, "dir|d" => \$opt::dir, "file|f" => \$opt::file, "uniq|unique|u" => \$opt::unique, @@ -487,6 +510,22 @@ sub error { print $fh $prog, ": Error: ", @w; } +sub version() { + # Returns: N/A + print join + ("\n", + "$Global::progname $Global::version", + "Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software", + "Foundation, Inc.", + "License GPLv3+: GNU GPL version 3 or later ", + "This is free software: you are free to change and redistribute it.", + "$Global::progname comes with no warranty.", + "", + "Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n", + ); + +} + sub my_dump(@) { # Returns: # ascii expression of object if Data::Dump(er) is installed diff --git a/transpose/transpose b/transpose/transpose index b97c717..d5052b9 100755 --- a/transpose/transpose +++ b/transpose/transpose @@ -493,7 +493,7 @@ transpose 20201130 Copyright (C) 2020 Ole Tange, http://ole.tange.dk License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. -GNU parallel comes with no warranty. +transpose comes with no warranty. Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/transpose EOF