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 FBS resources 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 |
# Hash of FbsSessions to thread IDs.
|
|
60 |
my %SessionThreadMap = ();
|
|
61 |
|
|
62 |
# A hash of thread names to the fbs resource count.
|
|
63 |
my %fbsResourcesPerThread = ();
|
|
64 |
|
|
65 |
# Array of the above hashes, one hash per heartbeat.
|
|
66 |
my @arrayOfSnapshots;
|
|
67 |
|
|
68 |
# Hashes of thread and process names to IDs.
|
|
69 |
my %ThreadNames;
|
|
70 |
my %ProcessNames;
|
|
71 |
|
|
72 |
|
|
73 |
##
|
|
74 |
## Command line options parsing...
|
|
75 |
## First arg is assumed to be the filename.
|
|
76 |
##
|
|
77 |
for my $i (1..$#ARGV)
|
|
78 |
{
|
|
79 |
my $cma = $ARGV[$i];
|
|
80 |
if ($cma =~ m/-h(\d*)/)
|
|
81 |
{
|
|
82 |
$heartBeatMS = $1;
|
|
83 |
}
|
|
84 |
else
|
|
85 |
{
|
|
86 |
print "Unrecognised parameter: $cma , ignoring...\n";
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
## Read from the file.
|
|
91 |
## Read the log into an array line by line.
|
|
92 |
my $TRACE_FILENAME = $ARGV[0];
|
178
|
93 |
open(INPUT_FILE, '<', $TRACE_FILENAME) or die $!;
|
|
94 |
binmode(INPUT_FILE);
|
160
|
95 |
|
|
96 |
##
|
|
97 |
## Parse each line sequentially...
|
|
98 |
##
|
178
|
99 |
while ( my $line = <INPUT_FILE> )
|
160
|
100 |
{
|
|
101 |
my $timeFromMidnightMS;
|
|
102 |
|
|
103 |
##
|
|
104 |
## If this line is about a new process, make a note of the name and the
|
|
105 |
## associated process id, so that FbsSessions can be mapped to their
|
|
106 |
## thread by name.
|
|
107 |
##
|
|
108 |
if ($line =~ /^.*Thread:Process name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$/i)
|
|
109 |
{
|
|
110 |
my $threadId = $1;
|
|
111 |
my $processId = $2;
|
|
112 |
my $processName = $3;
|
|
113 |
$ProcessNames{$processId} = $processName ;
|
|
114 |
}
|
|
115 |
|
|
116 |
##
|
|
117 |
## If this line is about a new process, make a note of the name and the
|
|
118 |
## associated process id, so that FbsSessions can be mapped to their
|
|
119 |
## thread by name when the csv is generated.
|
|
120 |
##
|
|
121 |
if (($line =~ /^.*Thread:Thread created;NThread:(.*);DProcess:(.*);Name:(.*)$/i) ||
|
|
122 |
($line =~ /^.*Thread:Thread name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$/i))
|
|
123 |
{
|
|
124 |
my $threadId = $1;
|
|
125 |
my $processId = $2;
|
|
126 |
my $threadName = $3;
|
|
127 |
my $fullThreadName = $ProcessNames{$processId} . ":" . $threadName;
|
|
128 |
$ThreadNames{$threadId} = $fullThreadName;
|
|
129 |
}
|
|
130 |
|
|
131 |
##
|
|
132 |
## Determine timestamp. If this time is beyond the heartbeat,
|
|
133 |
## take a snapshot and
|
|
134 |
##
|
|
135 |
if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/)
|
|
136 |
{
|
|
137 |
$timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4;
|
|
138 |
if ($nextHeartBeatMS == -1)
|
|
139 |
{
|
178
|
140 |
$nextHeartBeatMS = $firstHeartBeatTimeMS;
|
|
141 |
$logLastLineTimeMS = $timeFromMidnightMS;
|
160
|
142 |
}
|
178
|
143 |
## We have wrapped around midnight!
|
|
144 |
## Add a 1000ms cushion to the comparison to avoid wrapping around
|
|
145 |
## midnight if a trace is buffered too slowly.
|
|
146 |
if (($timeFromMidnightMS+1000) < $logLastLineTimeMS)
|
|
147 |
{
|
|
148 |
$timeFromMidnightMS += 86400000;
|
|
149 |
}
|
|
150 |
$nextHeartBeatMS -= ($timeFromMidnightMS - $logLastLineTimeMS);
|
|
151 |
$logLastLineTimeMS = $timeFromMidnightMS;
|
160
|
152 |
|
178
|
153 |
##
|
|
154 |
## If heartbeat reached, take snapshot of bmp memory per thread
|
|
155 |
## and set next heartbeat time.
|
|
156 |
##
|
|
157 |
while ($nextHeartBeatMS <= 0)
|
160
|
158 |
{
|
178
|
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++;
|
160
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
## FBS Client-side traces.
|
|
170 |
if ($line =~ m/\tFBSCLI: /)
|
|
171 |
{
|
|
172 |
##
|
|
173 |
## If this line is an FBSCLI trace, and it contains iSSH then
|
|
174 |
## it gives a chance to map a client thread ID to a session handle.
|
|
175 |
##
|
|
176 |
if ( $line =~ m/iSSH=(\w*);.*Thread ID:(.*)$/)
|
|
177 |
{
|
|
178 |
my $ServerSessionHandle = $1;
|
|
179 |
my $thread = $2;
|
|
180 |
if ($thread ne "0x00000000")
|
|
181 |
{
|
|
182 |
$SessionThreadMap{$ServerSessionHandle} = $thread;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
##
|
|
188 |
## FBS Server-side traces.
|
|
189 |
##
|
|
190 |
if ($line =~ m/\tFBSERV: /)
|
|
191 |
{
|
|
192 |
## The line must have a s= parameter to be useful - the session server handle.
|
|
193 |
## Any FBSERV line without this is not considered for parsing.
|
|
194 |
if ($line =~ m/; iSSH=(\w*);/)
|
|
195 |
{
|
|
196 |
my $FbsSessionHandle = $1;
|
|
197 |
my $thread = "Unknown Thread [Session=$FbsSessionHandle]";
|
|
198 |
if (defined($SessionThreadMap{$FbsSessionHandle}))
|
|
199 |
{
|
|
200 |
$thread = $SessionThreadMap{$FbsSessionHandle};
|
|
201 |
}
|
|
202 |
if ($line =~ m/; rc=(\d+);/)
|
|
203 |
{
|
|
204 |
my $resourceCount = $1;
|
|
205 |
if ($resourceCount == 0)
|
|
206 |
{
|
|
207 |
$resourceCount = '';
|
|
208 |
}
|
|
209 |
$fbsResourcesPerThread{$thread} = $resourceCount;
|
|
210 |
}
|
|
211 |
}
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
close (INPUT_FILE);
|
|
216 |
|
|
217 |
|
|
218 |
##
|
|
219 |
## Make a map of unique threads across all snapshots
|
|
220 |
## This is so only one occurrence of each thread will appear
|
|
221 |
## in the csv file.
|
|
222 |
##
|
|
223 |
my %uniqueThreads = ();
|
|
224 |
for my $i (0..$#arrayOfSnapshots)
|
|
225 |
{
|
|
226 |
for my $thread (keys %{$arrayOfSnapshots[$i]})
|
|
227 |
{
|
|
228 |
$uniqueThreads{$thread} = 1;
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
##
|
|
233 |
## Start writing to file.
|
|
234 |
## First row, which contains the heartbeat number column headings...
|
|
235 |
##
|
|
236 |
my $OUTPUT_FILENAME = sprintf("%s.csv", $TRACE_FILENAME);
|
|
237 |
open(OUTPUT_FILE,">$OUTPUT_FILENAME") or die $!;
|
|
238 |
print OUTPUT_FILE "Session$CSV_DELIMITER";
|
|
239 |
for my $i (0..$heartBeatCount)
|
|
240 |
{
|
|
241 |
print OUTPUT_FILE "$i$CSV_DELIMITER";
|
|
242 |
}
|
|
243 |
|
|
244 |
##
|
|
245 |
## For each subsequent row, print the first thread and the
|
|
246 |
## memory at each snapshot...
|
|
247 |
##
|
|
248 |
print OUTPUT_FILE "\n";
|
|
249 |
while ((my $thread, my $dummy) = each(%uniqueThreads))
|
|
250 |
{
|
|
251 |
# Resolve the thread to its full name...
|
|
252 |
print OUTPUT_FILE "$thread";
|
|
253 |
if (defined($ThreadNames{$thread}) )
|
|
254 |
{
|
|
255 |
my $threadName = $ThreadNames{$thread};
|
|
256 |
print OUTPUT_FILE ":$threadName";
|
|
257 |
}
|
|
258 |
print OUTPUT_FILE "$CSV_DELIMITER";
|
|
259 |
|
|
260 |
# print the memory use per thread, for each snapshot...
|
|
261 |
for my $i (0..$#arrayOfSnapshots)
|
|
262 |
{
|
|
263 |
my %snapshot = %{$arrayOfSnapshots[$i]};
|
|
264 |
while ((my $snapshotThread, my $fbsResourceCount) = each(%snapshot))
|
|
265 |
{
|
|
266 |
if ($snapshotThread eq $thread)
|
|
267 |
{
|
|
268 |
print OUTPUT_FILE "$fbsResourceCount";
|
|
269 |
}
|
|
270 |
}
|
|
271 |
print OUTPUT_FILE "$CSV_DELIMITER";
|
|
272 |
}
|
|
273 |
print OUTPUT_FILE "\n";
|
|
274 |
}
|
|
275 |
close (OUTPUT_FILE);
|
|
276 |
|