23 # OST dictionary, and GRAPHICS_RESOURCE_MANAGEMENT_SEMANTICS, |
23 # OST dictionary, and GRAPHICS_RESOURCE_MANAGEMENT_SEMANTICS, |
24 # GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS and GRAPHICS_CONTROL_FUNCTIONS in |
24 # GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS and GRAPHICS_CONTROL_FUNCTIONS in |
25 # FBSCLI OST dictionary. Once tracing is gathered, save trace output as ascii |
25 # FBSCLI OST dictionary. Once tracing is gathered, save trace output as ascii |
26 # and run this script against it. The resulting file can then be imported into |
26 # and run this script against it. The resulting file can then be imported into |
27 # a spreadsheet application to be visually processed. |
27 # a spreadsheet application to be visually processed. |
28 # |
|
29 # KNOWN DEFECTS: |
|
30 # Once the log time goes beyond midnight, snapshots will stop being taken. |
|
31 # |
28 # |
32 |
29 |
33 use strict; |
30 use strict; |
34 |
31 |
35 # Sanity checking of the command line parameters... |
32 # Sanity checking of the command line parameters... |
55 ## |
52 ## |
56 ## Internal structures... |
53 ## Internal structures... |
57 ## |
54 ## |
58 my $heartBeatCount = 0; |
55 my $heartBeatCount = 0; |
59 my $nextHeartBeatMS = -1; |
56 my $nextHeartBeatMS = -1; |
|
57 my $logLastLineTimeMS = 0; |
60 |
58 |
61 # Hash of FbsSessions to thread IDs. |
59 # Hash of FbsSessions to thread IDs. |
62 my %SessionThreadMap = (); |
60 my %SessionThreadMap = (); |
63 |
61 |
64 # A hash of thread names to the fbs resource count. |
62 # A hash of thread names to the fbs resource count. |
90 } |
88 } |
91 |
89 |
92 ## Read from the file. |
90 ## Read from the file. |
93 ## Read the log into an array line by line. |
91 ## Read the log into an array line by line. |
94 my $TRACE_FILENAME = $ARGV[0]; |
92 my $TRACE_FILENAME = $ARGV[0]; |
95 open(INPUT_FILE, $TRACE_FILENAME) or die $!; |
93 open(INPUT_FILE, '<', $TRACE_FILENAME) or die $!; |
96 my @traceLines = <INPUT_FILE>; |
94 binmode(INPUT_FILE); |
97 |
|
98 |
95 |
99 ## |
96 ## |
100 ## Parse each line sequentially... |
97 ## Parse each line sequentially... |
101 ## |
98 ## |
102 foreach my $line (@traceLines) |
99 while ( my $line = <INPUT_FILE> ) |
103 { |
100 { |
104 my $timeFromMidnightMS; |
101 my $timeFromMidnightMS; |
105 |
102 |
106 ## |
103 ## |
107 ## If this line is about a new process, make a note of the name and the |
104 ## If this line is about a new process, make a note of the name and the |
136 ## take a snapshot and |
133 ## take a snapshot and |
137 ## |
134 ## |
138 if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/) |
135 if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/) |
139 { |
136 { |
140 $timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4; |
137 $timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4; |
141 # Set up the time for the first snapshot. |
|
142 if ($nextHeartBeatMS == -1) |
138 if ($nextHeartBeatMS == -1) |
143 { |
139 { |
144 $nextHeartBeatMS = $timeFromMidnightMS + $firstHeartBeatTimeMS; |
140 $nextHeartBeatMS = $firstHeartBeatTimeMS; |
145 } |
141 $logLastLineTimeMS = $timeFromMidnightMS; |
146 } |
142 } |
147 |
143 ## We have wrapped around midnight! |
148 ## |
144 ## Add a 1000ms cushion to the comparison to avoid wrapping around |
149 ## If heartbeat reached, take snapshot of bmp memory per thread |
145 ## midnight if a trace is buffered too slowly. |
150 ## and set next heartbeat time. |
146 if (($timeFromMidnightMS+1000) < $logLastLineTimeMS) |
151 ## |
147 { |
152 while ($timeFromMidnightMS >= $nextHeartBeatMS) |
148 $timeFromMidnightMS += 86400000; |
153 { |
149 } |
154 $nextHeartBeatMS += $heartBeatMS; |
150 $nextHeartBeatMS -= ($timeFromMidnightMS - $logLastLineTimeMS); |
155 # take a snapshot of the current bitmap memory usage per thread |
151 $logLastLineTimeMS = $timeFromMidnightMS; |
156 while ((my $thread, my $fbsResourceCount) = each(%fbsResourcesPerThread)) |
152 |
157 { |
153 ## |
158 $arrayOfSnapshots[$heartBeatCount]{$thread} = $fbsResourceCount; |
154 ## If heartbeat reached, take snapshot of bmp memory per thread |
159 } |
155 ## and set next heartbeat time. |
160 $heartBeatCount++; |
156 ## |
|
157 while ($nextHeartBeatMS <= 0) |
|
158 { |
|
159 $nextHeartBeatMS += $heartBeatMS; |
|
160 # take a snapshot of the current bitmap memory usage per thread |
|
161 while ((my $thread, my $fbsResourceCount) = each(%fbsResourcesPerThread)) |
|
162 { |
|
163 $arrayOfSnapshots[$heartBeatCount]{$thread} = $fbsResourceCount; |
|
164 } |
|
165 $heartBeatCount++; |
|
166 } |
161 } |
167 } |
162 |
168 |
163 ## FBS Client-side traces. |
169 ## FBS Client-side traces. |
164 if ($line =~ m/\tFBSCLI: /) |
170 if ($line =~ m/\tFBSCLI: /) |
165 { |
171 { |