Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface ITmfMarker {
/** Duration marker attribute. The format is the output of Long.toString(). */
String MARKER_DURATION = "duration"; //$NON-NLS-1$

/** Duration marker attribute. The format is the output of Long.toString(). */
String MARKER_FOREGROUND = "foreground"; //$NON-NLS-1$
}
3 changes: 2 additions & 1 deletion tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Require-Bundle: org.eclipse.core.expressions,
org.eclipse.tracecompass.tmf.filter.parser,
org.eclipse.e4.ui.css.swt.theme,
org.eclipse.ui.themes,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
json
Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.ui.model;x-internal:=true,
org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart;x-internal:=true,
org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets;x-friends:="org.eclipse.tracecompass.analysis.timing.ui",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Messages extends NLS {

public static String AddBookmarkDialog_Alpha;
public static String AddBookmarkDialog_Color;

public static String AddBookmarkDialog_Foreground;
public static String AddBookmarkDialog_Message;
public static String AddBookmarkDialog_Title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@

package org.eclipse.tracecompass.internal.tmf.ui.dialogs;


import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.RGBA;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
Expand All @@ -38,15 +42,18 @@ public class AddBookmarkDialog extends MultiLineInputDialog {
private ColorSelector fColorSelector;
private Scale fAlphaScale;
private Label fAlphaLabel;
private int fAlpha = 128;
private Button fForgroundButton;
private int fAlpha = 32;
private boolean fForeground;

/**
* Constructor
*
* @param parentShell
* the parent shell
* @param initialValue
* the initial input value, or <code>null</code> if none (equivalent to the empty string)
* the initial input value, or <code>null</code> if none
* (equivalent to the empty string)
*/
public AddBookmarkDialog(Shell parentShell, String initialValue) {
super(parentShell, Messages.AddBookmarkDialog_Title, Messages.AddBookmarkDialog_Message, initialValue);
Expand All @@ -56,17 +63,26 @@ public AddBookmarkDialog(Shell parentShell, String initialValue) {
protected Control createDialogArea(Composite parent) {
Composite areaComposite = (Composite) super.createDialogArea(parent);
Composite colorComposite = new Composite(areaComposite, SWT.NONE);
RowLayout layout = new RowLayout();
layout.center = true;
colorComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
GridLayout layout = new GridLayout(1, false);
colorComposite.setLayout(layout);
colorComposite.moveBelow(getText());
Label colorLabel = new Label(colorComposite, SWT.NONE);

Composite colorPicker = new Composite(colorComposite, SWT.NONE);
colorPicker.setLayout(new GridLayout(2, false));
Label colorLabel = new Label(colorPicker, SWT.NONE);
colorLabel.setText(Messages.AddBookmarkDialog_Color);
fColorSelector = new ColorSelector(colorComposite);
fColorSelector = new ColorSelector(colorPicker);
fColorSelector.setColorValue(new RGB(255, 0, 0));
Label alphaLabel = new Label(colorComposite, SWT.NONE);

Composite alphaComposite = new Composite(colorComposite, SWT.NONE);
alphaComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // Ensure it expands
alphaComposite.setLayout(new GridLayout(3, false));

Label alphaLabel = new Label(alphaComposite, SWT.NONE);
alphaLabel.setText(Messages.AddBookmarkDialog_Alpha);
fAlphaScale = new Scale(colorComposite, SWT.NONE);

fAlphaScale = new Scale(alphaComposite, SWT.NONE);
fAlphaScale.setMaximum(255);
fAlphaScale.setSelection(fAlpha);
fAlphaScale.setIncrement(1);
Expand All @@ -78,8 +94,27 @@ public void widgetSelected(SelectionEvent e) {
fAlphaLabel.setText(Integer.toString(fAlpha));
}
});
fAlphaLabel = new Label(colorComposite, SWT.NONE);

// Make the scale take all available horizontal space
fAlphaScale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

fAlphaLabel = new Label(alphaComposite, SWT.NONE);
fAlphaLabel.setText(Integer.toString(fAlpha));

Composite fgComposite = new Composite(colorComposite, SWT.NONE);
fgComposite.setLayout(new GridLayout(2, false));
fForgroundButton = new Button(fgComposite, SWT.CHECK);
fForgroundButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fForeground = fForgroundButton.getSelection();
super.widgetSelected(e);
}
});
fForeground = true;
fForgroundButton.setSelection(fForeground);
new Label(fgComposite, SWT.NONE).setText(Messages.AddBookmarkDialog_Foreground);

