<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Modules::Prof;

########## Confixx(R) 3.1 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.swsoft.com - info@swsoft.com ####

BEGIN {
	use Exporter;
	@ISA = qw(Exporter);
	@EXPORT = qw(&amp;time_point);
}

my %conf = (
	'profile'	=&gt; 1,
	'warnings'	=&gt; 1
);

my %time_start = ();
my %time_stop  = ();

my %commands = (
	'start' 		=&gt; 'cmd_time_start',
	'stop'  		=&gt; 'cmd_time_stop',
	'print_close' 	=&gt; 'cmd_time_print_close',
	'stop_print' 	=&gt; 'cmd_time_stop_print',	
);

sub configure(%) {
	my (%new_conf) = @_;
	foreach my $param (keys %new_conf) {
		$conf{$param} = $new_conf{$param};
	}
	return 1;
}

sub time_point($;@) {
	@caller = caller;
	my ($cmd, @args) = @_;
	
	return 1 unless $conf{'profile'};	# do nothing

	unless (exists $commands{$cmd}) {
		&amp;prof_warn("Not existent command '$cmd' was called.");
		return 0;
	}
	my $ret = &amp;{$commands{$cmd}}(@args);
	@caller = ();
	return $ret;
}

sub cmd_time_start($) {
	my ($mark) = @_;
	
	if (exists $time_start{$mark}) {
		&amp;prof_warn("Redefining start-timepoint '$mark' ($time_start{$mark}).");	
	}
	$time_start{$mark} = time;
	return 1;
}

sub cmd_time_stop($) {
	my ($mark) = @_;
	
	if (exists $time_stop{$mark}) {
		&amp;prof_warn("Redefining stop-timepoint '$mark' ($time_stop{$mark}).");	
	}
	unless (exists $time_start{$mark}) {
		&amp;prof_warn("No matching start-timepoint '$mark' found.");	
	}
	$time_stop{$mark} = time;
	return 1;
}

sub cmd_time_close($) {
	my ($mark) = @_;

	unless (exists $time_start{$mark}) {
		&amp;prof_warn("Closing not existent start-timepoint '$mark'.");	
	}
	unless (exists $time_stop{$mark}) {
		&amp;prof_warn("Closing not existent stop-timepoint '$mark'.");	
	}
	
	delete ($time_start{$mark});
	delete ($time_stop{$mark});
	return 1;
}

sub cmd_time_print_close($$) {
	my ($mark, $msg) = @_;
	
	unless (exists $time_start{$mark}) {
		&amp;prof_warn("No start-timepoint '$mark' found.");	
	}
	unless (exists $time_stop{$mark}) {
		&amp;cmd_time_stop($mark);			# autoclosing timepoint
	}
	my $timestr = sprintf "%8d sec", $time_stop{$mark} - $time_start{$mark};
	chomp $msg;			# drop end of line if any
	$msg =~ s/&lt;time&gt;/$timestr/;
	print STDERR $msg."\n";
	
	return &amp;cmd_time_close($mark);
}

sub prof_warn($) {
	my ($msg) = @_;
	my (@pkg, $file, $line) = @caller;
	print STDERR "PROFILE WARNING at package $pkg, file $file, line $line: $msg\n";
	return 1;
}

1;
</pre></body></html>