debug statements to debugs statements

2007-04-18 Thread Tsantilas Christos

Hi all,
  Here is a perl script which can be used to convert debug statements 
to new debugs statements :-) .

It mostly works or just  do standard errors.
It does not formats the output. I think the astyle can do the rest work.
Does not convert the debug statements, if the format string contains 
formating flags like %2.1f.


I think can be used as reference for other related convertions too.

Should I proceed with the convertion?
Should I post a patch to bugzila  or open a temporary branch on 
sourceforge better?


Regards,
Christos


#!/usr/bin/perl

#
# Author: Tsantilas Christos
# email:  [EMAIL PROTECTED]
#
#

use File::Copy;



$in=$ARGV[0];
$out=$in.converted;
print $in,$out;
copy($in, $in.original);

if(!open(IN,$in)){
print Can't open input file: $in\n;
exit -1;
}


if(!open(OUT,$out)){
print Can't open output file: $out\n;
exit -1;
}

my $i = 0;
my $line,$mod_statement;
my $t;


while(IN){
$line=$_;
if ( $line =~ /( |\t)debug\((\d*),( )*(\d*)\)/ ) {
	$i=0;
	while($line !~ /\);/){

	if (! ($t=IN) ){
		exit(-1);
	}

	$i=$i+1;
	if($i10){
		# More than 10 lines to a single debug statement?
		# something goes wrong in parsing
		exit(-1);
	}
	$line=$line.$t;
	}
	print Found a debug line : $line  \n;
	$mod_statement=process_debug_command($line);
	if($mod_statement){
	print Converted to line: $mod_statement \n;
	print OUT $mod_statement;
	}
	else{
print Not modified\n;
	print OUT $line;
}
	print -\n\n;
}
else{
	print OUT $line;
}
}

close(IN);
close(OUT);

# Here we believe that we correctly do any convertion so copy new file
# to the original 

copy($in.converted, $in);
exit(0);


sub process_debug_command{
my($line)[EMAIL PROTECTED];
my $dsec,$dlevel,$format,$args,$arg,$val;
my @array_args;

# Handle multilined strings
$line =~ s/\( |\n|\t)*\//g;

#remove newlines
$line =~ s/\n//g;

#print This is the line:$line\n;

#read debug section and level and debug arguments. 
$line =~ /debug\((\d*),( )*(\d*)\)( )*\((.*)\)\;/sm;
$dsec=$1; 
$dlevel=$3;
$args=$5;




if($args =~ /\(.*)\,(.*)/sm){
	$format=$1;
	$args=$2;
}
elsif($args =~ /\(.*)\$/sm){
	$format=$1;
	$args=;
}
else{
	return '';
}
#print Format str:,$format,\n,Args:,$args,\n;



@array_args = split(/,/ , $args );

#print debugs($dsec, $dlevel, $format;
#foreach $arg (@array_args){
#	$val=~ s/^(( |\n|\t)*)//;
#	chomp($val);

#	print , $arg;
#}
#print );\n;


$arg=shift(@array_args);
$arg=~ s/^(( |\n|\t)*)//;
chomp($arg);
# we understand the following %x formats
while( $format =~ s/%(s|lu|ld|d|u|p|x)/  $arg  / ){
	if(!$arg){
	return '';
	}
	$arg=shift(@array_args);
	$arg=~ s/^(( |\n|\t)*)//;
	chomp($arg);
}
if($arg){
 print ERROR remain arg:$arg\n;
 return '';
}
$format=debugs($dsec, $dlevel, \$format\ );\n;
#print debugs($dsec, $dlevel, \$format\ );\n;

return $format;
}


Re: debug statements to debugs statements

2007-04-18 Thread Adrian Chadd
On Wed, Apr 18, 2007, Tsantilas Christos wrote:
 Hi all,
   Here is a perl script which can be used to convert debug statements 
 to new debugs statements :-) .
 It mostly works or just  do standard errors.
 It does not formats the output. I think the astyle can do the rest work.
 Does not convert the debug statements, if the format string contains 
 formating flags like %2.1f.
 
 I think can be used as reference for other related convertions too.
 
 Should I proceed with the convertion?
 Should I post a patch to bugzila  or open a temporary branch on 
 sourceforge better?

I'm going to be slightly greedy/annoying here and say:

