in reply to thread count

Create a unique key from the tid/pid by extracting those values from the log file (e.g. with a regex match), and then use a hash to count those keys' occurrences: $count{$key}++; (by iterating over the lines of the file)

Replies are listed 'Best First'.
Re^2: thread count
by namishtiwari (Acolyte) on Jun 10, 2009 at 12:48 UTC
    what i have tried is this--
    #!/usr/bin/perl -w print "Hello, World...\n"; my $logFile = $ARGV[0]; die "usage: $0 <logFile>" unless $logFile; die "Logfile $logFile doesn't exist" unless -f "$logFile"; open(my $log, "<", $logFile) or die "Can't open $logFile for reading." +; print "Processing file $logFile...\n"; #my $authenticates = {}; my $n = 0; my $TIDCount = 0; while(my $line = <$log>) { # Outer loop. Look for an interesting part of the log file. $n++; $line =~ tr/\r\n//d; if($line =~ /tid (\d+)/){ $TIDCount++; next; } } print "Thread count for the logfile is $TIDCount\n";
    but it is giving me the whole count including the repated ones, but i just want the count of unique threads. Thanks NT
      Did you read almut's post. There is a big clue in it, if you capture the digits after 'tld ', which you do, you can assign them to a value, if you put the scalar into a list context with brackets
      my $substring; my $string="For those about to rock"; ($substring)=$string=~/^.+?to (\w+)/; print "So, we're going to $substring then?\n";
      using this type of structure you can identify specific threads, then if you increment $threads{$substring} you have an array  keys %threads which contains the thread id of each thread, you even have a count of how busy they are in the logfiles ;)
        I am sorry but i did not get a clear idea how i should go about it. i have this piece of code which gives me total number of threads but not the unique ones.
        while(my $line = <$log>) { # Outer loop. Look for an interesting part of the log file. $n++; $line =~ tr/\r\n//d; ++$TIDCount; ($tid) = $line =~ /tid (\d+)/; print $tid "\n"; $tidc{$tid}++; } print "Thread count for the logfile is $TIDCount\n";
        i want the count of unique threads not the repeated one. if you can give me an example of this not necessarily my code, then it will be great. I am a novice in perl. Thanks NT