thread count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting thread count
# 1  
Old 06-10-2009
thread count

Hi,

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--

Code:
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.

Thanks
NT
# 2  
Old 06-10-2009
Code:
 awk 'BEGIN { FS1="[: ]+"}
{
        FS=FS1
        print $15
}' data > outfile

for tid in `cat outfile | /bin/sort -u`
do
        echo $tid appears `grep $tid outfile | wc -l` times.
done

# 3  
Old 06-10-2009
Code:
perl -ne'
  / tid (\d+)/ && $tid{$1}++;
  print map "$_: $tid{$_}\n", keys %tid
    if eof
  ' infile

# 4  
Old 06-10-2009
Try this:

Code:
awk '{a[$13]++}END{for(i in a){print i, a[i]}}' file

# 5  
Old 06-10-2009
Quote:
Originally Posted by radoulov
Code:
perl -ne'
  / tid (\d+)/ && $tid{$1}++;
  print map "$_: $tid{$_}\n", keys %tid
    if eof
  ' infile

Hi ,

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.

Code:
#!/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";

thanks
NT
# 6  
Old 06-10-2009
You should use something like this:

Code:
 ++$TIDcount 
    if / tid (\d+)/ && !$tidUnique{$1}++;

Given you sample data:

Code:
% perl -nle'
  ++$c if / tid (\d+)/ && !$tid{$1}++;
  print $c if eof
  ' infile
2

# 7  
Old 06-10-2009
Borrowing from Franklin52:
Code:
awk '{a[$13]++}END{for(i in a) if (a[i]==1) uniq++; print uniq }' file

Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

2. UNIX for Dummies Questions & Answers

Thread count for a process id

Hi, I want to know a command/program to get thread count for a process id in unix box. Please help me in this regard. (1 Reply)
Discussion started by: manaac
1 Replies

3. Solaris

thread count using top

I am running a multithreaded program which creates 10 threads and works away. However, when I use top to monitor my program whilst it is running, it only shows 4 under the thread count! Can anyone explain if this is in fact the number of threads running in my process... (0 Replies)
Discussion started by: supahoop
0 Replies

4. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies
Login or Register to Ask a Question