title: accurately timing an execution of a system call using perl
body: <p>Is there a better way programmatically using perl to track the timing of a unix process (start time, end time)??</p>
  
  <p>For example, I have a perl script that launches a unix command using system(). I print the timestamp before the system() and after. </p>
  
  <p>My log of the start time and end time are the same. I know for sure that when the process completes its a matter of minutes, so its not accurate.</p>
  
  <p>Here's my code thus far:</p>
  
  <pre><code>my $dt  = strftime('%Y%m%d', localtime(time));
  my $dt2 = strftime('%Y%m%d-%H:%M:%S', localtime(time)); 
  my @tbls = qx(mysql -u foo -pmypw --database $dbsrc -h $node -ss -e "show tables");
  
  open (CRLOG, "&gt;dump-$dt.log") || die "cannot append";
  foreach my $tbls (@tbls)
  {
     chomp $tbls;
     print CRLOG "TIME START =&gt; $dt2\n";
     my $crfile = qq{mysql -u foo -pmypw --database $dbsrc -h $node.test.com -ss -e "SELECT 'a','b','c' UNION SELECT 1,2,3 FROM $tbls"| tr "\t" ","&gt;$node-$tbls.$dt.csv};   system($crfile); 
     print CRLOG "COMMAND =&gt; $crfile\n";
     print CRLOG "TIME END =&gt; $dt2\n";
  }; 
  close (CRLOG);
  </code></pre>