return areaComposite;
}

Expand All @@ -92,4 +127,13 @@ public RGBA getColorValue() {
RGB rgb = fColorSelector.getColorValue();
return new RGBA(rgb.red, rgb.green, rgb.blue, fAlpha);
}

/**
* Returns if the marker is in the foreground.
*
* @return true if foreground
*/
public boolean getForeground() {
return fForeground;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# org.eclipse.tracecompass.tmf.ui.dialogs
AddBookmarkDialog_Alpha=alpha:
AddBookmarkDialog_Color=Color:
AddBookmarkDialog_Foreground=Foreground
AddBookmarkDialog_Message=Bookmark Description:
AddBookmarkDialog_Title=Add Bookmark
ManageCustomParsersDialog_ConflictMessage=Trace type ''{0} : {1}'' already exists.\nDo you want to rename to ''{2}'' or skip?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@

package org.eclipse.tracecompass.tmf.ui.viewers.events;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.regex.Matcher;
Expand All @@ -43,6 +50,7 @@
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -167,16 +175,20 @@
import org.eclipse.tracecompass.tmf.ui.views.colors.IColorSettingsListener;
import org.eclipse.tracecompass.tmf.ui.widgets.rawviewer.TmfRawEventViewer;
import org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.TmfVirtualTable;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.themes.ColorUtil;
import org.eclipse.ui.themes.IThemeManager;
import org.json.JSONObject;

import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
Expand Down Expand Up @@ -1282,6 +1294,106 @@ public void run() {
builder -> builder.setSynchronized(isChecked()));
}
};
String ollamaUrl = "http://localhost:11434";
final IAction lookupInLLMAction = new Action("Lookup in local LLM", IAction.AS_PUSH_BUTTON) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change "Lookup in local LLM" to be "Explain event with local LLM" to make it more descriptive to a user.

@Override
public void run() {
ITmfTrace trace = fTrace;
if (trace == null || (fSelectedRank == -1 && fSelectedBeginRank == -1)) {
return;
}
Map<String, String> values = new HashMap<>();
for (int i : fTable.getColumnOrder()) {
TableColumn column = fTable.getColumns()[i];
// Omit the margin column and hidden columns
if (isVisibleEventColumn(column)) {
values.put(column.getText(), fTable.getSelection()[0].getText(i));
}
}
Job jerb = new Job("llm") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change "llm" to be "LLM Event Lookup" :)


@Override
protected IStatus run(IProgressMonitor monitor) {
String urlString = ollamaUrl + "/api/generate";

try {
// Create the URL object
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);

// Create the JSON payload
JSONObject jsonPayload = new JSONObject();
jsonPayload.put("model", "llama3.2"); // Specify the
// model
jsonPayload.put("prompt", "I have an event from a trace of type " + trace.getTraceTypeId() + " in that there is an event content " + values.toString() + " explain it."); // Your

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I love this. However, I think this can be improved to make it easier for the LLM to parse particularly because LLMs love a specific format like this:
Explain the following trace event:
Trace Type: org.eclipse.tracecompass.some.type
Event Details:
- Timestamp: 123456789
- Event Name: ThreadStart
- PID: 12
  • I think a format similar to the one below could be used and I have drafted up a quick mockup of how this could look. However, I haven't tested the following code:
StringBuilder prompt = new StringBuilder();
prompt.append("Explain the following trace event:\n");
prompt.append("Trace Type: ").append(trace.getTraceTypeId()).append("\n");
prompt.append("Event Details:\n");
for (Map.Entry<String, String> entry : values.entrySet()) {
    prompt.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
}
jsonPayload.put("prompt", prompt.toString());

jsonPayload.put("stream", false); // input
// prompt

// Send the request
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
wr.writeBytes(jsonPayload.toString());
wr.flush();
}

