| 1 |
/* Copyright (C) 2022-2025 Free Software Foundation |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License as published by |
| 5 |
the Free Software Foundation, either version 3 of the License, or |
| 6 |
(at your option) any later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program. If not, see <http://www.gnu.org/licenses>. */ |
| 15 |
|
| 16 |
package org.gprofng.mpmt.timeline.events; |
| 17 |
|
| 18 |
import org.gprofng.mpmt.AnDouble; |
| 19 |
import org.gprofng.mpmt.AnInteger; |
| 20 |
import org.gprofng.mpmt.AnLocale; |
| 21 |
import org.gprofng.mpmt.statecolors.StackState; |
| 22 |
import org.gprofng.mpmt.timeline2.TimelineVariable; |
| 23 |
import java.awt.Color; |
| 24 |
import java.util.List; |
| 25 |
import javax.swing.*; |
| 26 |
|
| 27 |
public class Sample extends EventDetail implements DurationEvent { |
| 28 |
private static final double DIV = 1000000000.0; |
| 29 |
private static ImageIcon[] allIcons; |
| 30 |
private static Object allIconsLock = new Object(); |
| 31 |
private static String[] allLabels; |
| 32 |
private static Object allLabelsLock = new Object(); |
| 33 |
|
| 34 |
private static final String[] LABELS = { |
| 35 |
AnLocale.getString("Process:"), // NOI18N |
| 36 |
AnLocale.getString("Sample Number:"), // NOI18N |
| 37 |
AnLocale.getString("Sample Start Label:"), // NOI18N |
| 38 |
AnLocale.getString("Sample End Label:"), // NOI18N |
| 39 |
AnLocale.getString("Start Time (sec.):"), // NOI18N |
| 40 |
AnLocale.getString("End Time (sec.):"), // NOI18N |
| 41 |
AnLocale.getString("Duration (sec.):"), // NOI18N |
| 42 |
}; |
| 43 |
// private final static char[] MNEMONICS = { |
| 44 |
// AnLocale.getString('E', "MNEM_SAMPLE_EXPERIMENT_NAME"), // NOI18N |
| 45 |
// AnLocale.getString('m', "MNEM_SAMPLE_SAMPLE_NUMBER"), // NOI18N |
| 46 |
// AnLocale.getString('L', "MNEM_SAMPLE_SAMPLE_START_LABEL"), // NOI18N |
| 47 |
// AnLocale.getString('b', "MNEM_SAMPLE_SAMPLE_END_LABEL"), // NOI18N |
| 48 |
// AnLocale.getString('a', "MNEM_SAMPLE_START_TIME"), // NOI18N |
| 49 |
// AnLocale.getString('n', "MNEM_SAMPLE_END_TIME"), // NOI18N |
| 50 |
// AnLocale.getString('D', "MNEM_SAMPLE_DURATION"), // NOI18N |
| 51 |
// }; |
| 52 |
|
| 53 |
// passed to constructor |
| 54 |
private final int number; |
| 55 |
private final String start_label, end_label; |
| 56 |
private final long duration; // in nanosec |
| 57 |
private final long total; // resource usage in nanosec |
| 58 |
private final long[] mstates; // resource usage in nanosec |
| 59 |
private final String expname; |
| 60 |
private final String[] eventSpecificInfo; |
| 61 |
private final String[] eventSpecificLabels; |
| 62 |
|
| 63 |
// Constructor |
| 64 |
public Sample( |
| 65 |
int number, |
| 66 |
String start_label, |
| 67 |
String end_label, |
| 68 |
long start_time, |
| 69 |
long end_time, |
| 70 |
long total, |
| 71 |
long[] mstates, |
| 72 |
String expname, |
| 73 |
long time_adjust) { |
| 74 |
super(end_time, time_adjust); // event timestamps are end times, not start times |
| 75 |
|
| 76 |
this.number = number; |
| 77 |
this.start_label = start_label; |
| 78 |
this.end_label = end_label; |
| 79 |
this.duration = end_time - start_time; |
| 80 |
this.total = total; |
| 81 |
this.mstates = mstates; |
| 82 |
this.expname = expname; |
| 83 |
this.eventSpecificInfo = initEventSpecificInfo(); |
| 84 |
this.eventSpecificLabels = initEventSpecificLabels(); |
| 85 |
} |
| 86 |
|
| 87 |
public long getStack() { |
| 88 |
return DetailsIPC.INVALID_STACK_ID; |
| 89 |
} |
| 90 |
|
| 91 |
public final List<StackState> getStackStates() { |
| 92 |
return null; |
| 93 |
} |
| 94 |
|
| 95 |
public String getStartLabel() { |
| 96 |
return start_label; |
| 97 |
} |
| 98 |
|
| 99 |
public String getEndLabel() { |
| 100 |
return end_label; |
| 101 |
} |
| 102 |
|
| 103 |
public long getTotalTime() { |
| 104 |
return total; |
| 105 |
} |
| 106 |
|
| 107 |
public long getDuration() { |
| 108 |
return duration; |
| 109 |
} |
| 110 |
|
| 111 |
public Object getData() { |
| 112 |
return mstates; |
| 113 |
} |
| 114 |
|
| 115 |
public long[] getMStates() { |
| 116 |
return mstates; |
| 117 |
} |
| 118 |
|
| 119 |
public String[] getEventSpecificLabels() { |
| 120 |
String[] rc = this.eventSpecificLabels.clone(); |
| 121 |
return rc; |
| 122 |
} |
| 123 |
|
| 124 |
private String[] initEventSpecificLabels() { |
| 125 |
synchronized (allLabelsLock) { |
| 126 |
if (allLabels == null) { |
| 127 |
int idx = 0; |
| 128 |
allLabels = new String[LABELS.length + TimelineVariable.NUM_SOLARIS_MSTATES]; |
| 129 |
for (int ii = 0; ii < LABELS.length; ii++) { |
| 130 |
allLabels[idx++] = LABELS[ii]; |
| 131 |
} |
| 132 |
for (int ii = 0; ii < TimelineVariable.NUM_SOLARIS_MSTATES; ii++) { |
| 133 |
allLabels[idx++] = TimelineVariable.mstate_info.getNameByDisplayIdx(ii); |
| 134 |
} |
| 135 |
} |
| 136 |
return allLabels; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
public String[] getEventSpecificInfo() { |
| 141 |
String[] rc = eventSpecificInfo.clone(); |
| 142 |
return rc; |
| 143 |
} |
| 144 |
|
| 145 |
private String[] initEventSpecificInfo() { |
| 146 |
String[] strings; |
| 147 |
strings = new String[LABELS.length + TimelineVariable.NUM_SOLARIS_MSTATES]; |
| 148 |
strings[0] = expname; |
| 149 |
strings[1] = new AnInteger(number).toString(); |
| 150 |
strings[2] = start_label; |
| 151 |
strings[3] = end_label; |
| 152 |
strings[4] = TimelineVariable.strTimestamp(super.getTimestamp() - duration); |
| 153 |
strings[5] = TimelineVariable.strTimestamp(super.getTimestamp()); |
| 154 |
strings[6] = TimelineVariable.strTimestamp(duration); |
| 155 |
// int numLabels = LABELS.length + TimelineVariable.NUM_SOLARIS_MSTATES; |
| 156 |
for (int ii = 0; ii < mstates.length; ii++) { |
| 157 |
int idx = TimelineVariable.mstate_info.getDisplayIdx(ii); |
| 158 |
if (idx >= 0 && idx < TimelineVariable.NUM_SOLARIS_MSTATES) { |
| 159 |
double time = mstates[ii]; |
| 160 |
double percent = total == 0 ? total : (time / total) * 100; |
| 161 |
int labelIdx = LABELS.length + idx; // numLabels-1-idx; |
| 162 |
strings[labelIdx] = new AnDouble(time / DIV).toPercentQuote(percent); |
| 163 |
} else { |
| 164 |
; // unexpected |
| 165 |
} |
| 166 |
} |
| 167 |
return strings; |
| 168 |
} |
| 169 |
|
| 170 |
public ImageIcon[] getEventSpecificIcons() { |
| 171 |
synchronized (allIconsLock) { |
| 172 |
if (allIcons == null) { |
| 173 |
allIcons = new ImageIcon[LABELS.length + TimelineVariable.NUM_SOLARIS_MSTATES]; |
| 174 |
int idx = LABELS.length; |
| 175 |
for (int ii = 0; ii < TimelineVariable.NUM_SOLARIS_MSTATES; ii++) { |
| 176 |
Color c = TimelineVariable.mstate_info.getColorByDisplayIdx(ii); |
| 177 |
allIcons[idx++] = new ImageIcon(StackState.createIcon(c)); |
| 178 |
} |
| 179 |
} |
| 180 |
return allIcons; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
// public char[] getEventSpecificMnemonics() { |
| 185 |
// return MNEMONICS; |
| 186 |
// } |
| 187 |
} |