* Yes please! Because
* It cuts down on the amount of work required when migrating the codebase
  from C strings (and the C-string-like String type that Squid-3 is currently
  using) as there's a lot of places where C strings are debug'ed and I wasn't
  looking forward to converting them all to %*.s or similar (which allows you
  to pass an int length specifier before a buffer, a pre-requisite for
  logging strings when your strings suddenly aren't NUL-terminated!), but
* I'd just start submitting diffs against Squid-3-HEAD and include whatever can
  be done into the current codebase; this is something that can be done
  very incrementally and shouldn't have any actual operational impact, and
* It makes my next set of work easier (ie, starting to get rid of the C strings
  in Squid-3 and replacing them with String as a temporary stepping stone
  towards refcounted buffers.)

2c,




Adrian



Re: debug statements to debugs statements

2007-04-18 Thread Alex Rousskov
On Wed, 2007-04-18 at 11:30 +0300, Tsantilas Christos wrote:

Here is a perl script which can be used to convert debug statements 
 to new debugs statements :-) .
 It mostly works or just  do standard errors.
 It does not formats the output. I think the astyle can do the rest work.
 Does not convert the debug statements, if the format string contains 
 formating flags like %2.1f.

If you get a chance, please modify the script debugging/logging to use
one line for both the conversion status and the debug statement:

Found: $line\n
Converted: $mod_statement\n
LeftAsIs:  $line\n

This way it is much easier to grep/see debug statements that were _not_
converted, for example.


A few minor suggestions, if I may:

You may want to replace \d* in a line format with \w+ because the
arguments are required and sometimes contain variable names rather than
constants.

You may want to replace space and tab characters in the format with \s.

If you are not using a matched string, no need to use parens. For
example, this may work:
  if ( $line =~ /\sdebug\(\s*\w+\s*,\s*\w+\s*\)/ ) 


Thank you,

Alex.




Re: squid3-largeobj squid3/src AccessLogEntry.h,1.7,1.7.10.1 HttpHeader.cc,1.40,1.40.6.1 HttpHeader.h,1.18,1.18.6.1 HttpHeaderTools.cc,1.21,1.21.6.1 HttpMsg.cc,1.29,1.29.6.1 HttpMsg.h,1.14,1.14.6.1 Ht

2007-04-18 Thread Robert Collins
On Wed, 2007-04-18 at 20:52 +0200, Guido Serassio wrote:
 
 I think that here should be used the standard ISO C99 macro PRId64 
 like in Squid 2.6.
 This allow the portability of the code: on Windows %lld is not 
 available, when on some Unix 64 bit platforms (HP Tru64 is one) %ld 
 must be used instead of %lld. 

In squid3 we should be using stream formatting, not % based formatting,
which eliminates this class of problems.

-Rob
-- 
GPG key available at: http://www.robertcollins.net/keys.txt.


signature.asc
Description: This is a digitally signed message part


Re: cvs commit: squid3/src Store.h protos.h store.cc store_client.cc store_swapout.cc

2007-04-18 Thread Tsantilas Christos
Hi Duane,
  the StoreEntry::swapOut() does not compile when SIZEIF_OFF_T==4
I am using the following patch, but I am not sure if it is OK ...

Regards,
   Christos


--- store_swapout.cc18 Apr 2007 00:47:23 -  1.20
+++ store_swapout.cc18 Apr 2007 18:24:04 -
@@ -234,8 +234,8 @@
 #if SIZEOF_OFF_T == 4

 if (mem_obj-endOffset()  0x7FFF) {
-debug(20, 0) (WARNING: preventing off_t overflow for %s\n,
storeUrl(e));
-storeAbort(e);
+debug(20, 0) (WARNING: preventing off_t overflow for %s\n,
storeUrl(this));
+storeAbort(this);
 return;
 }


Duane Wessels wrote:
 ...
   Converted three store_swapout.cc functions to StoreEntry class methods
   
   storeSwapOut() is now StoreEntry::swapOut()
   storeSwapOutFileClose() is now StoreEntry::swapOutFileClose()
   storeSwapOutAble() is now Storeentry::swapOutAble()
   
  .


Re: debug statements to debugs statements

2007-04-18 Thread Tsantilas Christos
Thanks Alex,
  Also I handled some other minor cases and run it in my sources.

Some statistics:
 grep -n Converted CONVERT.log  |wc -l  - 2316
 grep -n LeftAsIs CONVERT.log  |wc -l  - 137

Only 5-6  cases needed some work by me. Now compiles and the debug info
I am getting looks OK.
I will continue testing the results and when I am ready I am going to
post the patch.

Regards,
Christos

Alex Rousskov wrote:
.
 
 If you get a chance, please modify the script debugging/logging to use
 one line for both the conversion status and the debug statement:
 
.
 
 A few minor suggestions, if I may:
  



Re: Rate Limiting using SQUID

2007-04-18 Thread Henrik Nordstrom
tis 2007-04-17 klockan 21:32 -0700 skrev Anand Lakshminath:
 Hi All,
 
 Is there a way to configure SQUID to rate limit requests to origin
 webservers. Basically, we don't want to hit any given website too hard
 and would like to throttle say 1 request per second.

The closest we have is the max-conn=N cache_peer option. Limits the
number of concurrent connections (==requests) to a given peer.

Plus the collapsed_forwarding feature which also helps a lot in reducing
storms on the backend servers..

Regards
Henrik


signature.asc
Description: Detta är en digitalt signerad	meddelandedel