add option to list snapshots
authorMark Wong <markwkm@gmail.com>
Sat, 27 Mar 2010 12:42:41 +0000 (05:42 -0700)
committerMark Wong <markwkm@gmail.com>
Sat, 27 Mar 2010 12:42:41 +0000 (05:42 -0700)
Added a -list flag to list all snapshots and their comments.

contrib/ps-util.pl

index 5798a420fdc974420d17ca40ba551410925022e4..c78ce97a75981507702e2ca3c93499316a4c7700 100755 (executable)
@@ -9,19 +9,21 @@ use Getopt::Long;
 use Data::Dumper::Simple;
 $Data::Dumper::Indent  = 1;
 
-my ($db, $pid, $snap_1, $snap_2);
+my ($db, $list, $pid, $snap_1, $snap_2);
 
 GetOptions(
        "db=s"  => \$db,
+       "list"  => \$list,
        "pid=i" => \$pid,
        "s1=i"  => \$snap_1,
        "s2=i"  => \$snap_2,
 );
 
 #better way to do this?
-if ((! $pid) or (! $snap_1) or (! $snap_2)) {
+if ((! $list) and ((! $pid) or (! $snap_1) or (! $snap_2))) {
        print <<USAGE
        You must supply a process id and two snapshot ids:
+       Usage: $0 [-d=<database>] -list
        Usage: $0 [-d=<database>] -p=<pid> -s1=<snap1> -s2=<snap2>
 USAGE
 ;
@@ -29,6 +31,13 @@ USAGE
 }
 
 $db    = "-d $db" if $db;
+
+if ($list) {
+       my $output = `psql $db -c "SELECT snap, time, note FROM ps_snaps ORDER BY time ASC"`;
+       print ("$output\n");
+       exit 0;
+}
+
 my $hz = find_hz();
 print ("HERTZ: $hz\n");