hi,
LWP fetches normally by 4k chunks, if you want to time them
you can use the code1 below.
On the other hand for some reason code2 doesn't work.
The output should look something like specified below.
If you wrap "LWP::Protocol::collect", you will time the whole fetch, not every chunk.
One more thing which may be interesting to know is, that the timeout you specify (LWP,Mechanize...) is the timeout for every chunk not the whole request (default:180sec).
So the request timeout could go far above 3 min.
hth
-----code1-----
use LWP::Debug qw(+);
use Time::HiRes qw(gettimeofday tv_interval);
my $ts;
use LWP::Protocol::http;
use Hook::LexWrap;
wrap 'LWP::Protocol::http::SocketMethods::sysread',
pre => sub { $ts = [gettimeofday] },
post => sub { printf ">>%.5f\n" , tv_interval($ts) };
-----code2-----
use LWP::Debug qw(+);
use Aspect;
my $pcut = call qr/LWP::Protocol::http::SocketMethods::sysread/;
before { $ts = [gettimeofday] } $pcut;
after { printf ">>%.5f\n" , tv_interval($ts) } $pcut;
====output=====
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
>>0.00536
LWP::Protocol::collect: read 796 bytes
>>0.00007
LWP::Protocol::collect: read 3356 bytes
>>0.00071
LWP::Protocol::collect: read 1460 bytes
>>0.00103
LWP::Protocol::collect: read 1460 bytes
>>0.00005
LWP::Protocol::collect: read 997 bytes
LWP::UserAgent::request: Simple response: OK
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.