This commit is contained in:
Ole Tange 2020-12-12 02:02:25 +01:00
parent 8be6d39649
commit e1c04807d4
7 changed files with 87 additions and 33 deletions

View file

@ -1,14 +1,15 @@
CMD = blink 2grep 2search burncpu drac duplicate-packets em emoticons \ CMD = blink 2grep 2search burncpu drac duplicate-packets em emoticons \
encdir field find-first-fail forever fxkill G gitnext gitundo \ encdir fanspeed field find-first-fail forever fxkill G \
goodpasswd histogram Loffice mtrr mirrorpdf neno not off \ gitnext gitundo goodpasswd histogram Loffice mtrr mirrorpdf \
pdfman pidcmd pidtree plotpipe puniq ramusage rand rclean \ neno not off pdfman pidcmd pidtree plotpipe puniq ramusage \
rina rn rrm seekmaniac shython sound-reload splitvideo stdout \ rand rclean rina rn rrm seekmaniac shython sound-reload \
swapout T teetime timestamp tracefile transpose upsidedown \ splitvideo stdout swapout T teetime timestamp tracefile \
vid w4it-for-port-open whitehash wifi-reload wssh ytv \ transpose upsidedown vid w4it-for-port-open whitehash \
yyyymmdd wifi-reload wssh ytv yyyymmdd
all: blink/blink.1 2search/2grep.1 2search/2search.1 \ 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 \ find-first-fail/find-first-fail.1 G/G.1 gitnext/gitnext.1 \
gitundo/gitundo.1 goodpasswd/goodpasswd.1 \ gitundo/gitundo.1 goodpasswd/goodpasswd.1 \
histogram/histogram.1 mirrorpdf/mirrorpdf.1 neno/neno.1 \ histogram/histogram.1 mirrorpdf/mirrorpdf.1 neno/neno.1 \

8
README
View file

@ -4,6 +4,8 @@ Probably not useful for you, but then again you never now.
2search - binary search through sorted text files. 2search - binary search through sorted text files.
burncpu - use 100% of some CPU threads.
blink - blink disks in a disk enclosure. blink - blink disks in a disk enclosure.
decrypt-root-with-usb - patch for cryptroot to decrypt root with key on USB. 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. 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- 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. 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. T - tee stdout to and from temporary files.
teetime - Save stdin including timing.
timestamp - prepend timestamp to output. timestamp - prepend timestamp to output.
tracefile - list files/dirs being accessed by program. tracefile - list files/dirs being accessed by program.

View file

