Skip to content

Commit

Permalink
Fill printed with toString() objects with violet color
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaa4eb committed Oct 14, 2023
1 parent 5281cef commit e78d694
Show file tree
Hide file tree
Showing 34 changed files with 309 additions and 315 deletions.
20 changes: 10 additions & 10 deletions ulyp-agent-classes/src/main/java/com/ulyp/agent/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Settings {
public static final String EXCLUDE_RECORDING_METHODS_PROPERTY = "ulyp.exclude-methods";
public static final String START_RECORDING_METHODS_PROPERTY = "ulyp.methods";
public static final String START_RECORDING_THREADS_PROPERTY = "ulyp.threads";
public static final String PRINT_CLASSES_PROPERTY = "ulyp.print-classes";
public static final String PRINT_TYPES_PROPERTY = "ulyp.print";
public static final String FILE_PATH_PROPERTY = "ulyp.file";
public static final String INSTRUMENT_CONSTRUCTORS_PROPERTY = "ulyp.constructors";
public static final String INSTRUMENT_LAMBDAS_PROPERTY = "ulyp.lambdas";
Expand All @@ -52,7 +52,7 @@ public class Settings {
private final boolean instrumentTypeInitializers;
private final String startRecordingPolicyPropertyValue;
private final CollectionsRecordingMode collectionsRecordingMode;
private final Set<TypeMatcher> classesToPrint;
private final Set<TypeMatcher> typesToPrint;
private final String bindNetworkAddress;
private final boolean agentDisabled;

Expand All @@ -66,7 +66,7 @@ public Settings(
boolean instrumentLambdas,
boolean instrumentTypeInitializers,
CollectionsRecordingMode collectionsRecordingMode,
Set<TypeMatcher> classesToPrint,
Set<TypeMatcher> typesToPrint,
String startRecordingPolicyPropertyValue,
List<TypeMatcher> excludeFromInstrumentationClasses,
String bindNetworkAddress,
Expand All @@ -80,7 +80,7 @@ public Settings(
this.instrumentLambdas = instrumentLambdas;
this.instrumentTypeInitializers = instrumentTypeInitializers;
this.collectionsRecordingMode = collectionsRecordingMode;
this.classesToPrint = classesToPrint;
this.typesToPrint = typesToPrint;
this.startRecordingPolicyPropertyValue = startRecordingPolicyPropertyValue;
this.excludeFromInstrumentationClasses = excludeFromInstrumentationClasses;
this.bindNetworkAddress = bindNetworkAddress;
Expand Down Expand Up @@ -161,8 +161,8 @@ public String toString() {

boolean agentDisabled = System.getProperty(AGENT_DISABLED_PROPERTY) != null;

Set<TypeMatcher> classesToPrint =
CommaSeparatedList.parse(System.getProperty(PRINT_CLASSES_PROPERTY, ""))
Set<TypeMatcher> typesToPrint =
CommaSeparatedList.parse(System.getProperty(PRINT_TYPES_PROPERTY, ""))
.stream()
.map(TypeMatcher::parse)
.collect(Collectors.toSet());
Expand All @@ -177,7 +177,7 @@ public String toString() {
instrumentLambdas,
instrumentTypeInitializers,
collectionsRecordingMode,
classesToPrint,
typesToPrint,
startRecordingPolicy,
excludeClassesFromInstrumentation,
bindNetworkAddress,
Expand Down Expand Up @@ -228,8 +228,8 @@ public CollectionsRecordingMode getCollectionsRecordingMode() {
return collectionsRecordingMode;
}

public Set<TypeMatcher> getClassesToPrint() {
return classesToPrint;
public Set<TypeMatcher> getTypesToPrint() {
return typesToPrint;
}

public String getStartRecordingPolicyPropertyValue() {
Expand All @@ -255,6 +255,6 @@ public String toString() {
",\ninstrument lambdas: " + instrumentLambdas +
",\nrecording policy: " + startRecordingPolicyPropertyValue +
",\nrecord collections: " + collectionsRecordingMode +
",\nclassesToPrintWithToString(TBD)=" + classesToPrint;
",\ntypesToPrintWithToString(TBD)=" + typesToPrint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.agent.tests.util.ForkProcessBuilder;
import com.ulyp.core.recorders.IdentityObjectRecord;
import com.ulyp.core.recorders.PrintedObjectRecord;
import com.ulyp.core.recorders.StringObjectRecord;
import com.ulyp.storage.CallRecord;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -42,9 +41,9 @@ public void shouldPrintObjectIfSettingSet() {
assertThat(root.getReturnValue(), instanceOf(PrintedObjectRecord.class));

PrintedObjectRecord printed = (PrintedObjectRecord) root.getReturnValue();
StringObjectRecord value = printed.getPrinted();
String value = printed.getPrintedObject();

assertThat(value.value(), is("X{val=5}"));
assertThat(value, is("X{val=5}"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public List<String> toCmdJavaProps() {
params.add("-D" + Settings.EXCLUDE_CLASSES_PROPERTY + "=" + excludeClassesProperty);
}
if (printClasses != null) {
params.add("-D" + Settings.PRINT_CLASSES_PROPERTY + "=" + printClasses);
params.add("-D" + Settings.PRINT_TYPES_PROPERTY + "=" + printClasses);
}
if (agentDisabled != null && agentDisabled) {
params.add("-D" + Settings.AGENT_DISABLED_PROPERTY);
Expand Down
2 changes: 1 addition & 1 deletion ulyp-agent/src/main/java/com/ulyp/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void start(String args, Instrumentation instrumentation) {
mapRecorder.setMode(settings.getCollectionsRecordingMode());

ToStringPrintingRecorder toStringRecorder = (ToStringPrintingRecorder) (ObjectRecorderRegistry.TO_STRING_RECORDER.getInstance());
toStringRecorder.addClassesToPrint(settings.getClassesToPrint());
toStringRecorder.addClassesToPrint(settings.getTypesToPrint());

ElementMatcher.Junction<TypeDescription> ignoreMatcher = buildIgnoreMatcher(settings);
ElementMatcher.Junction<TypeDescription> instrumentationMatcher = buildInstrumentationMatcher(settings);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package com.ulyp.core.recorders;

import com.ulyp.core.Type;
import lombok.Getter;

@Getter
public class PrintedObjectRecord extends ObjectRecord {

private final StringObjectRecord printed;
private final String printedObject;
private final int identityHashCode;

protected PrintedObjectRecord(StringObjectRecord printed, Type type, int identityHashCode) {
protected PrintedObjectRecord(String printedObject, Type type, int identityHashCode) {
super(type);

this.printed = printed;
this.printedObject = printedObject;
this.identityHashCode = identityHashCode;
}

public StringObjectRecord getPrinted() {
return printed;
}

public int getIdentityHashCode() {
return identityHashCode;
}

@Override
public String toString() {
return printed.toString();
return printedObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ObjectRecord read(@NotNull Type objectType, BinaryInput input, ByIdTypeRe
int result = input.readInt();
if (result == TO_STRING_CALL_SUCCESS) {
int identityHashCode = input.readInt();
StringObjectRecord printed = (StringObjectRecord) input.readObject(typeResolver);
String printed = input.readString();
return new PrintedObjectRecord(printed, objectType, identityHashCode);
} else {
return ObjectRecorderRegistry.IDENTITY_RECORDER.getInstance().read(objectType, input, typeResolver);
Expand All @@ -56,7 +56,7 @@ public void write(Object object, BinaryOutput out, TypeResolver typeResolver) th
try (BinaryOutputAppender appender = out.appender()) {
appender.append(TO_STRING_CALL_SUCCESS);
appender.append(System.identityHashCode(object));
appender.append(printed, typeResolver);
appender.append(printed);
}
} catch (Throwable e) {
try (BinaryOutputAppender appender = out.appender()) {
Expand Down
44 changes: 9 additions & 35 deletions ulyp-ui/src/main/kotlin/com/ulyp/ui/SettingsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.ulyp.ui
import com.ulyp.ui.looknfeel.Theme
import com.ulyp.ui.looknfeel.ThemeManager
import com.ulyp.ui.settings.Settings
import com.ulyp.ui.settings.SimpleIntegerProperty
import com.ulyp.ui.util.connect
import javafx.beans.property.StringProperty
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.control.CheckBox
Expand Down Expand Up @@ -43,46 +46,17 @@ class SettingsView(
override fun initialize(url: URL, rb: ResourceBundle?) {

themeChoiceBox.items.addAll(Theme.values().map { it.name }.toList())
themeChoiceBox.selectionModel.select(settings.theme.get())
themeChoiceBox.setOnAction {
settings.theme.value = themeChoiceBox.selectionModel.selectedItem
}
themeChoiceBox.connect(settings.theme)

systemFontChoiceBox.items.addAll(Font.getFamilies())
systemFontChoiceBox.selectionModel.select(settings.systemFontName.value)
systemFontChoiceBox.setOnAction {
settings.systemFontName.value = systemFontChoiceBox.selectionModel.selectedItem
}
systemFontChoiceBox.connect(settings.systemFontName)

recordingTreeFontChoiceBox.items.addAll(Font.getFamilies())
recordingTreeFontChoiceBox.selectionModel.select(settings.recordingTreeFontName.value)
recordingTreeFontChoiceBox.setOnAction {
settings.recordingTreeFontName.value = recordingTreeFontChoiceBox.selectionModel.selectedItem
}
recordingTreeFontChoiceBox.connect(settings.recordingTreeFontName)

systemFontSizeLabel.text = settings.systemFontSize.value.toString()
systemFontSizeSlider.value = settings.systemFontSize.value.toDouble()
systemFontSizeSlider.valueProperty().addListener { _, _, newValue ->
systemFontSizeLabel.text = newValue.toString()
systemFontSizeSlider.value = newValue.toInt().toDouble()
settings.systemFontSize.value = newValue.toInt()
}

recordingTreeFontSizeLabel.text = settings.recordingTreeFontSize.value.toString()
recordingTreeFontSizeSlider.value = settings.recordingTreeFontSize.value.toDouble()
recordingTreeFontSizeSlider.valueProperty().addListener { _, _, newValue ->
recordingTreeFontSizeLabel.text = newValue.toString()
recordingTreeFontSizeSlider.value = newValue.toInt().toDouble()
settings.recordingTreeFontSize.value = newValue.toInt()
}

recordingTreeFontSpacingLabel.text = settings.recordingTreeFontSpacing.value.toString()
recordingTreeFontSpacingSlider.value = settings.recordingTreeFontSpacing.doubleValue()
recordingTreeFontSpacingSlider.valueProperty().addListener { _, _, newValue ->
recordingTreeFontSpacingLabel.text = newValue.toString()
recordingTreeFontSpacingSlider.value = newValue.toInt().toDouble()
settings.recordingTreeFontSpacing.value = newValue.toInt()
}
systemFontSizeSlider.connect(systemFontSizeLabel, settings.systemFontSize)
recordingTreeFontSizeSlider.connect(recordingTreeFontSizeLabel, settings.recordingTreeFontSize)
recordingTreeFontSpacingSlider.connect(recordingTreeFontSpacingLabel, settings.recordingTreeFontSpacing)

recordingListShowThreads.selectedProperty().bindBidirectional(settings.recordingListShowThreads)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.ulyp.ui.elements.recording.objects
import com.ulyp.ui.RenderSettings
import javafx.scene.text.Text

class NotRecordedObject(renderSettings: RenderSettings) : RecordedObjectView() {
class NotRecordedRenderedObject(renderSettings: RenderSettings) : RenderedObject() {

init {
children.add(if (renderSettings.showTypes) Text("Method has not yet returned any value: ?") else Text("?"))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.ulyp.ui.RenderSettings
import com.ulyp.ui.util.Style
import com.ulyp.ui.util.StyledText.of

class RecordedBooleanView(record: BooleanRecord, renderSettings: RenderSettings) : RecordedObjectView() {
class RenderedBoolean(record: BooleanRecord, renderSettings: RenderSettings) : RenderedObject() {

init {
if (renderSettings.showTypes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.ulyp.ui.elements.recording.objects

import com.ulyp.core.recorders.arrays.ByteArrayRecord
import com.ulyp.ui.util.Style
import com.ulyp.ui.util.StyledText.of

class RecordedByteArrayView(record: ByteArrayRecord) : RecordedObjectView() {

init {
children.addAll(
listOf(
of("byte", Style.CALL_TREE_TYPE_NAME),
of("[", Style.CALL_TREE_COLLECTION_BRACKET),
of(record.length.toString(), Style.CALL_TREE_TYPE_NAME),
of("]", Style.CALL_TREE_COLLECTION_BRACKET),
of("@", Style.CALL_TREE_IDENTITY, Style.SMALLER_TEXT),
of(Integer.toHexString(record.hashCode), Style.CALL_TREE_IDENTITY, Style.SMALLER_TEXT)
)
)
}
package com.ulyp.ui.elements.recording.objects

import com.ulyp.core.recorders.arrays.ByteArrayRecord
import com.ulyp.ui.util.Style
import com.ulyp.ui.util.StyledText.of

class RenderedByteArray(record: ByteArrayRecord) : RenderedObject() {

init {
children.addAll(
listOf(
of("byte", Style.CALL_TREE_TYPE_NAME),
of("[", Style.CALL_TREE_COLLECTION_BRACKET),
of(record.length.toString(), Style.CALL_TREE_TYPE_NAME),
of("]", Style.CALL_TREE_COLLECTION_BRACKET),
of("@", Style.CALL_TREE_IDENTITY, Style.SMALLER_TEXT),
of(Integer.toHexString(record.hashCode), Style.CALL_TREE_IDENTITY, Style.SMALLER_TEXT)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.ulyp.ui.util.StyledText
import com.ulyp.ui.util.TrimmedTextView
import javafx.scene.text.Text

class RecordedCharView internal constructor(value: CharRecord)
: RecordedObjectView() {
class RenderedChar internal constructor(value: CharRecord)
: RenderedObject() {

init {
val text: Text = TrimmedTextView(Text("'" + value.value + "'"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.ulyp.ui.util.StyledText.of
import com.ulyp.ui.util.TrimmedTextView
import javafx.scene.text.Text

class RecordedClassObjectView(record: ClassObjectRecord, renderSettings: RenderSettings) : RecordedObjectView() {
class RenderedClassObject(record: ClassObjectRecord, renderSettings: RenderSettings) : RenderedObject() {

init {
if (renderSettings.showTypes) {
Expand Down
Loading

0 comments on commit e78d694

Please sign in to comment.