diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/resources/ITmfMarker.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/resources/ITmfMarker.java index 7a38474f29..b4ff96924b 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/resources/ITmfMarker.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/resources/ITmfMarker.java @@ -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$ } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF b/tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF index 5d1fa6d9d1..1eb3ab8723 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF +++ b/tmf/org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF @@ -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", diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java index 75ee73d61a..7c4664ad48 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java @@ -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; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java index d46537a3cc..8c636826ac 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/AddBookmarkDialog.java @@ -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; @@ -38,7 +42,9 @@ 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 @@ -46,7 +52,8 @@ public class AddBookmarkDialog extends MultiLineInputDialog { * @param parentShell * the parent shell * @param initialValue - * the initial input value, or null if none (equivalent to the empty string) + * the initial input value, or null if none + * (equivalent to the empty string) */ public AddBookmarkDialog(Shell parentShell, String initialValue) { super(parentShell, Messages.AddBookmarkDialog_Title, Messages.AddBookmarkDialog_Message, initialValue); @@ -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); @@ -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; } @@ -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; + } } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties index 7fa3f54518..29699bd42b 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties @@ -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? diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java index 6b62bd2a1a..0fb7831b9a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java @@ -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; @@ -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; @@ -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; @@ -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) { + @Override + public void run() { + ITmfTrace trace = fTrace; + if (trace == null || (fSelectedRank == -1 && fSelectedBeginRank == -1)) { + return; + } + Map 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") { + + @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 + 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"); + 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; @@ -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()); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java index e72c24eaa5..e029af2e0d 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java @@ -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) { @@ -1679,6 +1680,7 @@ private static List 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()) { @@ -1688,7 +1690,7 @@ private static List 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()); } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java index dd42509c46..4db41c5e6d 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -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();