8 if (scalar (@ARGV) < 1)
10 print STDERR
"lwes-calculate-max-size <esf_files>\n";
16 my $current_event = undef;
22 open (FH
, "< $ARGV[0]");
27 # kill leading and trailing white-space
32 next if $line =~ m/^#/;
41 $current_event = undef;
45 if ($line =~ /^(\w+)\s+(\w+);\s+#\s+(\w+)\s+(\w+),\s+(\w+)(,\s+(\w+))?/)
47 my ($type, $sname, $lname, $contract, $source, $max_length)
48 = ($1, $2, $3, $4, $5, $7);
49 if ($contract ne "OPTIONAL"
50 && $contract ne "REQUIRED")
52 print STDERR
"ERROR: line $lines\n";
53 print STDERR
"ERROR: '$contract' should be one of\n";
54 print STDERR
"\tOPTIONAL\n";
55 print STDERR
"\tREQUIRED\n";
58 foreach my $src (split /\|/, $source)
60 if ( $src ne "COMMAND_ARGS"
61 && $src ne "FUNCTION_ARGS"
62 && $src ne "CALCULATED"
67 print STDERR
"ERROR: line $lines\n";
68 print STDERR
"ERROR: '$src' should be one or"
70 print STDERR
"\tCOMMAND_ARGS\n";
71 print STDERR
"\tFUNCTION_ARGS\n";
72 print STDERR
"\tCALCULATED\n";
73 print STDERR
"\tHTTP_REQ\n";
74 print STDERR
"\tXARGS\n";
78 if (defined ($current_event))
80 $events->{$current_event}->{$sname} =
84 'contract' => $contract,
87 if (defined ($max_length))
89 $events->{$current_event}->{$sname}->{'max_length'} =
104 unless (exists ($events->{$line}))
106 $current_event = $line;
107 $events->{$current_event} = { };
111 print STDERR
"ERROR: line $lines\n";
112 print STDERR
"ERROR: $line event exists twice in file!\n";
120 # calculate the sizes
122 # calculate meta size
123 my $meta_attributes_size = 0;
124 foreach my $attr (keys %{$events->{'MetaEventInfo'}})
126 # ignore fields set by the listener or journaller
127 next if $attr eq "SenderIP";
128 next if $attr eq "SenderPort";
129 next if $attr eq "ReceiptTime";
130 next if $attr eq "SiteID";
131 $meta_attributes_size +=
132 calculateEventEntrySize
133 ($events->{'MetaEventInfo'}->{$attr}->{'type'},
135 $events->{'MetaEventInfo'}->{$attr}->{'max_length'});
138 foreach my $event (keys %{$events})
140 next if $event eq "MetaEventInfo";
141 my $event_max_size = $meta_attributes_size;
142 $event_max_size += calculateEventHeaderSize
($event);
143 foreach my $attr (keys %{$events->{$event}})
146 calculateEventEntrySize
147 ($events->{$event}->{$attr}->{'type'},
149 $events->{$event}->{$attr}->{'max_length'});
151 print "$event\t$event_max_size\n";
154 sub calculateEventHeaderSize
156 my ($eventname) = @_;
159 # one byte for event name length
162 # length bytes for event name
163 $size += length $eventname;
165 # two bytes for number of attributes
171 sub calculateEventEntrySize
173 my ($type, $attr, $max_size) = @_;
177 # add one byte for attribute name length
180 # add length bytes for attribute name
181 $size += length $attr;
183 # add one byte for attribute type id
186 # now add bytes for data types
187 if ($type eq "boolean")
191 elsif ($type eq "uint16")
195 elsif ($type eq "int16")
199 elsif ($type eq "uint32")
203 elsif ($type eq "int32")
207 elsif ($type eq "uint64")
211 elsif ($type eq "int64")
215 elsif ($type eq "ip_addr")
219 elsif ($type eq "string")
221 # two bytes of length
224 # add max size bytes of length
225 unless (defined ($max_size))
227 print STDERR
"ERROR: must specify a max size for string types\n";
230 if ($max_size > 65535)
232 print STDERR
"ERROR: max size must be less than 65535\n";
239 print STDERR
"ERROR: unknown type [$type]\n";