160
|
1 |
#!/usr/local/bin/perl
|
|
2 |
#
|
|
3 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
# All rights reserved.
|
|
5 |
# This component and the accompanying materials are made available
|
|
6 |
# under the terms of "Eclipse Public License v1.0"
|
|
7 |
# which accompanies this distribution, and is available
|
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
#
|
|
10 |
# Initial Contributors:
|
|
11 |
# Nokia Corporation - initial contribution.
|
|
12 |
#
|
|
13 |
# Contributors:
|
|
14 |
#
|
|
15 |
# Description:
|
|
16 |
# This script parses trace data produced by OST from FBS, using the the FBSCLI,
|
|
17 |
# FBSERV and Symbian BTrace Hooks OST dictionaries, to produce a CSV output of
|
|
18 |
# the amount of bitmap memory used per-thread over a user-definable time
|
|
19 |
# granularity, since the start of the trace.
|
|
20 |
#
|
|
21 |
# To use, enable SYMBIAN_KERNEL_THREAD_IDENTIFICATION trace group in Symbian
|
|
22 |
# BTrace Hooks OST dictionary, GRAPHICS_RESOURCE_MANAGEMENT_SEMANTICS in FBSERV
|
|
23 |
# OST dictionary, and GRAPHICS_RESOURCE_MANAGEMENT_SEMANTICS,
|
|
24 |
# GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS and GRAPHICS_CONTROL_FUNCTIONS in
|
|
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
|
|
27 |
# a spreadsheet application to be visually processed.
|
|
28 |
#
|
|
29 |
|
|
30 |
use strict;
|
|
31 |
|
|
32 |
# Sanity checking of the command line parameters...
|
|
33 |
if ($#ARGV == -1 || $ARGV[0] eq "help" || $ARGV[0] eq "/?")
|
|
34 |
{
|
|
35 |
print "\nusage: $0 filename [-h]\n";
|
|
36 |
print "where\n";
|
|
37 |
print " -h : Specifies the heartbeat in millisecs (default=10000)\n";
|
|
38 |
exit;
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
## Modifiable constants...
|
|
43 |
my $CSV_DELIMITER = ',';
|
|
44 |
|
|
45 |
# Time after start to take first snapshot, in millisecs
|
|
46 |
my $firstHeartBeatTimeMS = 1000;
|
|
47 |
|
|
48 |
# Default heartbeat in millisecs if none specified.
|
|
49 |
my $heartBeatMS = 10000;
|
|
50 |
|
|
51 |
|
|
52 |
##
|
|
53 |
## Internal structures...
|
|
54 |
##
|
|
55 |
my $heartBeatCount = 0;
|
|
56 |
my $nextHeartBeatMS = -1;
|
178
|
57 |
my $logLastLineTimeMS = 0;
|
160
|
58 |
|
|
59 |
# A hash of thread names to the amount of bitmap memory they
|
|
60 |
# have used since the start of the trace.
|
|
61 |
my %bmpMemoryPerThread = ();
|
|
62 |
|
|
63 |
# A hash of bitmaps fully qualified by the session they belong to,
|
|
64 |
# and their local handle (because bitmaps can have the same local
|
|
65 |
# handle in different threads), mapped to their size in bytes.
|
|
66 |
my %bmpMemoryByServerHandle = ();
|
|
67 |
|
|
68 |
# Hash of FbsSessions to thread IDs.
|
|
69 |
my %SessionThreadMap = ();
|
|
70 |
|
|
71 |
# Array of the above hashes, one hash per heartbeat.
|
|
72 |
my @arrayOfSnapshots;
|
|
73 |
|
|
74 |
# Hashes of thread and process names to IDs.
|
|
75 |
my %ThreadNames;
|
|
76 |
my %ProcessNames;
|
|
77 |
|
|
78 |
|
|
79 |
##
|
|
80 |
## Command line options parsing...
|
|
81 |
## First arg is assumed to be the filename.
|
|
82 |
##
|
|
83 |
for my $i (1..$#ARGV)
|
|
84 |
{
|
|
85 |
my $cma = $ARGV[$i];
|
|
86 |
if ($cma =~ m/-h(\d*)/)
|
|
87 |
{
|
|
88 |
$heartBeatMS = $1;
|
|
89 |
}
|
|
90 |
else
|
|
91 |
{
|
|
92 |
print "Unrecognised parameter: $cma , ignoring...\n";
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
## Read from the file.
|
|
97 |
## Read the log into an array line by line.
|
|
98 |
my $TRACE_FILENAME = $ARGV[0];
|
178
|
99 |
open(INPUT_FILE, '<', $TRACE_FILENAME) or die $!;
|
|
100 |
binmode(INPUT_FILE);
|
160
|
101 |
|
|
102 |
##
|
|
103 |
## Parse each line sequentially...
|
|
104 |
##
|
178
|
105 |
while ( my $line = <INPUT_FILE> )
|
160
|
106 |
{
|
|
107 |
my $timeFromMidnightMS;
|
|
108 |
|
|
109 |
##
|
|
110 |
## If this line is about a new process, make a note of the name and the
|
|
111 |
## associated process id, so that FbsSessions can be mapped to their
|
|
112 |
## thread by name.
|
|
113 |
##
|
|
114 |
if ($line =~ /^.*Thread:Process name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$/i)
|
|
115 |
{
|
|
116 |
my $threadId = $1;
|
|
117 |
my $processId = $2;
|
|
118 |
my $processName = $3;
|
|
119 |
$ProcessNames{$processId} = $processName ;
|
|
120 |
}
|
|
121 |
|
|
122 |
##
|
|
123 |
## If this line is about a new process, make a note of the name and the
|
|
124 |
## associated process id, so that FbsSessions can be mapped to their
|
|
125 |
## thread by name when the csv is generated.
|
|
126 |
##
|
|
127 |
if (($line =~ /^.*Thread:Thread created;NThread:(.*);DProcess:(.*);Name:(.*)$/i) ||
|
|
128 |
($line =~ /^.*Thread:Thread name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$/i))
|
|
129 |
{
|
|
130 |
my $threadId = $1;
|
|
131 |
my $processId = $2;
|
|
132 |
my $threadName = $3;
|
|
133 |
my $fullThreadName = $ProcessNames{$processId} . ":" . $threadName;
|
|
134 |
$ThreadNames{$threadId} = $fullThreadName;
|
|
135 |
}
|
|
136 |
|
|
137 |
##
|
|
138 |
## Determine timestamp. If this time is beyond the heartbeat,
|
|
139 |
## take a snapshot and
|
|
140 |
##
|
|
141 |
if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/)
|
|
142 |
{
|
|
143 |
$timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4;
|
|
144 |
if ($nextHeartBeatMS == -1)
|
|
145 |
{
|
178
|
146 |
$nextHeartBeatMS = $firstHeartBeatTimeMS;
|
|
147 |
$logLastLineTimeMS = $timeFromMidnightMS;
|
160
|
148 |
}
|
178
|
149 |
## We have wrapped around midnight!
|
|
150 |
## Add a 1000ms cushion to the comparison to avoid wrapping around
|
|
151 |
## midnight if a trace is buffered too slowly.
|
|
152 |
if (($timeFromMidnightMS+1000) < $logLastLineTimeMS)
|
|
153 |
{
|
|
154 |
$timeFromMidnightMS += 86400000;
|
|
155 |
}
|
|
156 |
$nextHeartBeatMS -= ($timeFromMidnightMS - $logLastLineTimeMS);
|
|
157 |
$logLastLineTimeMS = $timeFromMidnightMS;
|
160
|
158 |
|
178
|
159 |
##
|
|
160 |
## If heartbeat reached, take snapshot of bmp memory per thread
|
|
161 |
## and set next heartbeat time.
|
|
162 |
##
|
|
163 |
while ($nextHeartBeatMS <= 0)
|
160
|
164 |
{
|
178
|
165 |
$nextHeartBeatMS += $heartBeatMS;
|
|
166 |
# take a snapshot of the current bitmap memory usage per thread
|
|
167 |
while ((my $thread, my $bmpMemory) = each(%bmpMemoryPerThread))
|
|
168 |
{
|
|
169 |
$arrayOfSnapshots[$heartBeatCount]{$thread} = $bmpMemory;
|
|
170 |
}
|
|
171 |
$heartBeatCount++;
|
160
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
## FBS Client-side traces.
|
|
176 |
if ($line =~ m/\tFBSCLI: /)
|
|
177 |
{
|
|
178 |
##
|
|
179 |
## If this line is an FBSCLI trace, and it contains iSSH then
|
|
180 |
## it gives a chance to map a client thread ID to a session handle.
|
|
181 |
##
|
|
182 |
if ( $line =~ m/iSSH=(\w*);.*Thread ID:(.*)$/)
|
|
183 |
{
|
|
184 |
my $ServerSessionHandle = $1;
|
|
185 |
my $thread = $2;
|
|
186 |
if ($thread ne "0x00000000")
|
|
187 |
{
|
|
188 |
$SessionThreadMap{$ServerSessionHandle} = $thread;
|
|
189 |
}
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
##
|
|
194 |
## FBS Server-side traces.
|
|
195 |
##
|
|
196 |
if ($line =~ m/\tFBSERV: /)
|
|
197 |
{
|
|
198 |
## The line must have a s= parameter to be useful - the session server handle.
|
|
199 |
## Any FBSERV line without this is not considered for parsing.
|
|
200 |
if ($line =~ m/; iSSH=(\w*);/)
|
|
201 |
{
|
|
202 |
my $FbsSessionHandle = $1;
|
|
203 |
my $thread = "Unknown Thread [Session=$FbsSessionHandle]";
|
|
204 |
if (defined($SessionThreadMap{$FbsSessionHandle}))
|
|
205 |
{
|
|
206 |
$thread = $SessionThreadMap{$FbsSessionHandle};
|
|
207 |
}
|
|
208 |
if ($line =~ m/# Server resource destroyed; .*iH=(\w*);/)
|
|
209 |
{
|
|
210 |
my $bmpHandle = $1;
|
|
211 |
my $bmpIdentifier = "$FbsSessionHandle:$bmpHandle";
|
|
212 |
if (defined($bmpMemoryByServerHandle{$bmpIdentifier}))
|
|
213 |
{
|
|
214 |
$bmpMemoryPerThread{$thread} -= $bmpMemoryByServerHandle{$bmpIdentifier};
|
|
215 |
delete $bmpMemoryByServerHandle{$bmpIdentifier};
|
|
216 |
}
|
|
217 |
}
|
|
218 |
if ($line =~ m/# Server bitmap resized; .*iOldH=(\w*); iNewH=(\w*); newbytes=(\d*);/)
|
|
219 |
{
|
|
220 |
# When a bitmap is resized, the amount of memory held by the bitmap may change
|
|
221 |
# and the bitmap localhandle will change.
|
|
222 |
my $oldBmpHandle = $1;
|
|
223 |
my $newBmpHandle = $2;
|
|
224 |
my $newBmpBytes = $3;
|
|
225 |
my $oldBmpIdentifier = "$FbsSessionHandle:$oldBmpHandle";
|
|
226 |
my $newBmpIdentifier = "$FbsSessionHandle:$newBmpHandle";
|
|
227 |
if (defined($bmpMemoryByServerHandle{$oldBmpIdentifier}))
|
|
228 |
{
|
|
229 |
$bmpMemoryPerThread{$thread} -= $bmpMemoryByServerHandle{$oldBmpIdentifier};
|
|
230 |
delete $bmpMemoryByServerHandle{$oldBmpIdentifier};
|
|
231 |
}
|
|
232 |
$bmpMemoryPerThread{$thread} += $newBmpBytes;
|
|
233 |
$bmpMemoryByServerHandle{$newBmpIdentifier} = $newBmpBytes;
|
|
234 |
}
|
|
235 |
elsif ($line =~ m/#.*iOldH=(\w*); iNewH=(\w*);/)
|
|
236 |
{
|
|
237 |
# When a bitmap is compressed, cleaned or resized, the bitmap local handle changes
|
|
238 |
my $oldBmpHandle = $1;
|
|
239 |
my $newBmpHandle = $2;
|
|
240 |
my $oldBmpIdentifier = "$FbsSessionHandle:$oldBmpHandle";
|
|
241 |
my $newBmpIdentifier = "$FbsSessionHandle:$newBmpHandle";
|
|
242 |
if (defined($bmpMemoryByServerHandle{$oldBmpIdentifier}))
|
|
243 |
{
|
|
244 |
my $bytes = $bmpMemoryByServerHandle{$oldBmpIdentifier};
|
|
245 |
delete $bmpMemoryByServerHandle{$oldBmpIdentifier};
|
|
246 |
$bmpMemoryByServerHandle{$newBmpIdentifier} = $bytes;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
elsif ($line =~ m/#.*iH=(\w*);.*bytes=(\d+);/)
|
|
250 |
{
|
|
251 |
# Duplication of a bitmap typically. When a bitmap is duplicated,
|
|
252 |
# the memory is 'owned' by all threads that duplicate it.
|
|
253 |
my $bmpHandle = $1;
|
|
254 |
my $bmpBytes = $2;
|
|
255 |
my $bmpIdentifier = "$FbsSessionHandle:$bmpHandle";
|
|
256 |
$bmpMemoryPerThread{$thread} += $bmpBytes;
|
|
257 |
$bmpMemoryByServerHandle{$bmpIdentifier} = $bmpBytes;
|
|
258 |
}
|
|
259 |
}
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|
|
263 |
close (INPUT_FILE);
|
|
264 |
|
|
265 |
|
|
266 |
##
|
|
267 |
## Make a map of unique threads across all snapshots
|
|
268 |
## This is so only one occurrence of each thread will appear
|
|
269 |
## in the csv file.
|
|
270 |
##
|
|
271 |
my %uniqueThreads = ();
|
|
272 |
for my $i (0..$#arrayOfSnapshots)
|
|
273 |
{
|
|
274 |
for my $thread (keys %{$arrayOfSnapshots[$i]})
|
|
275 |
{
|
|
276 |
$uniqueThreads{$thread} = 1;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
##
|
|
281 |
## Start writing to file.
|
|
282 |
## First row, which contains the heartbeat number column headings...
|
|
283 |
##
|
|
284 |
my $OUTPUT_FILENAME = sprintf("%s.csv", $TRACE_FILENAME);
|
|
285 |
open(OUTPUT_FILE,">$OUTPUT_FILENAME") or die $!;
|
|
286 |
print OUTPUT_FILE "Session$CSV_DELIMITER";
|
|
287 |
for my $i (0..$heartBeatCount)
|
|
288 |
{
|
|
289 |
print OUTPUT_FILE "$i$CSV_DELIMITER";
|
|
290 |
}
|
|
291 |
|
|
292 |
##
|
|
293 |
## For each subsequent row, print the first thread and the
|
|
294 |
## memory at each snapshot...
|
|
295 |
##
|
|
296 |
print OUTPUT_FILE "\n";
|
|
297 |
while ((my $thread, my $dummy) = each(%uniqueThreads))
|
|
298 |
{
|
|
299 |
# Resolve the thread to its full name...
|
|
300 |
print OUTPUT_FILE "$thread";
|
|
301 |
if (defined($ThreadNames{$thread}) )
|
|
302 |
{
|
|
303 |
my $threadName = $ThreadNames{$thread};
|
|
304 |
print OUTPUT_FILE ":$threadName";
|
|
305 |
}
|
|
306 |
print OUTPUT_FILE "$CSV_DELIMITER";
|
|
307 |
|
|
308 |
# print the memory use per thread, for each snapshot...
|
|
309 |
for my $i (0..$#arrayOfSnapshots)
|
|
310 |
{
|
|
311 |
my %snapshot = %{$arrayOfSnapshots[$i]};
|
|
312 |
while ((my $snapshotThread, my $bmpMemory) = each(%snapshot))
|
|
313 |
{
|
|
314 |
if ($snapshotThread eq $thread)
|
|
315 |
{
|
|
316 |
print OUTPUT_FILE "$bmpMemory";
|
|
317 |
}
|
|
318 |
}
|
|
319 |
print OUTPUT_FILE "$CSV_DELIMITER";
|
|
320 |
}
|
|
321 |
print OUTPUT_FILE "\n";
|
|
322 |
}
|
|
323 |
close (OUTPUT_FILE);
|
|
324 |
|