1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng
.core
.latency
.analyzer
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
19 import java
.util
.Stack
;
21 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.Activator
;
22 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
25 * <b><u>StackWrapper</u></b>
29 * TODO Change the types of the HashMaps from <String,String> to <Integer,Integer>, in order to take advantage of the
30 * compilation-time String.hashCode() speedup over execution-time String hash computation.
32 * @author Philippe Sawicki
34 public class StackWrapper
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 * Hash map of event stacks.
43 private HashMap
<String
, Stack
<LttngEvent
>> fStacks
= null;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
52 public StackWrapper() {
53 fStacks
= new HashMap
<String
, Stack
<LttngEvent
>>();
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Adds an event to the list of events of the same type.
63 * The event to add to the list.
65 public void put(LttngEvent event
) {
66 String key
= event
.getMarkerName();
68 if (fStacks
.containsKey(key
)) {
69 fStacks
.get(key
).add(event
);
71 Stack
<LttngEvent
> newStack
= new Stack
<LttngEvent
>();
73 fStacks
.put(key
, newStack
);
78 * Checks if the stack contains a list of events of the given type.
80 * The type of events to check for.
81 * @return "true" if the stack contains events of the given type, "false" otherwise.
83 public boolean containsKey(String key
) {
84 return fStacks
.containsKey(key
);
88 * Returns the list of events of the given type.
90 * The type of events to return.
91 * @return The list of events of the given type, or null.
93 public Stack
<LttngEvent
> getStackOf(String key
) {
94 return fStacks
.get(key
);
98 * Removes the given event from the given stack list.
100 * The given stack type.
102 * The event to remove from the given stack type.
103 * @return "true" if the event was removed, "false" otherwise.
105 public boolean removeEvent(String key
, LttngEvent event
) {
106 Stack
<LttngEvent
> stack
= fStacks
.get(key
);
108 boolean removed
= false;
112 * TODO Correct this... Here, no matter what CPU or other content field, we always remove the last event
113 * added to the stack. Should be something like : return stack.remove(event);
117 } catch (Exception e
) {
118 Activator
.getDefault().logError("Error removing Event", e
); //$NON-NLS-1$
121 // Remove the stack from the stack list if it is empty
122 if (stack
.isEmpty()) {
130 * Clears the stack content.
132 public void clear() {
137 * Prints the content of the stack to the console.
139 @SuppressWarnings("nls")
140 public void printContent() {
141 Collection
<Stack
<LttngEvent
>> values
= fStacks
.values();
142 Iterator
<Stack
<LttngEvent
>> valueIt
= values
.iterator();
144 Set
<String
> keys
= fStacks
.keySet();
145 Iterator
<String
> keyIt
= keys
.iterator();
147 while (valueIt
.hasNext() && keyIt
.hasNext()) {
148 Stack
<LttngEvent
> stack
= valueIt
.next();
150 System
.out
.println(" " + keyIt
.next() + " [" + stack
.size() + "] : " + stack
);
This page took 0.035091 seconds and 5 git commands to generate.