@ -41,6 +41,9 @@ test_file() {
tmp=`tempfile` tmp=`tempfile`
echo Header > $tmp echo Header > $tmp
seq 100 >> $tmp seq 100 >> $tmp
echo 10 >> $tmp
echo 12 >> $tmp
echo 15 >> $tmp
10_to_15() { grep ^10$ $1 && grep ^15$ $1; } 10_to_15() { grep ^10$ $1 && grep ^15$ $1; }
export -f 10_to_15 export -f 10_to_15
echo 10..15 echo 10..15

View file

@ -154,7 +154,7 @@ B<pipeplot> uses B<gnuplot>.
=head1 SEE ALSO =head1 SEE ALSO
B<gnuplot> B<perl>, B<gnuplot>
=cut =cut
@ -182,12 +182,12 @@ sub version() {
# Returns: N/A # Returns: N/A
print join print join
("\n", ("\n",
"GNU $Global::progname $Global::version", "$Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software", "Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.", "Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>", "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.", "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", "Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n",
"", "",

View file

@ -22,3 +22,6 @@ parallel -vj1 doit \
# opening file relative to file descriptor of openat # opening file relative to file descriptor of openat
tracefile lscpu | grep /sys/devices/system/cpu/cpu0/cache/index0/level 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

View file

@ -245,17 +245,20 @@ B<strace>(1)
=cut =cut
use Getopt::Long; use Getopt::Long;
sub version();
$Global::progname = "tracefile"; $Global::progname = "tracefile";
$Global::version = 20201211;
Getopt::Long::Configure("bundling","require_order"); Getopt::Long::Configure("bundling","require_order");
get_options_from_array(\@ARGV) || die_usage(); get_options_from_array(\@ARGV) || die_usage();
if($opt::version) { version(); exit(0); }
init_functions(); init_functions();
my @cmd = shell_quote(@ARGV); my @cmd = shell_quote(@ARGV);
my $dir = "."; my $dir = ".";
my $pid = $opt::pid ? "-p $opt::pid" : ""; my $pid = $opt::pid ? "-p $opt::pid" : "";
my %seen; my %seen;
my $multithreading_printed;
# BUG: If command gives output on stderr that can confuse the strace output # 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; open(IN, "-|", "strace -ff $pid -e trace=file @cmd 2>&1 >/dev/null") || die;
@ -265,20 +268,21 @@ while(<IN>) {
} }
# [pid 30817] stat("t/tar.gz", {st_mode=S_IFREG|0644, st_size=140853248, ...}) = 0 # [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 # openat(AT_FDCWD, "/tmp/a", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
if(/^(\[[^]]+\])? # Match pid if(/^(?:[<]*<unfinished ...>)? # , O_RDONLY|O_CLOEXEC <unfinished ...>
\s*([^\" ]+) # function e.g. openat (?:\[[^]]+\])? # Match pid: [pid 46932]
[(] # ( \s*([^\" ]+) # function e.g. openat
([^",]*) # E.g. AT_FDCWD or 4 [(] # (
[^"]* # E.g. , ([^",]*) # E.g. AT_FDCWD or 4
" # " [^"]* # E.g. ,
(([^\\"]|\\[\\"nt])*) # content of string with \n \" \t \\ " # "
"(.*)/x) # Rest ((?:[^\\"]|\\[\\"nt])*) # content of string with \n \" \t \\
"(.*)/x) # Rest
{ {
# Matches the strace structure for a file # Matches the strace structure for a file
my $function = $2; my $function = $1;
my $first_arg = $3; my $first_arg = $2;
my $file = shell_unquote($4); my $file = shell_unquote($3);
my $addinfo = $6; my $addinfo = $4;
if($function eq "openat" if($function eq "openat"
or or
$function eq "faccessat") { $function eq "faccessat") {
@ -287,14 +291,24 @@ while(<IN>) {
# faccessat(4, "cpu0/cache/index4", F_OK) = -1 ENOENT # faccessat(4, "cpu0/cache/index4", F_OK) = -1 ENOENT
# openat can open a file descriptor # openat can open a file descriptor
# openat/faccessat can open relative to a file descriptor # openat/faccessat can open relative to a file descriptor
$addinfo =~ /= (-?\d+)(\s[^=]*)?$/ || die $addinfo,$_; if($addinfo =~ /= (-?\d+)(\s[^=]*)?$/) {
my $fd = $1; my $fd = $1;
if($first_arg eq "AT_FDCWD") { 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; $fd{$fd} = $file;
} elsif($first_arg =~ /^\d+$/) { } else {
$file = $fd{$first_arg}."/".$file; if($addinfo =~ /<unfinished|strace: Process .* attached|= [?]/) {
} else { die $first_arg,$_; } # openat(AT_FDCWD, "/...", O_RDONLY|O_CLOEXEC <unfinished ...>
$fd{$fd} = $file; 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 # Relative to $dir
$file =~ s:^([^/]):$dir/$1:; $file =~ s:^([^/]):$dir/$1:;
@ -323,7 +337,14 @@ while(<IN>) {
$print = 0; $print = 0;
} }
$print and print $file,"\n"; $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 # Returns a hash of the GetOptions config
return return
("debug|D" => \$opt::debug, ("debug|D" => \$opt::debug,
"quiet|q" => \$opt::quiet,
"version|V" => \$opt::version,
"dir|d" => \$opt::dir, "dir|d" => \$opt::dir,
"file|f" => \$opt::file, "file|f" => \$opt::file,
"uniq|unique|u" => \$opt::unique, "uniq|unique|u" => \$opt::unique,
@ -487,6 +510,22 @@ sub error {
print $fh $prog, ": Error: ", @w; 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 <https://gnu.org/licenses/gpl.html>",
"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(@) { sub my_dump(@) {
# Returns: # Returns:
# ascii expression of object if Data::Dump(er) is installed # ascii expression of object if Data::Dump(er) is installed

View file

@ -493,7 +493,7 @@ transpose 20201130
Copyright (C) 2020 Ole Tange, http://ole.tange.dk Copyright (C) 2020 Ole Tange, http://ole.tange.dk
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. 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 Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/transpose
EOF EOF