Presumably you have a loop reading the log file like:
while (my $logline = <LOG>) { # parse it }
Making a process max out at a certain percentage of CPU is not easy to do (because it's generally not a useful thing to do; if the CPU isn't otherwise used, why not use 100%? and if there are other things running, setting different priorities works out better) especially I think on Windows. It may be sufficient for your purposes just to put in a line like sleep 1 unless $. % 100 which makes perl stop for at least a second every 100 lines.

However, you may be able to get the linux code you posted to work by getting rid of sub Cat entirely and making CPU_used like:

sub CPU_used { (map $_->[0]+$_->[1], [times])[0] }
But unless I'm totally misunderstanding it, you should be using CPU_max(.2) to get a max of 20% CPU use.

Update: note that calling CPU_max every iteration is counterproductive; I'd figure out how many lines you process per second and make your code:

CPU_start(); while (my $logline = <LOG>) { # parse it CPU_max(.2) unless $. % $lines_per_second; }
(using your lines per second figure, and adjusting if needed for finer granularity.)

In reply to Re: CPU utilization by ysth
in thread CPU utilization by contact_chatan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.