/
CpuUsageEntryModel.java
123 lines (111 loc) · 3.72 KB
/
CpuUsageEntryModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**********************************************************************
* Copyright (c) 2017, 2018 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.analysis.os.linux.core.cpuusage;
import java.util.List;
import java.util.Objects;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.os.linux.core.model.OsStrings;
import org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider;
import org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver;
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
/**
* Entry Model to represent entries for the {@link CpuUsageDataProvider}.
*
* @author Loic Prieur-Drevon
* @since 2.4
*/
public class CpuUsageEntryModel extends TmfTreeDataModel implements ICoreElementResolver {
private final int fTid;
private final long fTime;
private final Multimap<String, Object> fMetadata;
/**
* Constructor
*
* @param id
* the new entry's unique ID
* @param parentId
* the entry's parent ID
* @param tid
* The TID of the process
* @param processName
* The process's name
* @param time
* The total amount of time spent on CPU
*/
public CpuUsageEntryModel(long id, long parentId, String processName, int tid, long time) {
this(id, parentId, ImmutableList.of(processName, String.valueOf(tid), String.valueOf(0L), String.valueOf(time)), tid, time);
}
/**
* Constructor
*
* @param id
* the new entry's unique ID
* @param parentId
* the entry's parent ID
* @param tid
* The TID of the process
* @param labels
* The process's labels, in order, name, tid, percent usage and
* formatted time
* @param time
* The total amount of time spent on CPU
* @since 4.0
*/
public CpuUsageEntryModel(long id, long parentId, List<String> labels, int tid, long time) {
super(id, parentId, labels);
fTid = tid;
fTime = time;
Multimap<String, Object> map = HashMultimap.create();
map.put(OsStrings.tid(), tid);
fMetadata = map;
}
/**
* Get the process name thread represented by this entry
*
* @return The thread's TID
*/
public int getTid() {
return fTid;
}
/**
* Get the total time spent on CPU in the time interval represented by this
* entry.
*
* @return The total time spent on CPU
*/
public long getTime() {
return fTime;
}
@Override
public boolean equals(@Nullable Object obj) {
if (!super.equals(obj)) {
// reference equality, nullness, getName, ID and parent ID
return false;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
CpuUsageEntryModel other = (CpuUsageEntryModel) obj;
return fTid == other.fTid
&& fTime == other.fTime;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fTid, fTime);
}
@Override
public Multimap<String, Object> getMetadata() {
return fMetadata;
}
}