Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: Analyzer.pm | |
4 | # Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | # 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | # | |
7 | # * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | # | |
9 | # This program is free software; you can redistribute it and/or modify | |
10 | # it under the terms of the GNU General Public License as published by | |
11 | # the Free Software Foundation; version 2 of the License. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | # | |
22 | # For the avoidance of doubt, and except that if any non-GPL license | |
23 | # choice is available it will apply instead, Sun elects to use only | |
24 | # the General Public License version 2 (GPLv2) at this time for any | |
25 | # software where a choice of GPL license versions is made | |
26 | # available with the language indicating that GPLv2 or any later version | |
27 | # may be used, or where a choice of which version of the GPL is applied is | |
28 | # otherwise unspecified. | |
29 | # | |
30 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | # CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | # have any questions. | |
33 | # | |
34 | # ========== Copyright Header End ============================================ | |
35 | package AnalyzeDiag::Analyzer; | |
36 | ||
37 | use strict; | |
38 | use warnings; | |
39 | ||
40 | use AnalyzeDiag::Output; | |
41 | use AnalyzeDiag::Logfile; | |
42 | use AnalyzeDiag::SymbolTable; | |
43 | use AnalyzeDiag::Measurement; | |
44 | ||
45 | ||
46 | use fields qw( | |
47 | dir | |
48 | logfile symtab | |
49 | measurements | |
50 | parsed_measurements | |
51 | ); | |
52 | ||
53 | our $Hex_Regex = qr/[\da-f]+/; | |
54 | ||
55 | ############################################################################### | |
56 | ||
57 | sub new { | |
58 | my $this = shift; | |
59 | my %args = @_; | |
60 | ||
61 | unless (ref $this) { | |
62 | $this = fields::new($this); | |
63 | } | |
64 | ||
65 | $this->{measurements} = []; | |
66 | ||
67 | foreach my $key (keys %args) { | |
68 | $this->{$key} = $args{$key}; | |
69 | } | |
70 | ||
71 | $this->open_files() if defined $this->{dir}; | |
72 | ||
73 | return $this; | |
74 | } | |
75 | ||
76 | ############################################################################### | |
77 | ||
78 | sub open_files { | |
79 | my $this = shift; | |
80 | script_die "No directory defined!\n" unless defined $this->{dir}; | |
81 | ||
82 | $this->{logfile} = AnalyzeDiag::Logfile->create_from_dir($this->{dir}); | |
83 | $this->{symtab} = AnalyzeDiag::SymbolTable->create_from_dir($this->{dir}); | |
84 | } | |
85 | ||
86 | ############################################################################### | |
87 | ||
88 | sub logfile { | |
89 | my $this = shift; | |
90 | return $this->{logfile}; | |
91 | } | |
92 | ||
93 | ############################################################################### | |
94 | ||
95 | sub add_measurements { | |
96 | my $this = shift; | |
97 | my @measurements = @_; | |
98 | ||
99 | push @{$this->{measurements}}, @measurements; | |
100 | } | |
101 | ||
102 | ############################################################################### | |
103 | ||
104 | sub parse_measurements { | |
105 | my $this = shift; | |
106 | ||
107 | my %labels; | |
108 | foreach my $m (@{$this->{measurements}}) { | |
109 | if($m->start() !~ /^ $Hex_Regex $/ox) { | |
110 | $labels{$m->start()} = 0; | |
111 | } | |
112 | if($m->end() !~ /^ $Hex_Regex $/ox) { | |
113 | $labels{$m->end()} = 0; | |
114 | } | |
115 | } | |
116 | ||
117 | my $label_hash = $this->{symtab}->get_vas_for_labels( [ keys %labels] ); | |
118 | ||
119 | foreach my $label (keys %$label_hash) { | |
120 | my @vas = @{ $label_hash->{$label} }; | |
121 | chat "Label $label: @vas\n"; | |
122 | } | |
123 | ||
124 | $this->{parsed_measurements} = {}; | |
125 | ||
126 | foreach my $m (@{$this->{measurements}}) { | |
127 | my $parsed = {}; | |
128 | $this->{parsed_measurements}{$m->{name}} = $parsed; | |
129 | ||
130 | my $start = $m->start(); | |
131 | my $end = $m->end(); | |
132 | my $name = $m->name(); | |
133 | ||
134 | if($start =~ /^ $Hex_Regex $/ox) { | |
135 | $parsed->{start} = [ $start ]; | |
136 | } elsif(exists $label_hash->{$start}) { | |
137 | $parsed->{start} = $label_hash->{$start}; | |
138 | } else { | |
139 | script_die "Cannot find VA for label '$start' in '$name'\n"; | |
140 | } | |
141 | ||
142 | if($end =~ /^ $Hex_Regex $/ox) { | |
143 | $parsed->{end} = [ $end ]; | |
144 | } elsif(exists $label_hash->{$end}) { | |
145 | $parsed->{end} = $label_hash->{$end}; | |
146 | } else { | |
147 | script_die "Cannot find VA for label '$end' in '$name'\n"; | |
148 | } | |
149 | ||
150 | $parsed->{name} = $name; | |
151 | foreach (@{$parsed->{start}}) { | |
152 | s/^0+//; | |
153 | } | |
154 | foreach (@{$parsed->{end}}) { | |
155 | s/^0+//; | |
156 | } | |
157 | ||
158 | } | |
159 | ||
160 | # foreach my $pm (keys %{$this->{parsed_measurements}}) { | |
161 | # my $obj = $this->{parsed_measurements}{$pm}; | |
162 | # my @start = @{ $obj->{start} }; | |
163 | # my @end = @{ $obj->{end} }; | |
164 | # debug "Name=$obj->{name}, start=@start, end=@end\n"; | |
165 | # } | |
166 | ||
167 | ||
168 | } | |
169 | ||
170 | ############################################################################### | |
171 | ||
172 | sub analyze { | |
173 | my $this = shift; | |
174 | ||
175 | $this->parse_measurements(); | |
176 | ||
177 | my %results; | |
178 | ||
179 | my %pclist; # hash instead of array to remove duplicates | |
180 | foreach my $pm (keys %{$this->{parsed_measurements}}) { | |
181 | my $obj = $this->{parsed_measurements}{$pm}; | |
182 | my @list = ( @{ $obj->{start} }, @{ $obj->{end} } ); | |
183 | foreach my $elem (@list) { | |
184 | $pclist{$elem} = 1; | |
185 | } | |
186 | } | |
187 | my @pclist = keys %pclist; | |
188 | debug "pclist is @pclist\n"; | |
189 | ||
190 | my $log = $this->{logfile}; | |
191 | my $pchash = $log->get_times_for_pcs(\@pclist); | |
192 | ||
193 | foreach my $pm (keys %{$this->{parsed_measurements}}) { | |
194 | my $obj = $this->{parsed_measurements}{$pm}; | |
195 | my @start_times; | |
196 | foreach my $pc (@{$obj->{start}}) { | |
197 | my $times = $pchash->{$pc}; | |
198 | push @start_times, @$times; | |
199 | } | |
200 | my @end_times; | |
201 | foreach my $pc (@{$obj->{end}}) { | |
202 | my $times = $pchash->{$pc}; | |
203 | push @end_times, @$times; | |
204 | } | |
205 | ||
206 | my @diff = $log->subtract_times(\@end_times, \@start_times); | |
207 | my @diff_cyc = $log->to_cycles(\@diff); | |
208 | ||
209 | debug "NAME=$obj->{name}, start_times=@start_times, end_times=@end_times,". | |
210 | " diff=@diff, diff_cyc=@diff_cyc\n"; | |
211 | ||
212 | $results{$pm} = [ @diff_cyc ]; | |
213 | ||
214 | } | |
215 | ||
216 | return %results; | |
217 | } | |
218 | ||
219 | ############################################################################### | |
220 | 1; |