// Get the response
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));) {
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}

// Print the response
JSONObject jsonObj = new JSONObject(response.toString());
String data = String.valueOf(jsonObj.get("response"));
IProject project = fTrace.getResource().getProject();
IFile file = project.getFile("event.txt");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Naming of the file could be more specific as this gets overwritten every time.
  • I suggest that the current time could be added to each event text file like this:

IFile file = project.getFile("event_" + System.currentTimeMillis() + ".txt");

String fullPath = file.getFullPath().makeAbsolute().toOSString();
try {
file.create(data.getBytes(), IResource.FORCE, monitor);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (file.exists()) {
Display.getDefault().asyncExec(() -> {
// Get the active workbench page
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// Open the file in the Markdown editor
try {
page.openEditor(
new FileEditorInput(file),
IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
} catch (PartInitException e) {
e.printStackTrace();
} // Replace

});

} else {
System.out.println("File does not exist: " + fullPath);
}
}
} else {
System.out.println("POST request failed");
}
} catch (IOException e) {
e.printStackTrace();
}

return Status.OK_STATUS;
}
};
jerb.schedule();
}
};

class ToggleBookmarkAction extends Action {
private final Long fRank;
Expand Down Expand Up @@ -1361,6 +1473,17 @@ public void run() {
} else if (!fRawViewer.isVisible()) {
fTablePopupMenuManager.add(showRawAction);
}
URL url;
try {
url = new URL(ollamaUrl);
HttpURLConnection huc = (HttpURLConnection) url.openConnection();

if (huc.getResponseCode() == HttpURLConnection.HTTP_OK) {
fTablePopupMenuManager.add(lookupInLLMAction);
}
} catch (IOException e) {
// ignore
}
fTablePopupMenuManager.add(exportToTextAction);
fTablePopupMenuManager.add(new Separator());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
TmfTimestamp.fromNanos(bookmark.getTime())));
}
marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().toString());
marker.setAttribute(ITmfMarker.MARKER_FOREGROUND, bookmark.isForeground());
}
}, null);
} catch (CoreException e) {
Expand Down Expand Up @@ -1679,6 +1680,7 @@ private static List<IMarkerEvent> refreshBookmarks(final IFile editorFile) {
String time = marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null);
String duration = marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0));
String rgba = marker.getAttribute(ITmfMarker.MARKER_COLOR, (String) null);
boolean fg = marker.getAttribute(ITmfMarker.MARKER_FOREGROUND, Boolean.TRUE);
if (label != null && time != null && rgba != null) {
Matcher matcher = RGBA_PATTERN.matcher(rgba);
if (matcher.matches()) {
Expand All @@ -1688,7 +1690,7 @@ private static List<IMarkerEvent> refreshBookmarks(final IFile editorFile) {
int blue = Integer.valueOf(matcher.group(3));
int alpha = Integer.valueOf(matcher.group(4));
RGBA color = new RGBA(red, green, blue, alpha);
bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, true));
bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, fg));
} catch (NumberFormatException e) {
Activator.getDefault().logError(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,8 @@ public void runWithEvent(Event event) {
if (dialog.open() == Window.OK) {
final String label = dialog.getValue();
final RGBA rgba = dialog.getColorValue();
IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, rgba, label, true);
final boolean foreground = dialog.getForeground();
IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, rgba, label, foreground);
fBookmarks.add(bookmark);
updateMarkerList();
updateMarkerActions();
Expand Down
Loading