sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.memory/src/com/nokia/carbide/cpp/pi/memory/MemTraceGraph.java
changeset 5 844b047e260d
parent 2 b9ab3b238396
child 12 ae255c9aa552
equal deleted inserted replaced
4:615035072f7e 5:844b047e260d
    19 
    19 
    20 import java.awt.Dimension;
    20 import java.awt.Dimension;
    21 import java.awt.event.FocusEvent;
    21 import java.awt.event.FocusEvent;
    22 import java.awt.event.FocusListener;
    22 import java.awt.event.FocusListener;
    23 import java.text.DecimalFormat;
    23 import java.text.DecimalFormat;
       
    24 import java.text.MessageFormat;
    24 import java.util.ArrayList;
    25 import java.util.ArrayList;
    25 import java.util.Enumeration;
    26 import java.util.Enumeration;
    26 import java.util.Hashtable;
    27 import java.util.Hashtable;
    27 import java.util.Iterator;
    28 import java.util.Iterator;
       
    29 import java.util.List;
    28 import java.util.TreeMap;
    30 import java.util.TreeMap;
    29 import java.util.Map.Entry;
       
    30 
    31 
    31 import org.eclipse.draw2d.ColorConstants;
    32 import org.eclipse.draw2d.ColorConstants;
    32 import org.eclipse.draw2d.FigureCanvas;
    33 import org.eclipse.draw2d.FigureCanvas;
    33 import org.eclipse.draw2d.Graphics;
    34 import org.eclipse.draw2d.Graphics;
    34 import org.eclipse.draw2d.MouseEvent;
    35 import org.eclipse.draw2d.MouseEvent;
    35 import org.eclipse.draw2d.MouseMotionListener;
    36 import org.eclipse.draw2d.MouseMotionListener;
    36 import org.eclipse.draw2d.Panel;
    37 import org.eclipse.draw2d.Panel;
       
    38 import org.eclipse.draw2d.geometry.PointList;
       
    39 import org.eclipse.jface.action.Action;
    37 import org.eclipse.jface.viewers.CheckboxTableViewer;
    40 import org.eclipse.jface.viewers.CheckboxTableViewer;
    38 import org.eclipse.swt.SWT;
    41 import org.eclipse.swt.SWT;
       
    42 import org.eclipse.swt.custom.SashForm;
    39 import org.eclipse.swt.events.SelectionAdapter;
    43 import org.eclipse.swt.events.SelectionAdapter;
    40 import org.eclipse.swt.events.SelectionEvent;
    44 import org.eclipse.swt.events.SelectionEvent;
    41 import org.eclipse.swt.graphics.Color;
    45 import org.eclipse.swt.graphics.Color;
    42 import org.eclipse.swt.graphics.GC;
    46 import org.eclipse.swt.graphics.GC;
    43 import org.eclipse.swt.graphics.Point;
    47 import org.eclipse.swt.graphics.Point;
    44 import org.eclipse.swt.graphics.RGB;
    48 import org.eclipse.swt.graphics.RGB;
    45 import org.eclipse.swt.graphics.Rectangle;
    49 import org.eclipse.swt.graphics.Rectangle;
       
    50 import org.eclipse.swt.layout.FillLayout;
       
    51 import org.eclipse.swt.layout.FormAttachment;
       
    52 import org.eclipse.swt.layout.FormData;
       
    53 import org.eclipse.swt.layout.FormLayout;
    46 import org.eclipse.swt.layout.GridData;
    54 import org.eclipse.swt.layout.GridData;
    47 import org.eclipse.swt.layout.GridLayout;
       
    48 import org.eclipse.swt.widgets.Composite;
    55 import org.eclipse.swt.widgets.Composite;
    49 import org.eclipse.swt.widgets.Display;
    56 import org.eclipse.swt.widgets.Display;
    50 import org.eclipse.swt.widgets.Event;
    57 import org.eclipse.swt.widgets.Event;
    51 import org.eclipse.swt.widgets.Label;
    58 import org.eclipse.swt.widgets.Listener;
    52 import org.eclipse.swt.widgets.Menu;
    59 import org.eclipse.swt.widgets.Menu;
    53 import org.eclipse.swt.widgets.MenuItem;
    60 import org.eclipse.swt.widgets.MenuItem;
       
    61 import org.eclipse.swt.widgets.Sash;
       
    62 import org.eclipse.ui.PlatformUI;
    54 
    63 
    55 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
    64 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
    56 import com.nokia.carbide.cpp.internal.pi.memory.actions.MemoryStatisticsDialog;
    65 import com.nokia.carbide.cpp.internal.pi.memory.actions.MemoryStatisticsDialog;
    57 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace;
    66 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace;
    58 import com.nokia.carbide.cpp.internal.pi.plugin.model.IContextMenu;
    67 import com.nokia.carbide.cpp.internal.pi.plugin.model.IContextMenu;
       
    68 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITitleBarMenu;
    59 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph;
    69 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph;
    60 import com.nokia.carbide.cpp.internal.pi.visual.GraphComposite;
    70 import com.nokia.carbide.cpp.internal.pi.visual.GraphComposite;
    61 import com.nokia.carbide.cpp.internal.pi.visual.PIEvent;
    71 import com.nokia.carbide.cpp.internal.pi.visual.PIEvent;
    62 import com.nokia.carbide.cpp.internal.pi.visual.PIEventListener;
    72 import com.nokia.carbide.cpp.internal.pi.visual.PIEventListener;
    63 import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
    73 import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
       
    74 import com.nokia.carbide.cpp.pi.memory.ProfiledLibraryEvent.GraphSamplePoint;
    64 import com.nokia.carbide.cpp.pi.util.ColorPalette;
    75 import com.nokia.carbide.cpp.pi.util.ColorPalette;
       
    76 import com.nokia.carbide.cpp.pi.visual.IGenericTraceGraph;
    65 
    77 
    66 public class MemTraceGraph extends GenericTraceGraph implements FocusListener,
    78 public class MemTraceGraph extends GenericTraceGraph implements FocusListener,
    67 		PIEventListener, MouseMotionListener, IContextMenu {
    79 		PIEventListener, MouseMotionListener, IContextMenu, ITitleBarMenu {
    68 	private enum UsageType {
    80 	private enum UsageType {
    69 		CHUNKS, HEAPSTACK, CHUNKS_HEAPSTACK
    81 		CHUNKS, HEAPSTACK, CHUNKS_HEAPSTACK
    70 	};
    82 	};
    71 
    83 
    72 	private boolean dynamicMemoryVisualisation = false;
    84 	private boolean dynamicMemoryVisualisation = false;
    73 
    85 
    74 	private MemThreadTable memThreadTable;
    86 	private MemThreadTable memThreadTable;
       
    87 	private MemLibraryEventTable memLibraryEventTable;
    75 	private CheckboxTableViewer memoryTableViewer;
    88 	private CheckboxTableViewer memoryTableViewer;
    76 
    89 
    77 	Hashtable<Integer, Integer> threadList;
    90 	Hashtable<Integer, Integer> threadList;
    78 
    91 
    79 	// 3 tabs can share the same trace, but they need different graphs
    92 	// 3 tabs can share the same trace, but they need different graphs
   113 	private DecimalFormat memKBFormat = new DecimalFormat(Messages
   126 	private DecimalFormat memKBFormat = new DecimalFormat(Messages
   114 			.getString("MemTraceGraph.KBformat")); //$NON-NLS-1$
   127 			.getString("MemTraceGraph.KBformat")); //$NON-NLS-1$
   115 	private DecimalFormat memMBFloatFormat = new DecimalFormat(Messages
   128 	private DecimalFormat memMBFloatFormat = new DecimalFormat(Messages
   116 			.getString("MemTraceGraph.MBformat")); //$NON-NLS-1$
   129 			.getString("MemTraceGraph.MBformat")); //$NON-NLS-1$
   117 
   130 
   118 	private static int xLegendHeight = 20;
   131 	private static int xLegendHeight = 50;
   119 
   132 
   120 	private boolean firstTimeDrawThreadList = true;
   133 	private boolean firstTimeDrawThreadList = true;
       
   134 
       
   135 	private Composite holder;
       
   136 	private boolean isLibraryEventTrace = false;
       
   137 	
       
   138 	private final boolean[] lockMouseToolTipResolver ={false}; 
       
   139 	private boolean showMemoryUsageLine = true;
   121 	
   140 	
   122 	public MemTraceGraph(int graphIndex, MemTrace memTrace, int uid) {
   141 	public MemTraceGraph(int graphIndex, MemTrace memTrace, int uid) {
   123 		super((GenericSampledTrace) memTrace);
   142 		super((GenericSampledTrace) memTrace);
   124 
       
   125 		// 
       
   126 
   143 
   127 		if (memTrace != null) {
   144 		if (memTrace != null) {
   128 
   145 
   129 			// if no version number is found from trace, we can assume
   146 			// if no version number is found from trace, we can assume
   130 			// that sampling based memory model is in use
   147 			// that sampling based memory model is in use
   143 			System.out.print(Messages
   160 			System.out.print(Messages
   144 					.getString("MemTraceGraph.traceDataNotFound")); //$NON-NLS-1$
   161 					.getString("MemTraceGraph.traceDataNotFound")); //$NON-NLS-1$
   145 			return;
   162 			return;
   146 		}
   163 		}
   147 
   164 
       
   165 		if(memTrace.getVersion() >= 203){
       
   166 			isLibraryEventTrace = true;
       
   167 		}
       
   168 		
   148 		samplingTime = calcSamplingTime();
   169 		samplingTime = calcSamplingTime();
   149 		memTrace.gatherDrawData();
   170 		memTrace.gatherDrawData();
   150 
   171 
       
   172 		
   151 		// create the label and a tableviewer
   173 		// create the label and a tableviewer
   152 		Composite holder = new Composite(NpiInstanceRepository.getInstance()
   174 		holder = new Composite(NpiInstanceRepository.getInstance()
   153 				.getProfilePage(uid, graphIndex).getBottomComposite(), SWT.NONE);
   175 				.getProfilePage(uid, graphIndex).getBottomComposite(), SWT.NONE);
   154 
   176 		PlatformUI.getWorkbench().getHelpSystem().setHelp(holder, MemoryPlugin.HELP_CONTEXT_ID_MAIN_PAGE);
   155 		GridLayout gl = new GridLayout();
   177 		
   156 		gl.marginHeight = 0;
   178 		if(isLibraryEventTrace){	
   157 		gl.marginWidth = 0;
   179 			FormLayout formLayout = new FormLayout();
   158 		gl.marginLeft = 0;
   180 			formLayout.marginHeight = 0;
   159 		gl.marginRight = 0;
   181 			formLayout.marginWidth = 0;
   160 		holder.setLayout(gl);
   182 			formLayout.marginLeft = 0;
   161 
   183 			formLayout.marginRight = 0;
   162 		Label label = new Label(holder, SWT.CENTER);
   184 			holder.setLayout(formLayout);
   163 		label
   185 			holder.setLayoutData(new GridData(GridData.FILL_BOTH));
   164 				.setBackground(holder.getDisplay().getSystemColor(
   186 			
   165 						SWT.COLOR_WHITE));
   187 		    final Sash sash = new Sash(holder, SWT.VERTICAL);
   166 		label.setFont(PIPageEditor.helvetica_8);
   188 		    final FormData data = new FormData();
   167 		label.setText(Messages.getString("MemTraceGraph.graphTitle")); //$NON-NLS-1$
   189 		    data.top = new FormAttachment(0);
   168 		label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   190 		    data.bottom = new FormAttachment(100); 
   169 
   191 		    data.left = new FormAttachment(50); 
   170 		this.memThreadTable = new MemThreadTable(this, holder);
   192 		    sash.setLayoutData(data);
       
   193 		
       
   194 		    // Memory usage table
       
   195 		    FormData leftData = new FormData();
       
   196 		    leftData.top = new FormAttachment(0);
       
   197 		    leftData.bottom = new FormAttachment(100);
       
   198 		    leftData.left = new FormAttachment(0);
       
   199 		    leftData.right = new FormAttachment(sash);		    
       
   200 		    SashForm sfLeft = new SashForm(holder, SWT.NONE);
       
   201 		    sfLeft.setLayout(formLayout);
       
   202 		    sfLeft.setLayoutData(leftData);		 
       
   203 		    this.memThreadTable = new MemThreadTable(this, sfLeft);
       
   204 			    
       
   205 		    
       
   206 		    // Library event table
       
   207 		    FormData rightData = new FormData();
       
   208 		    rightData.top = new FormAttachment(0, 0);
       
   209 		    rightData.bottom = new FormAttachment(100, 0);
       
   210 		    rightData.left = new FormAttachment(sash, 0);
       
   211 		    rightData.right = new FormAttachment(100, 0);
       
   212 		    
       
   213 		    SashForm sfRight = new SashForm(holder, SWT.NONE);
       
   214 		    sfRight.setLayout(formLayout);
       
   215 		    sfRight.setLayoutData(rightData);		 
       
   216 		    this.memLibraryEventTable = new MemLibraryEventTable(this, sfRight);
       
   217 			
       
   218 		    // allow to drag the sash
       
   219 		    sash.addListener(SWT.Selection, new Listener() {
       
   220 				public void handleEvent(Event event) {
       
   221 					if (event.detail != SWT.DRAG) {
       
   222 						data.left = new FormAttachment(0, event.x);
       
   223 						sash.getParent().layout();					
       
   224 					}
       
   225 				}
       
   226 			});
       
   227 		}else{				
       
   228 			holder.setLayout(new FillLayout());
       
   229 			this.memThreadTable = new MemThreadTable(this, holder);
       
   230 		}
   171 		this.memoryTableViewer = this.memThreadTable.getTableViewer();
   231 		this.memoryTableViewer = this.memThreadTable.getTableViewer();
   172 
   232 
   173 		this.readyToDraw = true;
   233 		this.readyToDraw = true;
   174 	}
   234 	}
   175 
   235 
   189 			makeThreadDrawLists();
   249 			makeThreadDrawLists();
   190 		} else if (actionString.equals("rescale_off")) //$NON-NLS-1$
   250 		} else if (actionString.equals("rescale_off")) //$NON-NLS-1$
   191 		{
   251 		{
   192 			dynamicMemoryVisualisation = false;
   252 			dynamicMemoryVisualisation = false;
   193 			makeThreadDrawLists();
   253 			makeThreadDrawLists();
   194 		} else {
   254 		}  else if (actionString.equals("memory_usage_line_on")) //$NON-NLS-1$
       
   255 		{
       
   256 			showMemoryUsageLine = true;
       
   257 		}  else if (actionString.equals("memory_usage_line_off")) //$NON-NLS-1$
       
   258 		{
       
   259 			showMemoryUsageLine = false;
       
   260 		}else {
   195 			return;
   261 			return;
   196 		}
   262 		}
   197 
   263 
   198 		this.repaint();
   264 		this.repaint();
   199 		if (this.leftFigureCanvas != null)
   265 		if (this.leftFigureCanvas != null)
   214 			double startTime = PIPageEditor.currentPageEditor().getStartTime();
   280 			double startTime = PIPageEditor.currentPageEditor().getStartTime();
   215 			double endTime = PIPageEditor.currentPageEditor().getEndTime();
   281 			double endTime = PIPageEditor.currentPageEditor().getEndTime();
   216 
   282 
   217 			memTrace.setMaxMemDataByInterval((int) (startTime * 1000),
   283 			memTrace.setMaxMemDataByInterval((int) (startTime * 1000),
   218 					(int) (endTime * 1000));
   284 					(int) (endTime * 1000));
       
   285 		
       
   286 			if(isLibraryEventTrace){
       
   287 				memTrace.setMaxMemLibraryEventDataByInterval((int) (startTime * 1000),
       
   288 					(int) (endTime * 1000));
       
   289 			}
   219 
   290 
   220 			// send this message to the 2 other graphs
   291 			// send this message to the 2 other graphs
   221 			PIEvent be2 = new PIEvent(be.getValueObject(),
   292 			PIEvent be2 = new PIEvent(be.getValueObject(),
   222 					PIEvent.SELECTION_AREA_CHANGED2);
   293 					PIEvent.SELECTION_AREA_CHANGED2);
   223 
   294 
   235 		case PIEvent.SELECTION_AREA_CHANGED2:
   306 		case PIEvent.SELECTION_AREA_CHANGED2:
   236 			double[] values = (double[]) be.getValueObject();
   307 			double[] values = (double[]) be.getValueObject();
   237 			this.setSelectionStart(values[0]);
   308 			this.setSelectionStart(values[0]);
   238 			this.setSelectionEnd(values[1]);
   309 			this.setSelectionEnd(values[1]);
   239 			this.memThreadTable.piEventReceived(be);
   310 			this.memThreadTable.piEventReceived(be);
       
   311 			if(this.memLibraryEventTable != null){
       
   312 				this.memLibraryEventTable.piEventReceived(be);
       
   313 			}		
   240 			this.repaint();
   314 			this.repaint();
   241 			break;
   315 			break;
   242 
   316 
   243 		case PIEvent.CHANGED_MEMORY_TABLE:
   317 		case PIEvent.CHANGED_MEMORY_TABLE:
   244 			this.makeThreadDrawLists();
   318 			this.makeThreadDrawLists();
   245 			this.repaint();
   319 			this.repaint();
   246 			if (this.leftFigureCanvas != null)
   320 			if (this.leftFigureCanvas != null)
   247 				this.leftFigureCanvas.redraw();
   321 				this.leftFigureCanvas.redraw();
       
   322 			if(memLibraryEventTable != null){				
       
   323 				memLibraryEventTable.updateSelection(memThreadTable.getTableViewer().getCheckedElements());	
       
   324 			}
   248 			break;
   325 			break;
   249 
   326 
   250 		case PIEvent.SCALE_CHANGED:
   327 		case PIEvent.SCALE_CHANGED:
   251 			double scale = ((Double) be.getValueObject()).doubleValue();
   328 			double scale = ((Double) be.getValueObject()).doubleValue();
   252 			this.setScale(scale);
   329 			this.setScale(scale);
   253 			this.repaint();
   330 			this.repaint();
   254 			break;
   331 			break;
   255 
   332 
   256 		case PIEvent.SCROLLED:
   333 		case PIEvent.SCROLLED:
   257 			Event event = ((Event) be.getValueObject());
   334 			Event event = ((Event) be.getValueObject());
   258 			this.parentComponent.setScrolledOrigin(event.x, event.y);
   335 			this.parentComponent.setScrolledOrigin(event.x, event.y, (FigureCanvas)event.data);
   259 			this.repaint();
   336 			this.repaint();
   260 			break;
   337 			break;
   261 
   338 
   262 		default:
   339 		default:
   263 			break;
   340 			break;
   276 
   353 
   277 		this.setSize(this.getSize().width, getVisualSize().height);
   354 		this.setSize(this.getSize().width, getVisualSize().height);
   278 		this.makeThreadDrawLists();
   355 		this.makeThreadDrawLists();
   279 		this.paintThreads(graphics);
   356 		this.paintThreads(graphics);
   280 		this.drawDottedLineBackground(graphics, MemTraceGraph.xLegendHeight);
   357 		this.drawDottedLineBackground(graphics, MemTraceGraph.xLegendHeight);
   281 
   358 		
       
   359 		if(showMemoryUsageLine){
       
   360 			paintMemoryUsageLine(graphics);
       
   361 		}		
       
   362 		if(isLibraryEventTrace){
       
   363 			paintLibraryEvents(graphics);
       
   364 		}
       
   365 		
   282 		// draw the same selection as the Address/Thread trace
   366 		// draw the same selection as the Address/Thread trace
   283 		this.drawSelectionSection(graphics, MemTraceGraph.xLegendHeight);
   367 		this.drawSelectionSection(graphics, MemTraceGraph.xLegendHeight);
       
   368 		
       
   369 	}
       
   370 	
       
   371 	private void paintLibraryEvents(Graphics graphics){
       
   372 		Enumeration<ProfiledLibraryEvent> enume = memTrace.getLibraryEvents().elements();	
       
   373 		while(enume.hasMoreElements()){
       
   374 			ProfiledLibraryEvent ple = enume.nextElement();	
       
   375 			if(!ple.isEnabled(graphIndex)){
       
   376 				continue;
       
   377 			}
       
   378 			List<GraphSamplePoint> pointList = ple.getGraphSamplePoints();
       
   379 			Iterator<GraphSamplePoint> iterator = pointList.iterator();
       
   380 			while (iterator.hasNext()) {
       
   381 				GraphSamplePoint samplePoint = iterator.next();
       
   382 				graphics.setBackgroundColor(ple.getColor());
       
   383 				graphics.setForegroundColor(ple.getColor());
       
   384 				drawThreadMarks((int) samplePoint.firstSamplePoint,
       
   385 						(int) samplePoint.lastSamplePoint,
       
   386 						this.getVisualSize().height, graphics);
       
   387 			}
       
   388 		}
       
   389 	}
       
   390 	
       
   391 	private void paintMemoryUsageLine(Graphics graphics){
       
   392 		Color black = ColorPalette.getColor(new RGB(0, 0, 0));
       
   393 		graphics.setBackgroundColor(black);
       
   394 		graphics.setForegroundColor(black);
       
   395 		PointList pl = new PointList();
       
   396 		Iterator<MemSampleByTime> iterator = memTrace.getDrawDataByTime().iterator();
       
   397 		while(iterator.hasNext()){
       
   398 			MemSampleByTime msbt = iterator.next();	
       
   399 			// calculate new x coord's value and round it to integer
       
   400 			int xCoord = (int) ((msbt.getTime()/getScale()) + 0.5);
       
   401 			int maxBytes;
       
   402 			if (dynamicMemoryVisualisation)
       
   403 				maxBytes = maxChunks;
       
   404 			else
       
   405 				maxBytes = memTrace.getTraceMaxChunks();
       
   406 			int yMultiplier = prettyMaxBytes(maxBytes) / height;
       
   407 			// calculate new y-coord's value and round it to integer
       
   408 			int yCoord = (int) (((double) height - (double) msbt.getUsedMemory()
       
   409 					/ yMultiplier) + 0.5);				
       
   410 			pl.addPoint(xCoord,yCoord);
       
   411 		}
       
   412 		graphics.setLineWidth(2);
       
   413 		graphics.drawPolyline(pl);		
   284 	}
   414 	}
   285 
   415 
   286 	private void paintSampledChunks(Graphics graphics) {
   416 	private void paintSampledChunks(Graphics graphics) {
   287 		if (chunkListY == null)
   417 		if (chunkListY == null)
   288 			return;
   418 			return;
   585 		int previousYCoord = 0;
   715 		int previousYCoord = 0;
   586 
   716 
   587 		// get first event and key from map.
   717 		// get first event and key from map.
   588 		Iterator<Long> keys = map.keySet().iterator();
   718 		Iterator<Long> keys = map.keySet().iterator();
   589 		Iterator<Integer> values = map.values().iterator();
   719 		Iterator<Integer> values = map.values().iterator();
   590 		
   720 
   591 	
       
   592 		int previousXCoord = 0;
   721 		int previousXCoord = 0;
   593 		int countOfSameXCoords = 1;
   722 		int countOfSameXCoords = 1;
   594 
   723 
   595 		// set first into zero so that polygon is drawn correctly
   724 		// set first into zero so that polygon is drawn correctly
   596 		points[0] = 0;
   725 		points[0] = 0;
   602 
   731 
   603 			// calculate new x coord's value and round it to integer
   732 			// calculate new x coord's value and round it to integer
   604 			xCoord = (int) (((double) keys.next() / xMultiplier) + 0.5);
   733 			xCoord = (int) (((double) keys.next() / xMultiplier) + 0.5);
   605 
   734 
   606 			// calculate new y-coord's value and round it to integer
   735 			// calculate new y-coord's value and round it to integer
   607 			yCoord = (int) (((double) height - (double) values.next() / yMultiplier) + 0.5);
   736 			yCoord = (int) (((double) height - (double) values.next()
       
   737 					/ yMultiplier) + 0.5);
   608 
   738 
   609 			if (xCoord == previousXCoord && index > 3) {
   739 			if (xCoord == previousXCoord && index > 3) {
   610 				// if more than one sample at one point in the screen, count
   740 				// if more than one sample at one point in the screen, count
   611 				// average value
   741 				// average value
   612 				// for y coordinate
   742 				// for y coordinate
   719 								.getString("MemTraceGraph.threadProcessNoSamples1") + memThread.fullName + Messages.getString("MemTraceGraph.threadProcessNoSamples")); //$NON-NLS-1$ //$NON-NLS-2$
   849 								.getString("MemTraceGraph.threadProcessNoSamples1") + memThread.fullName + Messages.getString("MemTraceGraph.threadProcessNoSamples")); //$NON-NLS-1$ //$NON-NLS-2$
   720 				continue;
   850 				continue;
   721 			}
   851 			}
   722 
   852 
   723 			// create empty sample
   853 			// create empty sample
   724 			MemSample previousSample = new MemSample(new MemThread(0, "", ""),
   854 			MemSample previousSample = new MemSample(new MemThread(0, "", ""), //$NON-NLS-1$ //$NON-NLS-2$
   725 					0, 0, 0);
   855 					0, 0, 0);
   726 
   856 
   727 			Iterator<MemSample> values = memSamples.values().iterator();
   857 			Iterator<MemSample> values = memSamples.values().iterator();
   728 
   858 
   729 			while (values.hasNext()) {
   859 			while (values.hasNext()) {
   730 				MemSample memSample = values.next(); 
   860 				MemSample memSample = values.next();
   731 				// go thru samples from single threas
   861 				// go thru samples from single threas
   732 				// save changes after last received sample into TreeMaps
   862 				// save changes after last received sample into TreeMaps
   733 				addEventToTreeMap(this.eventStackListY,
   863 				addEventToTreeMap(this.eventStackListY,
   734 						memSample.sampleSynchTime, memSample.stackSize
   864 						memSample.sampleSynchTime, memSample.stackSize
   735 								- previousSample.stackSize);
   865 								- previousSample.stackSize);
   755 
   885 
   756 		if (this.memTrace.getTraceMaxChunks() == 0) {
   886 		if (this.memTrace.getTraceMaxChunks() == 0) {
   757 			this.memTrace.setTraceMaxChunks(maxChunks);
   887 			this.memTrace.setTraceMaxChunks(maxChunks);
   758 			this.memTrace.setTraceMaxStackHeap(maxStack);
   888 			this.memTrace.setTraceMaxStackHeap(maxStack);
   759 			this.memTrace.setTraceMaxTotal(maxStackHeap);
   889 			this.memTrace.setTraceMaxTotal(maxStackHeap);
   760 			
   890 
   761 			//repaint left legend if this is first time that tread lists are made
   891 			// repaint left legend if this is first time that tread lists are
   762 			if(firstTimeDrawThreadList){
   892 			// made
       
   893 			if (firstTimeDrawThreadList) {
   763 				this.parentComponent.paintLeftLegend();
   894 				this.parentComponent.paintLeftLegend();
   764 				firstTimeDrawThreadList = false;
   895 				firstTimeDrawThreadList = false;
   765 			}
   896 			}
   766 
   897 
   767 		}
   898 		}
   779 
   910 
   780 		Iterator<Integer> values = map.values().iterator();
   911 		Iterator<Integer> values = map.values().iterator();
   781 		Iterator<Long> keys = map.keySet().iterator();
   912 		Iterator<Long> keys = map.keySet().iterator();
   782 
   913 
   783 		while (values.hasNext()) {
   914 		while (values.hasNext()) {
   784 			
   915 
   785 			int memValue = values.next();
   916 			int memValue = values.next();
   786 			long memKey = keys.next();
   917 			long memKey = keys.next();
   787 			
   918 
   788 			// go thru array and count actual state of
   919 			// go thru array and count actual state of
   789 			// memory in each event
   920 			// memory in each event
   790 			int value = previousValue + memValue;
   921 			int value = previousValue + memValue;
   791 
   922 
   792 			// is value is greater that max value save
   923 			// is value is greater that max value save
   900 					this.chunkListY[index] += memSample.heapSize;
  1031 					this.chunkListY[index] += memSample.heapSize;
   901 					this.chunkStackListY[index] += memSample.heapSize
  1032 					this.chunkStackListY[index] += memSample.heapSize
   902 							+ memSample.stackSize;
  1033 							+ memSample.stackSize;
   903 					counter++;
  1034 					counter++;
   904 				}
  1035 				}
   905 				
  1036 
   906 			}
  1037 			}
   907 
  1038 
   908 			// tempListX[0] = (int)
  1039 			// tempListX[0] = (int)
   909 			// (((MemSample)memSamples.firstEntry().getValue()).sampleSynchTime
  1040 			// (((MemSample)memSamples.firstEntry().getValue()).sampleSynchTime
   910 			// / getScale());
  1041 			// / getScale());
   911 			MemSample firstMemSample = (MemSample)memSamples.get(memSamples.firstKey());
  1042 			MemSample firstMemSample = (MemSample) memSamples.get(memSamples
       
  1043 					.firstKey());
   912 			tempListX[0] = (int) ((firstMemSample.sampleSynchTime / getScale()));
  1044 			tempListX[0] = (int) ((firstMemSample.sampleSynchTime / getScale()));
   913 			tempListX[tempListX.length - 1] = tempListX[tempListX.length - 2];
  1045 			tempListX[tempListX.length - 1] = tempListX[tempListX.length - 2];
   914 
  1046 
   915 			// defaults the originating and ending points into window corners
  1047 			// defaults the originating and ending points into window corners
   916 			this.stackListY[0] = height;
  1048 			this.stackListY[0] = height;
  1034 	 * addContextMenuItems(org.eclipse.swt.widgets.Menu,
  1166 	 * addContextMenuItems(org.eclipse.swt.widgets.Menu,
  1035 	 * org.eclipse.swt.events.MouseEvent)
  1167 	 * org.eclipse.swt.events.MouseEvent)
  1036 	 */
  1168 	 */
  1037 	public void addContextMenuItems(Menu menu,
  1169 	public void addContextMenuItems(Menu menu,
  1038 			org.eclipse.swt.events.MouseEvent me) {
  1170 			org.eclipse.swt.events.MouseEvent me) {
       
  1171 
  1039 		new MenuItem(menu, SWT.SEPARATOR);
  1172 		new MenuItem(menu, SWT.SEPARATOR);
  1040 
  1173 
  1041 		MenuItem memoryStatsItem = new MenuItem(menu, SWT.PUSH);
  1174 		MenuItem memoryStatsItem = new MenuItem(menu, SWT.PUSH);
  1042 		memoryStatsItem.setText(Messages.getString("MemoryPlugin.memoryStats")); //$NON-NLS-1$
  1175 		memoryStatsItem.setText(Messages.getString("MemoryPlugin.memoryStats")); //$NON-NLS-1$
  1043 		memoryStatsItem.addSelectionListener(new SelectionAdapter() {
  1176 		memoryStatsItem.addSelectionListener(new SelectionAdapter() {
  1044 			public void widgetSelected(SelectionEvent e) {
  1177 			public void widgetSelected(SelectionEvent e) {
  1045 				new MemoryStatisticsDialog(Display.getCurrent());
  1178 				new MemoryStatisticsDialog(Display.getCurrent());
  1046 			}
  1179 			}
  1047 		});
  1180 		});
  1048 
  1181 
  1049 		new MenuItem(menu, SWT.SEPARATOR);
       
  1050 
       
  1051 		boolean showChunk = true;
       
  1052 		boolean showHeapStack = true;
       
  1053 
       
  1054 		Object obj;
  1182 		Object obj;
  1055 		// if there is a showChunk value associated with the current Analyser
       
  1056 		// tab, then use it
       
  1057 		obj = NpiInstanceRepository.getInstance().activeUidGetPersistState(
       
  1058 				"com.nokia.carbide.cpp.pi.memory.showChunk"); //$NON-NLS-1$
       
  1059 		if ((obj != null) && (obj instanceof Boolean))
       
  1060 			// retrieve the current value
       
  1061 			showChunk = (Boolean) obj;
       
  1062 		else
       
  1063 			// set the initial value
       
  1064 			NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1065 					"com.nokia.carbide.cpp.pi.memory.showChunk", showChunk); //$NON-NLS-1$
       
  1066 
       
  1067 		// if there is a showHeapStack value associated with the current
       
  1068 		// Analyser tab, then use it
       
  1069 		obj = NpiInstanceRepository.getInstance().activeUidGetPersistState(
       
  1070 				"com.nokia.carbide.cpp.pi.memory.showHeapStack"); //$NON-NLS-1$
       
  1071 		if ((obj != null) && (obj instanceof Boolean))
       
  1072 			// retrieve the current value
       
  1073 			showHeapStack = (Boolean) obj;
       
  1074 		else
       
  1075 			// set the initial value
       
  1076 			NpiInstanceRepository
       
  1077 					.getInstance()
       
  1078 					.activeUidSetPersistState(
       
  1079 							"com.nokia.carbide.cpp.pi.memory.showHeapStack", showHeapStack); //$NON-NLS-1$
       
  1080 
       
  1081 		MenuItem showChunkItem = new MenuItem(menu, SWT.RADIO);
       
  1082 		showChunkItem.setText(Messages.getString("MemoryPlugin.showChunks")); //$NON-NLS-1$
       
  1083 		showChunkItem.setSelection(showChunk && !showHeapStack);
       
  1084 		showChunkItem.addSelectionListener(new SelectionAdapter() {
       
  1085 			public void widgetSelected(SelectionEvent e) {
       
  1086 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1087 						"com.nokia.carbide.cpp.pi.memory.showChunk", true); //$NON-NLS-1$
       
  1088 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1089 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", false); //$NON-NLS-1$
       
  1090 
       
  1091 				for (int i = 0; i < 3; i++) {
       
  1092 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1093 							.getTraceGraph(i);
       
  1094 					graph.action("chunk_on"); //$NON-NLS-1$
       
  1095 				}
       
  1096 			}
       
  1097 		});
       
  1098 
       
  1099 		MenuItem showHeapItem = new MenuItem(menu, SWT.RADIO);
       
  1100 		showHeapItem.setText(Messages.getString("MemoryPlugin.showHeapStack")); //$NON-NLS-1$
       
  1101 		showHeapItem.setSelection(showHeapStack && !showChunk);
       
  1102 		showHeapItem.addSelectionListener(new SelectionAdapter() {
       
  1103 			public void widgetSelected(SelectionEvent e) {
       
  1104 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1105 						"com.nokia.carbide.cpp.pi.memory.showChunk", false); //$NON-NLS-1$
       
  1106 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1107 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", true); //$NON-NLS-1$
       
  1108 
       
  1109 				for (int i = 0; i < 3; i++) {
       
  1110 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1111 							.getTraceGraph(i);
       
  1112 					graph.action("heapstack_on"); //$NON-NLS-1$
       
  1113 				}
       
  1114 			}
       
  1115 		});
       
  1116 
       
  1117 		MenuItem showBothItem = new MenuItem(menu, SWT.RADIO);
       
  1118 		showBothItem.setText(Messages.getString("MemoryPlugin.showAll")); //$NON-NLS-1$
       
  1119 		showBothItem.setSelection(showChunk && showHeapStack);
       
  1120 		showBothItem.addSelectionListener(new SelectionAdapter() {
       
  1121 			public void widgetSelected(SelectionEvent e) {
       
  1122 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1123 						"com.nokia.carbide.cpp.pi.memory.showChunk", true); //$NON-NLS-1$
       
  1124 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1125 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", true); //$NON-NLS-1$
       
  1126 
       
  1127 				for (int i = 0; i < 3; i++) {
       
  1128 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1129 							.getTraceGraph(i);
       
  1130 					graph.action("chunk_heapstack_on"); //$NON-NLS-1$
       
  1131 				}
       
  1132 			}
       
  1133 		});
       
  1134 
       
  1135 		new MenuItem(menu, SWT.SEPARATOR);
       
  1136 
  1183 
  1137 		boolean rescale = false;
  1184 		boolean rescale = false;
  1138 
  1185 
  1139 		// if there is a rescale value associated with the current Analyser tab,
  1186 		// if there is a rescale value associated with the current Analyser tab,
  1140 		// then use it
  1187 		// then use it
  1168 
  1215 
  1169 				for (int i = 0; i < 3; i++) {
  1216 				for (int i = 0; i < 3; i++) {
  1170 					MemTraceGraph graph = (MemTraceGraph) memTrace
  1217 					MemTraceGraph graph = (MemTraceGraph) memTrace
  1171 							.getTraceGraph(i);
  1218 							.getTraceGraph(i);
  1172 					graph.action(action);
  1219 					graph.action(action);
  1173 				}
  1220 				}		
       
  1221 				MemoryPlugin.getDefault().updateMenuItems();
  1174 			}
  1222 			}
  1175 		});
  1223 		});
       
  1224 		
       
  1225 		// if there is a show memory usage value associated with the current Analyser tab, then use it		
       
  1226 		obj = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.memory.showMemoryUsage");	//$NON-NLS-1$
       
  1227 		if ((obj != null) && (obj instanceof Boolean))
       
  1228 			// retrieve the current value
       
  1229 			showMemoryUsageLine = (Boolean)obj;
       
  1230 		else
       
  1231 			// set the initial value
       
  1232 			NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.memory.showMemoryUsage", showMemoryUsageLine);	//$NON-NLS-1$
       
  1233 		
       
  1234 		new MenuItem(menu, SWT.SEPARATOR);		
       
  1235 		MenuItem memoryUsageLine = new MenuItem(menu, SWT.CHECK);
       
  1236 		memoryUsageLine.setText(Messages.getString("MemTraceGraph.showTotalMemoryUsage")); //$NON-NLS-1$
       
  1237 		memoryUsageLine.addSelectionListener(new SelectionAdapter() {
       
  1238 			public void widgetSelected(SelectionEvent e) {
       
  1239 				showMemoryUsageLine = !showMemoryUsageLine;
       
  1240 				NpiInstanceRepository
       
  1241 				.getInstance()
       
  1242 				.activeUidSetPersistState(
       
  1243 						"com.nokia.carbide.cpp.pi.memory.showMemoryUsage", showMemoryUsageLine); //$NON-NLS-1$
       
  1244 				repaint();			
       
  1245 				MemoryPlugin.getDefault().updateMenuItems();
       
  1246 			}
       
  1247 		});
       
  1248 		memoryUsageLine.setSelection(showMemoryUsageLine);
       
  1249 		
  1176 	}
  1250 	}
  1177 
  1251 
  1178 	public void paintLeftLegend(FigureCanvas figureCanvas, GC gc) {
  1252 	public void paintLeftLegend(FigureCanvas figureCanvas, GC gc) {
  1179 		// System.out.println("MEM"); if (true)return;
  1253 		// System.out.println("MEM"); if (true)return;
  1180 		// if there are no threads to draw
  1254 		// if there are no threads to draw
  1253 						+ Messages.getString("MemTraceGraph.byMB"); //$NON-NLS-1$
  1327 						+ Messages.getString("MemTraceGraph.byMB"); //$NON-NLS-1$
  1254 			}
  1328 			}
  1255 
  1329 
  1256 			Point extent = gc.stringExtent(legend);
  1330 			Point extent = gc.stringExtent(legend);
  1257 
  1331 
  1258 			gc.drawLine(GenericTraceGraph.yLegendWidth - 3, (int) y + 1,
  1332 			gc.drawLine(IGenericTraceGraph.Y_LEGEND_WIDTH - 3, (int) y + 1,
  1259 					GenericTraceGraph.yLegendWidth, (int) y + 1);
  1333 					IGenericTraceGraph.Y_LEGEND_WIDTH, (int) y + 1);
  1260 
  1334 
  1261 			if (y >= previousBottom) {
  1335 			if (y >= previousBottom) {
  1262 				gc.drawString(legend, GenericTraceGraph.yLegendWidth - extent.x
  1336 				gc.drawString(legend, IGenericTraceGraph.Y_LEGEND_WIDTH - extent.x
  1263 						- 4, (int) y);
  1337 						- 4, (int) y);
  1264 				previousBottom = (int) y + extent.y;
  1338 				previousBottom = (int) y + extent.y;
  1265 			}
  1339 			}
  1266 		}
  1340 		}
  1267 
  1341 
  1320 	 */
  1394 	 */
  1321 	public void mouseMoved(MouseEvent me) {
  1395 	public void mouseMoved(MouseEvent me) {
  1322 		double x = me.x * this.getScale();
  1396 		double x = me.x * this.getScale();
  1323 		double y = me.y;
  1397 		double y = me.y;
  1324 
  1398 
  1325 		if (y > this.getVisualSizeY() - MemTraceGraph.xLegendHeight) {
       
  1326 			this.setToolTipText(null);
       
  1327 			return;
       
  1328 		}
       
  1329 
       
  1330 		// mouse event may return out of range X, that may
  1399 		// mouse event may return out of range X, that may
  1331 		// crash when we use it to index data array
  1400 		// crash when we use it to index data array
  1332 		x = x >= 0 ? x : 0;
  1401 		x = x >= 0 ? x : 0;
  1333 		if (me.x >= this.getVisualSize().width
  1402 		if (me.x >= this.getVisualSize().width
  1334 				+ this.parentComponent.getScrolledOrigin().x) {
  1403 				+ this.parentComponent.getScrolledOrigin(this).x) {
  1335 			x = (this.getVisualSize().width - 1) * this.getScale();
  1404 			x = (this.getVisualSize().width - 1) * this.getScale();
  1336 		}
  1405 		}
  1337 
  1406 
  1338 		if (x > PIPageEditor.currentPageEditor().getMaxEndTime() * 1000) {
  1407 		if (x > PIPageEditor.currentPageEditor().getMaxEndTime() * 1000) {
  1339 			this.setToolTipText(null);
  1408 			this.setToolTipText(null);
  1340 			return;
  1409 			return;
  1341 		}
  1410 		}
  1342 
  1411 	
       
  1412 		if (y > this.getVisualSizeY() - MemTraceGraph.xLegendHeight) {
       
  1413 			if (isLibraryEventTrace) {
       
  1414 				final long xPoint = (long) (x + 0.5);
       
  1415 				if (!lockMouseToolTipResolver[0]) {
       
  1416 					// Resolve tool tip text in thread
       
  1417 					new Thread() {
       
  1418 						@Override
       
  1419 						public void run() {
       
  1420 							lockMouseToolTipResolver[0] = true;
       
  1421 							try {
       
  1422 								final ArrayList<MemSample> list = memTrace
       
  1423 										.getLibraryEventDataByTime(graphIndex,
       
  1424 												xPoint, (long) getScale());
       
  1425 								Display.getDefault().syncExec(new Runnable() {
       
  1426 									public void run() {
       
  1427 										if (list.isEmpty()) {
       
  1428 											setToolTipText(null);
       
  1429 										} else {
       
  1430 											final MemSample ms = list.get(list
       
  1431 													.size() - 1);										
       
  1432 											setToolTipText(getLibraryEventToolTipText(ms));											
       
  1433 										}
       
  1434 									}
       
  1435 								});
       
  1436 
       
  1437 							} finally {
       
  1438 								lockMouseToolTipResolver[0] = false;
       
  1439 							}
       
  1440 						}
       
  1441 					}.start();
       
  1442 				}			
       
  1443 			} else {
       
  1444 				this.setToolTipText(null);
       
  1445 			}
       
  1446 			return;
       
  1447 		}
       
  1448 	
  1343 		long chunkSize = 0;
  1449 		long chunkSize = 0;
  1344 		long stackHeapSize = 0;
  1450 		long stackHeapSize = 0;
  1345 		// long totalSize = 0;
       
  1346 		Entry<Long, Integer> entry;
       
  1347 		if (memTrace.getVersion() >= 202) {
  1451 		if (memTrace.getVersion() >= 202) {
  1348 			if (eventStackListY != null) {
  1452 			if (eventStackListY != null) {
  1349 				/*
       
  1350 				 * TODO entry = eventStackListY.floorEntry((long)x); if(entry !=
       
  1351 				 * null){ stackHeapSize = entry.getValue(); }
       
  1352 				 */
       
  1353 				Integer value = (Integer) MemTrace.getFloorEntryFromMap(
  1453 				Integer value = (Integer) MemTrace.getFloorEntryFromMap(
  1354 						(long) x, eventStackListY);
  1454 						(long) x, eventStackListY);
  1355 				if (value != null) {
  1455 				if (value != null) {
  1356 					stackHeapSize = value;
  1456 					stackHeapSize = value;
  1357 				}
  1457 				}
  1358 			}
  1458 			}
  1359 			if (eventChunkListY != null) {
  1459 			if (eventChunkListY != null) {
  1360 				/*
       
  1361 				 * TODO entry = eventChunkListY.floorEntry((long)x); if(entry !=
       
  1362 				 * null){ chunkSize = entry.getValue(); }
       
  1363 				 */
       
  1364 				Integer value = (Integer) MemTrace.getFloorEntryFromMap(
  1460 				Integer value = (Integer) MemTrace.getFloorEntryFromMap(
  1365 						(long) x, eventChunkListY);
  1461 						(long) x, eventChunkListY);
  1366 				if (value != null) {
  1462 				if (value != null) {
  1367 					chunkSize = value;
  1463 					chunkSize = value;
  1368 				}
  1464 				}
  1369 
  1465 
  1370 			}/*
  1466 			}
  1371 			 * if(stackHeapSize == null){ this.setToolTipText(null); return; }
       
  1372 			 */
       
  1373 		} else {
  1467 		} else {
  1374 			ArrayList<MemSample> samples = memTrace
  1468 			ArrayList<MemSample> samples = memTrace
  1375 					.getMemSampleDataByTime((long) x);
  1469 					.getMemSampleDataByTime((long) x);
  1376 
  1470 
  1377 			if (samples != null) {
  1471 			if (samples != null) {
  1408 					+ (stackHeapSize + 512) / 1024
  1502 					+ (stackHeapSize + 512) / 1024
  1409 					+ Messages.getString("MemTraceGraph.stackHeapTooltip2")); //$NON-NLS-1$
  1503 					+ Messages.getString("MemTraceGraph.stackHeapTooltip2")); //$NON-NLS-1$
  1410 		} else
  1504 		} else
  1411 			return;
  1505 			return;
  1412 
  1506 
       
  1507 	}
       
  1508 	
       
  1509 	private String getLibraryEventToolTipText(MemSample memSample) {
       
  1510 		String libraryName = getMemTrace().getLibraryNameString(
       
  1511 				memSample.thread.fullName);
       
  1512 		String process = getMemTrace().getProcessFromLibraryNameString(
       
  1513 				memSample.thread.fullName);
       
  1514 		if (memSample.stackSize != 0) {
       
  1515 			return MessageFormat.format(Messages
       
  1516 					.getString("MemTraceGraph.mouseToolTipLoaded"),
       
  1517 					libraryName, process, memKBFormat
       
  1518 							.format(((memSample.heapSize) + 512) / 1024),
       
  1519 					memSample.sampleNum);
       
  1520 		} else {
       
  1521 			return MessageFormat.format(Messages
       
  1522 					.getString("MemTraceGraph.mouseToolTipUnloaded"),
       
  1523 					libraryName, process, memKBFormat
       
  1524 							.format(((memSample.heapSize) + 512) / 1024),
       
  1525 					memSample.sampleNum);
       
  1526 		}
  1413 	}
  1527 	}
  1414 
  1528 
  1415 	public void setCurrentThreads(Hashtable<Integer, Integer> threadList) {
  1529 	public void setCurrentThreads(Hashtable<Integer, Integer> threadList) {
  1416 		this.threadList = threadList;
  1530 		this.threadList = threadList;
  1417 	}
  1531 	}
  1484 					* (1024 * 1024 * 1024);
  1598 					* (1024 * 1024 * 1024);
  1485 
  1599 
  1486 		return bytes;
  1600 		return bytes;
  1487 	}
  1601 	}
  1488 
  1602 
       
  1603 	/*
       
  1604 	 * (non-Javadoc)
       
  1605 	 * 
       
  1606 	 * @seecom.nokia.carbide.cpp.internal.pi.plugin.model.ITitleBarMenu#
       
  1607 	 * addTitleBarMenuItems()
       
  1608 	 */
       
  1609 	public Action[] addTitleBarMenuItems() {
       
  1610 
       
  1611 		// Create actions for Title Bar's drop-down list 
       
  1612 		
       
  1613 		ArrayList<Action> actionArrayList = new ArrayList<Action>();
       
  1614 
       
  1615 		// Action for showing only chunks
       
  1616 		Action actionShowChunk = new Action() {
       
  1617 			public void run() {
       
  1618 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1619 						"com.nokia.carbide.cpp.pi.memory.showChunk", true); //$NON-NLS-1$
       
  1620 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1621 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", false); //$NON-NLS-1$
       
  1622 
       
  1623 				for (int i = 0; i < 3; i++) {
       
  1624 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1625 							.getTraceGraph(i);
       
  1626 					graph.action("chunk_on"); //$NON-NLS-1$
       
  1627 				}
       
  1628 			}
       
  1629 		};
       
  1630 		actionShowChunk.setText(Messages.getString("MemoryPlugin.showChunks")); //$NON-NLS-1$
       
  1631 
       
  1632 		// Action for showing only heap/stack
       
  1633 		Action actionShowHeap = new Action() {
       
  1634 			public void run() {
       
  1635 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1636 						"com.nokia.carbide.cpp.pi.memory.showChunk", false); //$NON-NLS-1$
       
  1637 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1638 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", true); //$NON-NLS-1$
       
  1639 
       
  1640 				for (int i = 0; i < 3; i++) {
       
  1641 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1642 							.getTraceGraph(i);
       
  1643 					graph.action("heapstack_on"); //$NON-NLS-1$
       
  1644 				}
       
  1645 			}
       
  1646 		};
       
  1647 		actionShowHeap
       
  1648 				.setText(Messages.getString("MemoryPlugin.showHeapStack")); //$NON-NLS-1$
       
  1649 
       
  1650 		// Action for showing both heap/stack and chunks
       
  1651 		Action actionShowBothItem = new Action() {
       
  1652 			public void run() {
       
  1653 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1654 						"com.nokia.carbide.cpp.pi.memory.showChunk", true); //$NON-NLS-1$
       
  1655 				NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1656 						"com.nokia.carbide.cpp.pi.memory.showHeapStack", true); //$NON-NLS-1$
       
  1657 
       
  1658 				for (int i = 0; i < 3; i++) {
       
  1659 					MemTraceGraph graph = (MemTraceGraph) memTrace
       
  1660 							.getTraceGraph(i);
       
  1661 					graph.action("chunk_heapstack_on"); //$NON-NLS-1$
       
  1662 				}
       
  1663 			}
       
  1664 		};
       
  1665 		actionShowBothItem.setText(Messages.getString("MemoryPlugin.showAll")); //$NON-NLS-1$
       
  1666 
       
  1667 		actionArrayList.add(actionShowChunk);
       
  1668 		actionArrayList.add(actionShowHeap);
       
  1669 		actionArrayList.add(actionShowBothItem);
       
  1670 
       
  1671 		// check which drawing mode is selected and set its action's state to
       
  1672 		// checked
       
  1673 		boolean showChunk = isShowChunkEnabled();
       
  1674 		boolean showHeapStack = isShowHeapStackEnabled();
       
  1675 
       
  1676 		if (showChunk && !showHeapStack) {
       
  1677 			actionShowChunk.setChecked(true);
       
  1678 		} else if (showHeapStack && !showChunk) {
       
  1679 			actionShowHeap.setChecked(true);
       
  1680 		} else {
       
  1681 			actionShowBothItem.setChecked(true);
       
  1682 		}
       
  1683 
       
  1684 		return actionArrayList.toArray(new Action[actionArrayList.size()]);
       
  1685 	}
       
  1686 	
       
  1687 	/* (non-Javadoc)
       
  1688 	 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITitleBarMenu#getContextHelpId()
       
  1689 	 */
       
  1690 	public String getContextHelpId() {
       
  1691 		return MemoryPlugin.HELP_CONTEXT_ID_MAIN_PAGE;
       
  1692 	}
       
  1693 
       
  1694 	/**
       
  1695 	 * Function for checking if chunk view is enabled
       
  1696 	 * 
       
  1697 	 * @return boolean value that is true when chunk view is enabled
       
  1698 	 */
       
  1699 
       
  1700 	private boolean isShowChunkEnabled() {
       
  1701 		// if there is a showChunk value associated with the current Analyser
       
  1702 		// tab, then use it
       
  1703 		Object obj = NpiInstanceRepository.getInstance()
       
  1704 				.activeUidGetPersistState(
       
  1705 						"com.nokia.carbide.cpp.pi.memory.showChunk"); //$NON-NLS-1$
       
  1706 		if ((obj != null) && (obj instanceof Boolean))
       
  1707 			// retrieve the current value
       
  1708 			return true;
       
  1709 		else
       
  1710 			// set the initial value
       
  1711 			NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1712 					"com.nokia.carbide.cpp.pi.memory.showChunk", true); //$NON-NLS-1$
       
  1713 		return false;
       
  1714 	}
       
  1715 
       
  1716 	/**
       
  1717 	 * Function for checking if stack/heap view is enabled
       
  1718 	 * 
       
  1719 	 * @return boolean value that is true when stack/heap view is enabled
       
  1720 	 */
       
  1721 	private boolean isShowHeapStackEnabled() {
       
  1722 		// if there is a showHeapStack value associated with the current
       
  1723 		// Analyser tab, then use it
       
  1724 		Object obj = NpiInstanceRepository.getInstance()
       
  1725 				.activeUidGetPersistState(
       
  1726 						"com.nokia.carbide.cpp.pi.memory.showHeapStack"); //$NON-NLS-1$
       
  1727 		if ((obj != null) && (obj instanceof Boolean))
       
  1728 			// retrieve the current value
       
  1729 			return true;
       
  1730 		else
       
  1731 			// set the initial value
       
  1732 			NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
  1733 					"com.nokia.carbide.cpp.pi.memory.showHeapStack", true); //$NON-NLS-1$
       
  1734 		return false;
       
  1735 	}
       
  1736 	
       
  1737 	/*
       
  1738 	 * (non-Javadoc)
       
  1739 	 * @see com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph#setLegendTableVisible(boolean)
       
  1740 	 */
       
  1741 	public void graphVisibilityChanged(boolean value){
       
  1742 		if(holder != null){
       
  1743 			holder.setVisible(value);
       
  1744 			holder.getParent().layout();
       
  1745 		}
       
  1746 	}
       
  1747 	
       
  1748 	/*
       
  1749 	 * (non-Javadoc)
       
  1750 	 * @see com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph#setLegendTableMaximized(boolean)
       
  1751 	 */
       
  1752 	public void graphMaximized(boolean value){
       
  1753 		if(holder != null){
       
  1754 			if(holder.getParent().getClass() == SashForm.class){
       
  1755 				SashForm sashForm = (SashForm)holder.getParent();
       
  1756 				if(value){
       
  1757 					sashForm.setMaximizedControl(holder);
       
  1758 				}
       
  1759 				else{
       
  1760 					sashForm.setMaximizedControl(null);
       
  1761 
       
  1762 				}
       
  1763 			}
       
  1764 			
       
  1765 		}
       
  1766 	}
       
  1767 	
       
  1768 	/*
       
  1769 	 * (non-Javadoc)
       
  1770 	 * @see com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph#isGraphMinimizedWhenOpened()
       
  1771 	 */
       
  1772 	public boolean isGraphMinimizedWhenOpened(){
       
  1773 		// Memory Graph is shown when view is opened
       
  1774 		return false;
       
  1775 	}
       
  1776 
       
  1777 	/* (non-Javadoc)
       
  1778 	 * @see com.nokia.carbide.cpp.pi.visual.IGenericTraceGraph#getTitle()
       
  1779 	 */
       
  1780 	@Override
       
  1781 	public String getTitle() {
       
  1782 		return Messages.getString("MemoryPlugin.pluginTitle"); //$NON-NLS-1$
       
  1783 	}	
  1489 }
  1784 }