source: LMDZ5/trunk/tools/fcm/lib/Fcm/Timer.pm @ 5220

Last change on this file since 5220 was 1578, checked in by jghattas, 13 years ago
  • Add fcm in LMDZ5/tools directory

It is no longer needed to have fcm in your environement PATH variable.
Now makelmdz_fcm takes by default this fcm. It is still possible to use
another fcm, using -fcm_path argument in makelmdz_fcm.

File size: 2.2 KB
Line 
1#!/usr/bin/perl
2# ------------------------------------------------------------------------------
3# NAME
4#   Fcm::Timer
5#
6# DESCRIPTION
7#   This is a package of timer utility used by the FCM command.
8#
9# COPYRIGHT
10#   (C) Crown copyright Met Office. All rights reserved.
11#   For further details please refer to the file COPYRIGHT.txt
12#   which you should have received as part of this distribution.
13# ------------------------------------------------------------------------------
14
15package Fcm::Timer;
16
17# Standard pragma
18use warnings;
19use strict;
20
21# Exports
22our (@ISA, @EXPORT, @EXPORT_OK);
23
24sub timestamp_command;
25
26require Exporter;
27@ISA = qw(Exporter);
28@EXPORT = qw(timestamp_command);
29
30# ------------------------------------------------------------------------------
31
32# Module level variables
33my %cmd_start_time = (); # Command start time, (key = command, value = time)
34
35# ------------------------------------------------------------------------------
36# SYNOPSIS
37#   $string = &Fcm::Timer::timestamp_command ($command[, $status]);
38#
39# DESCRIPTION
40#   This function returns a string adding to $command a prefix according the
41#   value of $status. If $status is not specified or does not match the word
42#   "end", the status is assumed to be "start". At "start", the prefix will
43#   contain the current timestamp. If $status is the word "end", the prefix
44#   will contain the total time taken since this function was called with the
45#   same $command at the "start" status.
46# ------------------------------------------------------------------------------
47
48sub timestamp_command {
49  (my $command, my $status) = @_;
50
51  my $prefix;
52  if ($status and $status =~ /end/i) {
53    # Status is "end", insert time taken
54    my $lapse = time () - $cmd_start_time{$command};
55    $prefix = sprintf "# Time taken: %12d s=> ", $lapse;
56
57  } else {
58    # Status is "start", insert time stamp
59    $cmd_start_time{$command} = time;
60
61    (my $sec, my $min, my $hour, my $mday, my $mon, my $year) = localtime;
62    $prefix = sprintf "# Start: %04d-%02d-%02d %02d:%02d:%02d=> ",
63              $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
64  }
65
66  return $prefix . $command . "\n";
67}
68
69# ------------------------------------------------------------------------------
70
711;
72
73__END__
Note: See TracBrowser for help on using the repository browser.