sbsv1/abld/memtrace/memtrace.pl
author Ross Qin <ross.qin@nokia.com>
Thu, 18 Nov 2010 16:02:32 +0800
changeset 697 818fe0ed324b
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Moving feature configuration out of the buildrom scope.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Postprocess EPOC memory usage trace file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
no strict 'vars';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
use English;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
# Standard Symbian boilerplate to find and load E32env library
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
use FindBin;		# for FindBin::Bin
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
use Getopt::Long;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
BEGIN {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
# check user has a version of perl that will cope
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
	require 5.005_03;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
# establish the path to the Perl libraries: currently the same directory as this script
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
	$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
	$PerlLibPath .= "\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
use lib $PerlLibPath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
use Modload;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
Load_SetModulePath($PerlLibPath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
my $tickperiod = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
my $emulproc = quotemeta("epoc[00000000]0001::");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
my $apprun = quotemeta("apprun[10003a4b]");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
my $ramdrive = quotemeta("TheRamDriveChunk");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
my @chunknames;	# Array of chunk names, indexed by chunkid
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
my @traces;		# Array of chunk traces, each trace being an array
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
				# of (tick,chunkid,size) triples
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
my @chunkgroup;	# Group that a chunk belongs to, indexed by chunkid
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
my @groupnames;	# Array of chunk group names (normally a group==a process)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
my @groups;		# Array of chunk groups, each group being an array of chunkids
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
my %opts;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
my $result = GetOptions (\%opts, "detailed", "help");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
if($result && ($opts{'help'} || $#ARGV<0))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
	&help;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	exit 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
if(!$result || $#ARGV>0)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
	&usage;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
	exit 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
my $file = $ARGV[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
open TRACE,$file or die "Error: Can't open trace file \"$file\".\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
# Parse trace file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
my %current;	# chunkids hashed by DChunk address
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
my $nextchunkid;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
while(<TRACE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	if (/MT:P\s+(\d+)\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
		$tickperiod = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	elsif (/MT:C\s+(\d+)\s+([0-9a-fA-F]+)\s+(.+)\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
		$current{$2} = $nextchunkid++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
		push @chunknames, $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
	elsif (my ($tick, $addr, $size, $name) =
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
		   (/MT:A\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(.+)\s*$/))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
		my $chunkid = $current{$addr};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
		die "Error: Parsing failure - is trace file complete ?"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
			unless (defined $chunkid);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
		push @traces, [0+$tick, $chunkid, hex($size)];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
		# Check whether chunk has been renamed to something more useful
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
		$chunknames[$chunkid] = $name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
			if (($chunknames[$chunkid] =~ /^$emulproc/io) ||
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
				($chunknames[$chunkid] =~ /^$apprun/io));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
	elsif (/MT:D\s+(\d+)\s+([0-9a-fA-F]+)\s+(.+)\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
		die "Error: Parsing failure" unless (defined $current{$2});
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
		push @traces, [0+$1, $current{$2}, 0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
		delete $current{$2};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
	elsif (/(MT:.\s+.*)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
		printf "Warning: Unrecognised trace line \"$1\".\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
close TRACE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
die "Error: File \"$file\" does not contain any memory traces.\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
  unless ($#chunknames>0);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
# Group chunks together by name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
for (0..$#chunknames)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
	my $chunkid = $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
	my $name = $chunknames[$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
	$name = $1 if ($name =~ /($ramdrive)$/i);	# Special handling for ramdrive
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
	$name = $1 if ($name =~ /^$emulproc(.*)/i);	# Use thread names on Emulator
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
	($name) = ($name =~ /([^:]+)/);				# otherwise strip thread name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
	# yuck! linear search
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
	my $found = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
	for (0..$#groupnames)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
		my $groupid = $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
		if ($groupnames[$groupid] eq $name)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
			$found = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			push @{$groups[$groupid]}, $chunkid;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			$chunkgroup[$chunkid] = $groupid;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
			last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
	if (!$found)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
		push @groupnames, $name;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
		push @groups, [$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
		$chunkgroup[$chunkid] = $#groups;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
# Strip instance number (if any) from group name for presentation
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
for (0..$#groupnames)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
	$groupnames[$_] = $1 if ($groupnames[$_] =~ /^([^]]+]?)/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
# Output
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
my @chunksizes; # Array of chunk sizes, indexed by chunkid
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
for (0..$#chunknames) { $chunksizes[$_] = 0 };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
if ($opts{'detailed'})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
	# Detailed output
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
	foreach my $name (@groupnames) { print ",\"$name\"" };
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
	print "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
	# if the tick size in microseconds hasn't been reported in the log with MT:P, take a guess
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
	my $tickdiv = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
	if ($tickperiod == 0)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
		# Uses hacky method to determine whether on Emulator or Target
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
		$tickdiv = ($chunknames[0] =~ /^$emulproc/io) ? 10 : 64;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
	else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
		# tickperiod is number of microseconds 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
		$tickdiv = 1000000 / $tickperiod;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
	my ($oldtick, $minitick) = (0,0);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
	my @groupsizes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
	for my $trace (@traces)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
		my ($tick, $chunkid, $size) = @$trace;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
		if ($oldtick != $tick)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
			$oldtick = $tick;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
			$minitick=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
		$chunksizes[$chunkid] = $size;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
		my $groupid=$chunkgroup[$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
		my $groupsize = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
		foreach $chunkid (@{$groups[$groupid]})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
			$groupsize += $chunksizes[$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
		$groupsizes[$groupid] = $groupsize;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
		print $tick/$tickdiv + ($minitick++)/1000000;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
		foreach $groupsize (@groupsizes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
			if ($groupsize)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
				printf ",%d", $groupsize/1024;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
			else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
				print ',';		# make output prettier by omitting 0s
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
		print "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
	# Summary output
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
	my @grouphighs;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
	for my $trace (@traces)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
		my ($tick, $chunkid, $size) = @$trace;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
		$chunksizes[$chunkid] = $size;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
		my $groupid=$chunkgroup[$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
		my $groupsize = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
		foreach $chunkid (@{$groups[$groupid]})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
			$groupsize += $chunksizes[$chunkid];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
		$grouphighs[$groupid] = $groupsize
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
			if (!defined($grouphighs[$groupid]) ||
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
				($grouphighs[$groupid] < $groupsize));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
	printf "\"Process\", Size [K]\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
	for (0..$#groupnames)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
		printf "\"$groupnames[$_]\", %d\n", $grouphighs[$_]/1024;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
exit 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
sub help ()
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
	my $build;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
	&Load_ModuleL('E32TPVER');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
	print "\nmemtrace - " .
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
	  "Postprocess EPOC memory usage trace (Build ", &E32tpver, ")\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
	&usage;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
sub usage ()
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
	print <<EOF
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
Usage:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
  memtrace [-d] <logfile>
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
Where:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
  <logfile>     Memory usage trace file.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
Options:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
  -d            Produce a detailed listing.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
EOF
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
	;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
	}