Skip to content

Commit 2de679f

Browse files
committed
GH-482 ProfilerRuntimeCPU.MAX_STRING_LENGTH can be changed in JDBC settings UI
1 parent 9687d03 commit 2de679f

File tree

18 files changed

+138
-15
lines changed

18 files changed

+138
-15
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.graalvm.visualvm.lib.common/2
33
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/lib/common/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 2.8
4+
OpenIDE-Module-Specification-Version: 2.9
55
OpenIDE-Module-Needs: org.graalvm.visualvm.lib.common.Profiler
66

visualvm/libs.profiler/lib.profiler.common/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ questions.
3636
<compile-dependency/>
3737
<run-dependency>
3838
<release-version>2</release-version>
39-
<specification-version>2.15</specification-version>
39+
<specification-version>2.16</specification-version>
4040
</run-dependency>
4141
</dependency>
4242
<dependency>

visualvm/libs.profiler/lib.profiler.common/src/org/graalvm/visualvm/lib/common/ProfilingSettings.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class ProfilingSettings {
8888
public static final String PROP_INSTRUMENT_METHOD_INVOKE = "profiler.settings.instrument.method.invoke"; //NOI18N
8989
public static final String PROP_INSTRUMENT_SPAWNED_THREADS = "profiler.settings.instrument.spawned.threads"; //NOI18N
9090
public static final String PROP_N_PROFILED_THREADS_LIMIT = "profiler.settings.n.profiled.threads.limit"; //NOI18N
91+
public static final String PROP_MAX_STRING_LENGTH = "profiler.settings.max.string.length"; //NOI18N
9192
public static final String PROP_STACK_DEPTH_LIMIT = "profiler.settings.stack.depth.limit"; //NOI18N
9293
public static final String PROP_SORT_RESULTS_BY_THREAD_CPU_TIME = "profiler.settings.sort.results.by.thread.cpu.time"; //NOI18N
9394
public static final String PROP_SAMPLING_INTERVAL = "profiler.settings.sampling.interval"; //NOI18N
@@ -150,6 +151,7 @@ public class ProfilingSettings {
150151
private int codeRegionCPUResBufSize = 1000;
151152
private int cpuProfilingType = CommonConstants.CPU_INSTR_FULL;
152153
private int instrScheme = CommonConstants.INSTRSCHEME_LAZY;
154+
private int maxStringLength = CommonConstants.MAX_STRING_LENGTH_DEFAULT;
153155
private int nProfiledThreadsLimit = 32;
154156
private int stackDepthLimit = Integer.MAX_VALUE;
155157
private int profilingType = PROFILE_MONITOR;
@@ -405,6 +407,14 @@ public int getNProfiledThreadsLimit() {
405407
return nProfiledThreadsLimit;
406408
}
407409

410+
public void setMaxStringLength(int maxLength) {
411+
maxStringLength = maxLength;
412+
}
413+
414+
public int getMaxStringLength() {
415+
return maxStringLength;
416+
}
417+
408418
public void setStackDepthLimit(int num) {
409419
stackDepthLimit = num;
410420
}
@@ -575,6 +585,7 @@ public void applySettings(final ProfilerEngineSettings settings) {
575585
settings.setNProfiledThreadsLimit(Integer.MAX_VALUE); // zero or negative value means we do not limit it, just remember value for the UI
576586
}
577587

588+
settings.setMaxStringLength(getMaxStringLength());
578589
settings.setStackDepthLimit(getStackDepthLimit());
579590
settings.setSortResultsByThreadCPUTime(getSortResultsByThreadCPUTime());
580591

@@ -632,6 +643,7 @@ public void copySettingsInto(final ProfilingSettings settings) {
632643
settings.setInstrumentMethodInvoke(getInstrumentMethodInvoke());
633644
settings.setInstrumentSpawnedThreads(getInstrumentSpawnedThreads());
634645
settings.setNProfiledThreadsLimit(getNProfiledThreadsLimit());
646+
settings.setMaxStringLength(getMaxStringLength());
635647
settings.setStackDepthLimit(getStackDepthLimit());
636648
settings.setSortResultsByThreadCPUTime(getSortResultsByThreadCPUTime());
637649

@@ -693,6 +705,8 @@ public String debug() {
693705
sb.append('\n'); //NOI18N
694706
sb.append("nProfiledThreadsLimit: ").append(getNProfiledThreadsLimit()); //NOI18N
695707
sb.append('\n'); //NOI18N
708+
sb.append("maxStringLength: ").append(getMaxStringLength()); //NOI18N
709+
sb.append('\n'); //NOI18N
696710
sb.append("stackDepthLimit: ").append(getStackDepthLimit()); //NOI18N
697711
sb.append('\n'); //NOI18N
698712
sb.append("sortResultsByThreadCPUTime: ").append(getSortResultsByThreadCPUTime()); //NOI18N
@@ -764,6 +778,7 @@ public void load(final Map props, final String prefix) {
764778
setInstrumentSpawnedThreads(Boolean.valueOf(getProperty(props, prefix + PROP_INSTRUMENT_SPAWNED_THREADS, "false"))
765779
.booleanValue()); //NOI18N
766780
setNProfiledThreadsLimit(Integer.parseInt(getProperty(props, prefix + PROP_N_PROFILED_THREADS_LIMIT, "32"))); //NOI18N
781+
setMaxStringLength(Integer.parseInt(getProperty(props, prefix + PROP_MAX_STRING_LENGTH, Integer.toString(CommonConstants.MAX_STRING_LENGTH_DEFAULT))));
767782
setStackDepthLimit(Integer.parseInt(getProperty(props, prefix + PROP_STACK_DEPTH_LIMIT, String.valueOf(Integer.MAX_VALUE))));
768783
setSortResultsByThreadCPUTime(Boolean.valueOf(getProperty(props, prefix + PROP_SORT_RESULTS_BY_THREAD_CPU_TIME, "false"))
769784
.booleanValue()); //NOI18N
@@ -882,6 +897,7 @@ public void store(final Map props, final String prefix) {
882897
props.put(prefix + PROP_INSTRUMENT_METHOD_INVOKE, Boolean.toString(getInstrumentMethodInvoke()));
883898
props.put(prefix + PROP_INSTRUMENT_SPAWNED_THREADS, Boolean.toString(getInstrumentSpawnedThreads()));
884899
props.put(prefix + PROP_N_PROFILED_THREADS_LIMIT, Integer.toString(getNProfiledThreadsLimit()));
900+
props.put(prefix + PROP_MAX_STRING_LENGTH, Integer.toString(getMaxStringLength()));
885901
props.put(prefix + PROP_STACK_DEPTH_LIMIT, Integer.toString(getStackDepthLimit()));
886902
props.put(prefix + PROP_SORT_RESULTS_BY_THREAD_CPU_TIME, Boolean.toString(getSortResultsByThreadCPUTime()));
887903
props.put(prefix + PROP_SAMPLING_FREQUENCY, Integer.toString(getSamplingFrequency()));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.graalvm.visualvm.lib.jfluid/2
33
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/lib/jfluid/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 2.15
4+
OpenIDE-Module-Specification-Version: 2.16
55

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/ProfilerClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ public void sendSetInstrumentationParamsCmd(boolean changeableOnly)
12251225
throws ClientUtils.TargetAppOrVMTerminated {
12261226
SetChangeableInstrParamsCommand cmd = new SetChangeableInstrParamsCommand(settings.isLockContentionMonitoringEnabled(),
12271227
settings.getNProfiledThreadsLimit(),
1228+
settings.getMaxStringLength(),
12281229
settings.getStackDepthLimit(),
12291230
settings.getSamplingInterval(),
12301231
settings.getAllocTrackEvery(),

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/ProfilerEngineSettings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public final class ProfilerEngineSettings implements CommonConstants, Cloneable
8888
private boolean lockContentionMonitoringEnabled;
8989
private boolean threadsSamplingEnabled;
9090
private int allocStackTraceLimit = -5; // Negative number means full (unlimited) depth actually used, although the limit is preserved
91+
private int maxStringLength = MAX_STRING_LENGTH_DEFAULT;
9192
private int allocTrackEvery = 10;
9293
private int architecture; // system architecture 32bit/64bit
9394
private int codeRegionCPUResBufSize = 1000;
@@ -277,6 +278,16 @@ public int getNProfiledThreadsLimit() {
277278
return nProfiledThreadsLimit;
278279
}
279280

281+
public void setMaxStringLength(int maxLength) {
282+
if (maxLength > MAX_STRING_LENGTH_TOP_LIMIT)
283+
throw new IllegalArgumentException(maxLength+" is over top limit "+MAX_STRING_LENGTH_TOP_LIMIT); // NOI18N
284+
maxStringLength = maxLength;
285+
}
286+
287+
public int getMaxStringLength() {
288+
return maxStringLength;
289+
}
290+
280291
public void setStackDepthLimit(int num) {
281292
stackDepthLimit = num;
282293
}

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/global/CommonConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public interface CommonConstants {
122122

123123
/** Size of the event buffer, used to store/read rough profiling data */
124124
public static final int EVENT_BUFFER_SIZE_IN_BYTES = 1200000;
125+
/** Default for max string size (in chars) sent as value of parameter from TA */
126+
public static final int MAX_STRING_LENGTH_DEFAULT = 1024;
127+
/** Max limit for MAX_STRING_LENGTH_DEFAULT */
128+
public static final int MAX_STRING_LENGTH_TOP_LIMIT = 4200;
125129

126130
// Codes of various profiling events, that are generated and stored in the buffer file by server and
127131
// then retrieved by tool
@@ -319,5 +323,6 @@ public interface CommonConstants {
319323
public static final int AGENT_VERSION_90 = 18;
320324
public static final int AGENT_VERSION_VISUALVM_20 = 19;
321325
public static final int AGENT_VERSION_VISUALVM_206 = 20;
322-
public static final int CURRENT_AGENT_VERSION = AGENT_VERSION_VISUALVM_206;
326+
public static final int AGENT_VERSION_VISUALVM_218 = 21;
327+
public static final int CURRENT_AGENT_VERSION = AGENT_VERSION_VISUALVM_218;
323328
}

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ProfilerRuntimeCPU.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ProfilerRuntimeCPU extends ProfilerRuntime {
4242
//~ Static fields/initializers -----------------------------------------------------------------------------------------------
4343

4444
private static final boolean DEBUG = false;
45-
private static final int MAX_STRING_LENGTH = 2048;
45+
private static int maxStringLength = MAX_STRING_LENGTH_DEFAULT; // in chars
4646
static final Object NO_RET_VALUE = new Object();
4747
private static int nProfiledThreadsLimit;
4848
protected static int nProfiledThreadsAllowed;
@@ -94,6 +94,10 @@ public static void setNProfiledThreadsLimit(int num) {
9494
nProfiledThreadsLimit = nProfiledThreadsAllowed = num;
9595
}
9696

97+
public static void setMaxStringLength(int maxLength) {
98+
maxStringLength = maxLength;
99+
}
100+
97101
public static void setStackDepthLimit(int num) {
98102
stackDepthLimit = num;
99103
}
@@ -784,12 +788,12 @@ static String convertToString(Object o) {
784788
}
785789

786790
private static int truncatedByteLength(String s) {
787-
int length = s.length()*2;
791+
int length = s.length();
788792

789-
if (length < MAX_STRING_LENGTH) {
790-
return length;
793+
if (length < maxStringLength) {
794+
return length*2;
791795
}
792-
return MAX_STRING_LENGTH;
796+
return maxStringLength*2;
793797
}
794798

795799
private static String getObjectId(Object o, String clazz) {

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ProfilerServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ public void run() {
14581458
lockContentionMonitoring = scipCmd.isLockContentionMonitoringEnabled();
14591459
ProfilerRuntime.setLockContentionMonitoringEnabled(lockContentionMonitoring);
14601460
ProfilerRuntimeCPU.setNProfiledThreadsLimit(scipCmd.getNProfiledThreadsLimit());
1461+
ProfilerRuntimeCPU.setMaxStringLength(scipCmd.getMaxStringLength());
14611462
ProfilerRuntimeCPU.setStackDepthLimit(scipCmd.getStackDepthLimit());
14621463
ProfilerRuntimeCPUSampledInstr.setSamplingInterval(scipCmd.getSamplingInterval());
14631464
ProfilerRuntimeSampler.setSamplngFrequency(scipCmd.getThreadsSamplingFrequency());

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/wireprotocol/SetChangeableInstrParamsCommand.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class SetChangeableInstrParamsCommand extends Command {
4747
private boolean threadsSamplingEnabled;
4848
private boolean lockContentionMonitoringEnabled;
4949
private int nProfiledThreadsLimit;
50+
private int maxStringLength;
5051
private int stackDepthLimit;
5152
private int objAllocStackSamplingDepth;
5253
private int objAllocStackSamplingInterval;
@@ -55,14 +56,16 @@ public class SetChangeableInstrParamsCommand extends Command {
5556

5657
//~ Constructors -------------------------------------------------------------------------------------------------------------
5758

58-
public SetChangeableInstrParamsCommand(boolean lockContentionMonitoringEnabled, int nProfiledThreadsLimit, int stackDepthLimit,
59+
public SetChangeableInstrParamsCommand(boolean lockContentionMonitoringEnabled, int nProfiledThreadsLimit,
60+
int maxStringLength, int stackDepthLimit,
5961
int samplingInterval, int objAllocStackSamplingInterval,
6062
int objAllocStackSamplingDepth, boolean runGCOnGetResults,
6163
boolean waitTrackingEnabled, boolean sleepTrackingEnabled,
6264
boolean threadsSamplingEnabled, int threadsSamplingFrequency) {
6365
super(SET_CHANGEABLE_INSTR_PARAMS);
6466
this.lockContentionMonitoringEnabled = lockContentionMonitoringEnabled;
6567
this.nProfiledThreadsLimit = nProfiledThreadsLimit;
68+
this.maxStringLength = maxStringLength;
6669
this.stackDepthLimit = stackDepthLimit;
6770
this.samplingInterval = samplingInterval;
6871
this.threadsSamplingFrequency = threadsSamplingFrequency;
@@ -89,6 +92,10 @@ public int getNProfiledThreadsLimit() {
8992
return nProfiledThreadsLimit;
9093
}
9194

95+
public int getMaxStringLength() {
96+
return maxStringLength;
97+
}
98+
9299
public int getStackDepthLimit() {
93100
return stackDepthLimit;
94101
}
@@ -129,6 +136,7 @@ public boolean isThreadsSamplingEnabled() {
129136
public String toString() {
130137
return super.toString() + ", lockContentionMonitoringEnabled: " + lockContentionMonitoringEnabled // NOI18N
131138
+ ", nProfiledThreadsLimit: " + nProfiledThreadsLimit // NOI18N
139+
+ ", maxStringLength: " + maxStringLength // NOI18N
132140
+ ", stackDepthLimit: " + stackDepthLimit // NOI18N
133141
+ ", samplingInterval: " + samplingInterval // NOI18N
134142
+ ", objAllocStackSamplingInterval: " + objAllocStackSamplingInterval // NOI18N
@@ -143,6 +151,7 @@ public String toString() {
143151
void readObject(ObjectInputStream in) throws IOException {
144152
lockContentionMonitoringEnabled = in.readBoolean();
145153
nProfiledThreadsLimit = in.readInt();
154+
maxStringLength = in.readInt();
146155
stackDepthLimit = in.readInt();
147156
samplingInterval = in.readInt();
148157
objAllocStackSamplingInterval = in.readInt();
@@ -157,6 +166,7 @@ void readObject(ObjectInputStream in) throws IOException {
157166
void writeObject(ObjectOutputStream out) throws IOException {
158167
out.writeBoolean(lockContentionMonitoringEnabled);
159168
out.writeInt(nProfiledThreadsLimit);
169+
out.writeInt(maxStringLength);
160170
out.writeInt(stackDepthLimit);
161171
out.writeInt(samplingInterval);
162172
out.writeInt(objAllocStackSamplingInterval);

0 commit comments

Comments
 (0)