1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Definitions for the class FreeInfo |
14 * Description: Definitions for the class FreeInfo |
15 * |
15 * |
16 */ |
16 */ |
|
17 |
17 package com.nokia.s60tools.analyzetool.engine.statistic; |
18 package com.nokia.s60tools.analyzetool.engine.statistic; |
18 |
19 |
|
20 import java.util.Arrays; |
19 import java.util.Collection; |
21 import java.util.Collection; |
20 import java.util.Collections; |
22 import java.util.Collections; |
21 import java.util.HashSet; |
|
22 import java.util.Set; |
23 import java.util.Set; |
23 |
24 |
24 |
25 |
25 |
26 |
26 /** |
27 /** |
27 * Constains information of free |
28 * Constains information of free |
28 * @author kihe |
29 * @author kihe |
29 * |
30 * |
30 */ |
31 */ |
31 public class FreeInfo extends BaseInfo { |
32 public class FreeInfo extends BaseInfo { |
32 Set<AllocInfo> allocsFreed; |
33 |
|
34 /** |
|
35 * Constructor |
|
36 * @param memoryAddress memory address for this free |
|
37 */ |
|
38 public FreeInfo(String memoryAddress) { |
|
39 super(memoryAddress); |
|
40 } |
33 |
41 |
|
42 AllocInfo[] allocsFreedArr; |
|
43 |
34 /** |
44 /** |
35 * Adds an alloc which has been freed by this Free |
45 * Sets all AllocInfos which were freed by this free |
36 * @param alloc the alloc to add |
46 * @param allocs The AllocInfos to set |
37 */ |
47 */ |
38 public void addFreedAlloc(AllocInfo alloc){ |
48 public void setFreedAllocs(Set<AllocInfo> allocs){ |
39 if (allocsFreed == null){ |
49 allocsFreedArr = allocs.toArray(new AllocInfo[allocs.size()]); |
40 allocsFreed = new HashSet<AllocInfo>(); |
|
41 } |
|
42 allocsFreed.add(alloc); |
|
43 } |
50 } |
44 |
51 |
45 /** |
52 /** |
46 * Returns a collection of allocs freed by this Free |
53 * Returns a collection of allocs freed by this Free |
47 * @return the Collection of AllocInfos freed |
54 * @return the Collection of AllocInfos freed |
48 */ |
55 */ |
49 public Collection<AllocInfo> getFreedAllocs(){ |
56 public Collection<AllocInfo> getFreedAllocs(){ |
50 return Collections.unmodifiableSet(allocsFreed == null ? new HashSet<AllocInfo>() : allocsFreed); |
57 return allocsFreedArr == null ? Collections.<AllocInfo>emptyList() : Arrays.asList(allocsFreedArr); |
|
58 } |
|
59 |
|
60 @Override |
|
61 public String toString() { |
|
62 return String.format("FreeInfo [%s allocsFreedArr=[%s]]", super.toString(), allocsFreedArrToString()); |
|
63 } |
|
64 |
|
65 private String allocsFreedArrToString() { |
|
66 if (allocsFreedArr == null){ |
|
67 return "null"; |
|
68 } |
|
69 |
|
70 StringBuilder sb = new StringBuilder(); |
|
71 boolean addComma = false; |
|
72 for (AllocInfo allocInfo : allocsFreedArr) { |
|
73 if (addComma){ |
|
74 sb.append(", "); |
|
75 } |
|
76 addComma = true; |
|
77 sb.append(String.format("addr=0x%08X time=%s", allocInfo.getMemoryAddress(), allocInfo.getTime())); |
|
78 } |
|
79 return sb.toString(); |
51 } |
80 } |
52 |
81 |
53 } |
82 } |