sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/engine/statistic/BaseInfo.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     1 /*
       
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Definitions for the class BaseInfo
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.engine.statistic;
       
    19 
       
    20 import java.util.AbstractList;
       
    21 import java.util.ArrayList;
       
    22 import java.util.Hashtable;
       
    23 import java.util.Iterator;
       
    24 
       
    25 /**
       
    26  * Base class for {@link AllocInfo} and {@link FreeInfo}
       
    27  *
       
    28  * @author kihe
       
    29  *
       
    30  */
       
    31 public class BaseInfo {
       
    32 
       
    33 	/**
       
    34 	 * Cache for callstack items. Used when allocation fragment is parsed wrong
       
    35 	 * order.
       
    36 	 */
       
    37 	private final Hashtable<Integer, AbstractList<AllocCallstack>> callstackCache;
       
    38 
       
    39 	/** Memory address of this memory allocation. */
       
    40 	private Long memoryAddress;
       
    41 
       
    42 	/** Memory allocation process id. */
       
    43 	private int processID;
       
    44 
       
    45 	/** Allocation time */
       
    46 	private Long time;
       
    47 	
       
    48 	/** Total memory size at this time */
       
    49 	private int totalMemory = 0;
       
    50 	private int size = 0;
       
    51 
       
    52 	/**
       
    53 	 * Constructor
       
    54 	 */
       
    55 	public BaseInfo() {
       
    56 		callstackCache = new Hashtable<Integer, AbstractList<AllocCallstack>>();
       
    57 	}
       
    58 
       
    59 	/**
       
    60 	 * Sets memory allocation callstack
       
    61 	 *
       
    62 	 * @param callstack
       
    63 	 *            Memory allocation callstack
       
    64 	 */
       
    65 	public void addCallstack(AbstractList<AllocCallstack> callstack) {
       
    66 		callstackCache.put(0, callstack);
       
    67 	}
       
    68 
       
    69 	/**
       
    70 	 * Returns memory allocation callstack.
       
    71 	 *
       
    72 	 * @return Callstack of memory allocation
       
    73 	 */
       
    74 	public AbstractList<AllocCallstack> getCallstack() {
       
    75 		AbstractList<AllocCallstack> wholeCallstack = new ArrayList<AllocCallstack>();
       
    76 		int callstacksize = callstackCache.size();
       
    77 		for (int i = 0; i < callstacksize; i++) {
       
    78 			AbstractList<AllocCallstack> tempCallstack = callstackCache
       
    79 					.get(i);
       
    80 			if (tempCallstack == null || tempCallstack.isEmpty())
       
    81 				continue;
       
    82 			Iterator<AllocCallstack> iterCall = tempCallstack.iterator();
       
    83 			while (iterCall.hasNext()) {
       
    84 				wholeCallstack.add(iterCall.next());
       
    85 			}
       
    86 		}
       
    87 		return wholeCallstack;
       
    88 	}
       
    89 
       
    90 	/**
       
    91 	 * Returns memory address
       
    92 	 *
       
    93 	 * @return Memory address
       
    94 	 */
       
    95 	public Long getMemoryAddress() {
       
    96 		return memoryAddress;
       
    97 	}
       
    98 
       
    99 	/**
       
   100 	 * Returns process ID.
       
   101 	 *
       
   102 	 * @return Process ID.
       
   103 	 */
       
   104 	public int getProcessID() {
       
   105 		return processID;
       
   106 	}
       
   107 
       
   108 	/**
       
   109 	 * Returns time for the allocation
       
   110 	 *
       
   111 	 * @return Allocation time
       
   112 	 */
       
   113 	public Long getTime() {
       
   114 		return time == null ? 0 : time;
       
   115 	}
       
   116 
       
   117 
       
   118 	/**
       
   119 	 * Sets memory address
       
   120 	 *
       
   121 	 * @param newMemoryAddress
       
   122 	 *            Memory address
       
   123 	 */
       
   124 	public void setMemoryAddress(String newMemoryAddress) {
       
   125 		Long lValue = Long.parseLong(newMemoryAddress, 16);
       
   126 		this.memoryAddress = lValue;
       
   127 	}
       
   128 
       
   129 	/**
       
   130 	 * Sets process ID.
       
   131 	 *
       
   132 	 * @param newProcessID
       
   133 	 *            Process ID
       
   134 	 */
       
   135 	public void setProcessID(String newProcessID) {
       
   136 		int iValue = Integer.parseInt(newProcessID, 16);
       
   137 		this.processID = iValue;
       
   138 	}
       
   139 
       
   140 	/**
       
   141 	 * Sets time for the allocation
       
   142 	 *
       
   143 	 * @param newTime
       
   144 	 *            Allocation time
       
   145 	 */
       
   146 	public void setTime(String newTime) {
       
   147 		Long lValue = Long.parseLong(newTime, 16);
       
   148 		this.time = lValue;
       
   149 	}
       
   150 	
       
   151 	public void setTime(Long newTime)
       
   152 	{
       
   153 		this.time = newTime;
       
   154 	}
       
   155 
       
   156 	/**
       
   157 	 * Updates allocation fragment. Means that given callstack is addition to
       
   158 	 * previous added alloc
       
   159 	 *
       
   160 	 * @param callstack
       
   161 	 *            Addition callstack items
       
   162 	 * @param packetNumber
       
   163 	 *            AllocF id value
       
   164 	 */
       
   165 	public void updateFragment(AbstractList<AllocCallstack> callstack,
       
   166 			String packetNumber) {
       
   167 		callstackCache.put(Integer.parseInt(packetNumber, 16), callstack);
       
   168 	}
       
   169 	
       
   170 	/**
       
   171 	 * set total memory used at this time.
       
   172 	 * @param size 
       
   173 	 */
       
   174 	public void setTotalMem(int newSize) {
       
   175 		totalMemory = newSize;
       
   176 	}
       
   177 	
       
   178 	/**
       
   179 	 * get total memory used at this time
       
   180 	 * @return size
       
   181 	 */
       
   182 	public int getTotalMem() {
       
   183 		return totalMemory;
       
   184 	}
       
   185 	
       
   186 	public void setSizeInt(int aSize) {
       
   187 		size = aSize;
       
   188 	}
       
   189 	
       
   190 	public int getSizeInt() {
       
   191 		return size;
       
   192 	}
       
   193 }