LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-11-2009, 04:12 AM   #1
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Rep: Reputation: 30
Measure script


Hi
Can anyone help me with a script to measure the time it takes process a request from start to finish.
the request will be and xml api post request i have a script that measures the total time but i would like to get the time for each activity it makes

Code:
#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use Time::HiRes qw(tv_interval gettimeofday);
use Time::HiRes qw(tv_interval gettimeofday);

my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my ($totaltime, $success, $error, $requests, $process);


my $debug = 1;
$totaltime = 0;
$success = 0;
$error = 0;

$mon=$mon+1;
if ($mon < 10) { $mon = "0$mon"; }
if ($day < 10) { $day = "0$day"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
$year=$year+1900;

open (LOG, ">>/root/gdsresponsetimelog.log");

sub do_work() {
my ($starttime, $time);
my $ua = LWP::UserAgent->new(agent => 'responsetime tracker');

my $request = "<?xml version='1.0'?>
<soap:Envelope soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\" xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\">
<soap:Body>
    <authentication>
      <affiliate>CD61</affiliate>
    </authentication>
    <query>
      <show_rooms>yes</show_rooms>
      <command>Search Multiple hotels</command>
      <hotels>
        <hotel>
          <id>192</id>
        </hotel>
        <hotel>
          <id>1801</id>
        </hotel>
        <hotel>
          <id>2978</id>
        </hotel>
      </hotels>
      <nr_adults>2</nr_adults>
      <nr_children/>
      <arrival>2009-09-22</arrival>
      <departure>2009-09-23</departure>
</query>
  </soap:Body>
</soap:Envelope>";

$starttime = [gettimeofday];
my $response = $ua->request(POST 'http://xml.site.net/xml/',
Content_Type => 'application/x-www-form-urlencoded',
Content => ['query' => $request]);

++$success if !$response->is_success;
++$error if $response->is_success;
print $response->as_string if $debug;
$time = tv_interval($starttime, [gettimeofday]);
$totaltime = $totaltime + $time;
return ($totaltime, $error, $success);
}

($totaltime, $success, $error) = do_work;

if ($success) {
        print LOG "$mon$day$hour$min -- OK -- TOTAL TIME: $totaltime\n";
} elsif ($error) {
        print LOG "$mon$day$hour$min -- ERROR -- TOTAL TIME: $totaltime\n";
}

close (LOG);
 
Old 06-11-2009, 08:51 PM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
This ought to be in the programming section.
 
Old 06-12-2009, 05:55 AM   #3
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Original Poster
Rep: Reputation: 30
dont know how to move it
 
Old 06-12-2009, 06:53 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Moved to Programming.....
 
Old 06-12-2009, 02:41 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by mahmoud View Post
Hi
Can anyone help me with a script to measure the time it takes process a request from start to finish.
the request will be and xml api post request i have a script that measures the total time but i would like to get the time for each activity it makes

Code:
#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use Time::HiRes qw(tv_interval gettimeofday);
use Time::HiRes qw(tv_interval gettimeofday);

my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my ($totaltime, $success, $error, $requests, $process);


my $debug = 1;
$totaltime = 0;
$success = 0;
$error = 0;

$mon=$mon+1;
if ($mon < 10) { $mon = "0$mon"; }
if ($day < 10) { $day = "0$day"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
$year=$year+1900;

open (LOG, ">>/root/gdsresponsetimelog.log");

sub do_work() {
my ($starttime, $time);
my $ua = LWP::UserAgent->new(agent => 'responsetime tracker');

my $request = "<?xml version='1.0'?>
<soap:Envelope soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\" xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\">
<soap:Body>
    <authentication>
      <affiliate>CD61</affiliate>
    </authentication>
    <query>
      <show_rooms>yes</show_rooms>
      <command>Search Multiple hotels</command>
      <hotels>
        <hotel>
          <id>192</id>
        </hotel>
        <hotel>
          <id>1801</id>
        </hotel>
        <hotel>
          <id>2978</id>
        </hotel>
      </hotels>
      <nr_adults>2</nr_adults>
      <nr_children/>
      <arrival>2009-09-22</arrival>
      <departure>2009-09-23</departure>
</query>
  </soap:Body>
</soap:Envelope>";

$starttime = [gettimeofday];
my $response = $ua->request(POST 'http://xml.site.net/xml/',
Content_Type => 'application/x-www-form-urlencoded',
Content => ['query' => $request]);

++$success if !$response->is_success;
++$error if $response->is_success;
print $response->as_string if $debug;
$time = tv_interval($starttime, [gettimeofday]);
$totaltime = $totaltime + $time;
return ($totaltime, $error, $success);
}

($totaltime, $success, $error) = do_work;

if ($success) {
        print LOG "$mon$day$hour$min -- OK -- TOTAL TIME: $totaltime\n";
} elsif ($error) {
        print LOG "$mon$day$hour$min -- ERROR -- TOTAL TIME: $totaltime\n";
}

close (LOG);
What exactly is "each activity" ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to measure system jitter nitinarora Linux - Kernel 2 05-26-2009 04:05 PM
pppd, wvdial, ip-down script | monthly bandwidth measure number-g Linux - Networking 1 05-02-2009 06:08 PM
a way to measure how much flops your PC can do? pusrob Linux - Hardware 3 11-14-2007 10:54 AM
Tool or script to measure bandwdith koolkicks311 Linux - Software 1 04-20-2007 11:28 PM
Measure disk performance smokinghound Linux - Hardware 1 07-10-2003 09:58 AM


All times are GMT -5. The time now is 08:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration