Instead of reading one line at a time from the log file, I want to read a block and keep it in memory (lets say 10 kb) , However we are facing some problem then how our parser will react as it read file line by line instead of chunk of file and in this case how will I parse our log file.
Perl has a Win32 package. How can I use this package to reduce the CPU usage as I got the following line of code but I am unable to use it.
As it gives cpu time always 0. I am working on windows platform: (I think we have the problem in red as it may be for linux then how can I use this code for windows.)
Link of code is: resource control: CPU
Seeking a great help from your side. Please do it as soon as because it is very urgent for me.CPU_start(); CPU_max(30) while 1; use Time::HiRes qw(time); sub CPU_used { (map {$_->[13]+$_->[14]} [split " ", Cat("/proc/self/stat")])[0] } { my %start = (tm => 0, cpu => 0); sub CPU_start { @start{"tm","cpu"} = (time(),CPU_used()) } sub CPU_max { my ($max, $real, $cpu) = ($_[0], time()-$start{tm}, CPU_used()-$start{cpu}); return unless defined($max) and $max > 0; &sleep( $cpu/$max-$real ); }} # # macro used from CPU_used() and CPU_max() # sub sleep { select undef,undef,undef,$_[0] } sub Cat { local *F; open F, "< ".$_[0] or return; local $/ unless wantarray; return <F>; }
Thanks
Chatanya Agrawal
20050224 Edit by ysth: code and p tags; id://-ify link
In reply to CPU utilization by contact_chatan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |