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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-11-2009, 04:12 AM
|
#1
|
|
Member
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269
Rep:
|
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);
|
|
|
|
06-11-2009, 08:51 PM
|
#2
|
|
Member
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961
Rep:
|
This ought to be in the programming section.
|
|
|
|
06-12-2009, 05:55 AM
|
#3
|
|
Member
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269
Original Poster
Rep:
|
dont know how to move it
|
|
|
|
06-12-2009, 06:53 AM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Moved to Programming.....
|
|
|
|
06-12-2009, 02:41 PM
|
#5
|
|
Senior Member
Registered: May 2005
Posts: 4,397
|
Quote:
Originally Posted by mahmoud
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" ?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:08 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|