I have a log file in which there are plenty of threads. i want to count the number of unique threads.Here thread is tid value.
My Logfile looks like this--
Wed May 20 05:22:53.993 2009 Morocco Standard Time INFO: pid 2172 tid 688: 17: 10106931: ArAuthFrameworkImpl::doPreAuth::1:10106931:: Authentication mechanism returned [0] for AuthIdentity []
Wed May 20 05:22:53.993 2009 Morocco Standard Time INFO: pid 2172 tid 688: 170: 10106931: Arcot Native Server: recvd AA_BIN_MSG_VER_CHG
Wed May 20 05:22:57.634 2009 Morocco Standard Time INFO: pid 2172 tid 3352: 170: 10106932: Arcot Native Server: recvd AA_BIN_MSG_GET_WLT
Wed May 20 05:22:57.634 2009 Morocco Standard Time INFO: pid 2172 tid 3352: 170: 10106932: Session tracker Id associated with generate challenge[1:10106932]
Like this there are thousands of threads in a log file.
i want to capture the unique threads and count the numbers.
Any kind of help or suggestion will be very useful to me.
i am using this code and it's giving me whole count including the repated ones. I just want to get the count of unique threads. please suggest me what i need to do to achieve 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";
what is $tidUnique here? how it is going to work in my case. Can you suggest me in my code.
when i used the code like this-
my $TIDCount = 0;
while(my $line = <$log>) {
# Outer loop. Look for an interesting part of the log file.
$n++;
$line =~ tr/\r\n//d;
++$TIDcount ;
if /tid (\d+)/ && !$tidUnique{$1}++;
next;
}
print "Thread count for the logfile is $TIDCount\n";
it gave me these errors
syntax error at tid_count.pl line 17, near "if /tid (\d+)/"
syntax error at tid_count.pl line 17, near "++;"
syntax error at tid_count.pl line 20, near "}"
Execution of tid_count.pl aborted due to compilation errors.
#!/usr/bin/perl
use warnings;
use strict;
print "Hello, World...\n";
my $logFile = shift;
my ( $TIDCount, %TIDUnique );
die "usage: $0 <logFile>\n" unless defined $logFile;
die "Logfile $logFile doesn't exist\n" unless -f $logFile;
open my $log, $logFile or die "Can't open $logFile for reading\n";
print "Processing file $logFile...\n";
while (<$log>) {
++$TIDCount
if / tid (\d+)/ && !$TIDUnique{$1}++;
}
print "Thread count for the logfile is $TIDCount\n";