Skip to content

Commit

Permalink
feat: passing custom options to explorer,optimizer,hotspotDetection
Browse files Browse the repository at this point in the history
  • Loading branch information
goerlibe committed Feb 2, 2024
1 parent aca8a07 commit d36cf43
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 63 deletions.
9 changes: 3 additions & 6 deletions src/DiscoPoPExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Decoration } from './utils/Decorations'
import { SimpleTreeNode } from './utils/SimpleTree'
import { UIPrompts } from './utils/UIPrompts'
import path = require('path')
import { config } from 'process'

function logAndShowErrorMessageHandler(error: any, optionalMessage?: string) {
if (optionalMessage) {
Expand Down Expand Up @@ -328,13 +329,9 @@ export class DiscoPoPExtension {
this.context.subscriptions.push(
vscode.commands.registerCommand(
Commands.runOptimizer,
async (configuration: Configuration) => {
// HotspotDetection
async (configuration: RunCapableConfiguration) => {
try {
const hsRunner = new OptimizerWorkflowUI(
configuration.dotDiscoPoP
)
this.dpResults = await hsRunner.run()
this.dpResults = await configuration.runOptimizer()
} catch (error: any) {
if (error instanceof CancellationError) {
UIPrompts.showMessageForSeconds(
Expand Down
18 changes: 12 additions & 6 deletions src/configurationManager/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as vscode from 'vscode'
import { TreeItem, ThemeIcon, TreeItemCollapsibleState } from 'vscode'
import { ConfigurationTreeItem } from './ConfigurationTreeItem'
import { Editable } from './Editable'
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'
import { DiscoPoPResults } from '../discoPoP/classes/DiscoPoPResults'
import { HotspotDetectionResults } from '../hotspotDetection/classes/HotspotDetectionResults'
import { ConfigurationTreeItem } from './ConfigurationTreeItem'
import { Editable } from './Editable'

export interface ConfigurationObserver {
onConfigurationChange(configuration: Configuration): void
Expand All @@ -12,7 +12,7 @@ export interface ConfigurationObserver {
export abstract class Configuration implements ConfigurationTreeItem, Editable {
public constructor(
private _name: string,
onConfigurationChange: ConfigurationObserver
onConfigurationChange: ConfigurationObserver | undefined
) {
this._running = false
if (onConfigurationChange !== undefined) {
Expand Down Expand Up @@ -96,11 +96,17 @@ export interface RunCapableConfiguration extends Configuration {
runDiscoPoP(): Promise<DiscoPoPResults>

/**
* Runs the HotspotDetection using the configuration's settings. After running, the results are stored in the .discopop directory.
* @returns true if successfully completed, false if aborted
* Runs the HotspotDetection using the configuration's settings. Returns the parsed results
* @throws if errors occured
*/
runHotspotDetection(): Promise<HotspotDetectionResults>

/**
* !!! Assumes that DiscoPoP was run before !!!
* Runs the optimizer using the configuration's settings. Returns the parsed results
* @throws if errors occured
*/
runOptimizer(): Promise<DiscoPoPResults>
}

export enum ConfigurationType {
Expand Down
7 changes: 5 additions & 2 deletions src/configurationManager/ConfigurationDeserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ export default function configurationFromJSON(
switch (json.configurationType) {
case ConfigurationType.CMake:
return new ConfigurationCMake(
observer,
json.name,
json.projectPath,
json.buildPath,
json.buildArguments,
json.executableName,
json.executableArgumentsForDiscoPoP,
json.executableArgumentsForHotspotDetection,
observer
json.buildArguments || '',
json.overrideExplorerArguments || '',
json.overrideOptimizerArguments || '',
json.overrideHotspotDetectionArguments || ''
)
case ConfigurationType.ViewOnly:
return new ConfigurationViewOnly(
Expand Down
21 changes: 11 additions & 10 deletions src/configurationManager/ConfigurationTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export class ConfigurationTreeDataProvider
return
}

const buildArguments = await vscode.window.showInputBox({
prompt: 'Enter the build arguments',
ignoreFocusOut: true,
})
if (buildArguments === undefined) {
return
}
// const buildArguments = await vscode.window.showInputBox({
// prompt: 'Enter the build arguments',
// ignoreFocusOut: true,
// })
// if (buildArguments === undefined) {
// return
// }

const executableName = await vscode.window.showInputBox({
prompt: 'Enter the name of the executable',
Expand All @@ -105,14 +105,15 @@ export class ConfigurationTreeDataProvider
)

configuration = new ConfigurationCMake(
this,
name,
projectPath,
buildPath,
buildArguments,
executableName,
executableArgumentsForDiscoPoP,
[],
this
[]
// use default for the buildArguments
// use default for all override... arguements
)
break
case ConfigurationType.ViewOnly:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'
import { ConfigurationTreeItem } from '../ConfigurationTreeItem'
import { Property, PropertyObserver, StringProperty } from '../Property'
import { ConfigurationCMake } from './ConfigurationCMake'

export class AdvancedConfigurationSettings
implements ConfigurationTreeItem, PropertyObserver
{
public constructor(
private cmakeConfig: ConfigurationCMake,
overrideExplorerArguments: string = '',
overrideOptimizerArguments: string = '',
overrideHotspotDetectionArguments: string = ''
) {
this._overrideExplorerArguments = new StringProperty(
'Override Explorer Arguments',
overrideExplorerArguments,
'If not empty: override the discopop_explorer arguments with the provided string.',
this
)
this._overrideOptimizerArguments = new StringProperty(
'Override Optimizer Arguments',
overrideOptimizerArguments,
'If not empty: override the optimizer arguments with the provided string.',
this
)
this._overrideHotspotDetectionArguments = new StringProperty(
'Override Hotspot Detection Arguments',
overrideHotspotDetectionArguments,
'If not empty: override the hotspot_detection arguments with the provided string.',
this
)
}
onPropertyChanged(property: Property<string | string[]>): void {
this.refresh()
}

private readonly _overrideExplorerArguments: StringProperty
public get overrideExplorerArguments(): string {
return this._overrideExplorerArguments.value
}
public set overrideExplorerArguments(value: string) {
this._overrideExplorerArguments.value = value
this.refresh()
}

private readonly _overrideOptimizerArguments: StringProperty
public get overrideOptimizerArguments(): string {
return this._overrideOptimizerArguments.value
}
public set overrideOptimizerArguments(value: string) {
this._overrideOptimizerArguments.value = value
this.refresh()
}

private readonly _overrideHotspotDetectionArguments: StringProperty
public get overrideHotspotDetectionArguments(): string {
return this._overrideHotspotDetectionArguments.value
}
public set overrideHotspotDetectionArguments(value: string) {
this._overrideHotspotDetectionArguments.value = value
this.refresh()
}

public getView(): TreeItem {
const treeItem = new TreeItem(
'Advanced Settings',
TreeItemCollapsibleState.Collapsed
)
treeItem.description =
'Override the default arguments for the explorer, optimizer, and hotspot detection.'
treeItem.iconPath = new ThemeIcon('symbol-class')
treeItem.tooltip =
'Override the default arguments for the explorer, optimizer, and hotspot detection.'
return treeItem
}

getChildren(): ConfigurationTreeItem[] {
return [
this._overrideExplorerArguments,
this._overrideOptimizerArguments,
this._overrideHotspotDetectionArguments,
]
}

refresh(): void {
this.cmakeConfig.refresh()
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import { CancellationError, TreeItem } from 'vscode'
import { TreeItem } from 'vscode'
import { DiscoPoPResults } from '../../discoPoP/classes/DiscoPoPResults'
import { HotspotDetectionResults } from '../../hotspotDetection/classes/HotspotDetectionResults'
import { DiscoPoPCMakeWorkflowUI } from '../../runners/workflows/DiscoPoPCMakeWorkflowUI'
import { HotspotDetectionCMakeWorkflowUI } from '../../runners/workflows/HotspotDetectionCMakeWorkflowUI'
import { OptimizerWorkflowUI } from '../../runners/workflows/OptimizerWorkflowUI'
import {
Configuration,
ConfigurationObserver,
ConfigurationType,
RunCapableConfiguration,
} from '../Configuration'
import { ConfigurationTreeItem } from '../ConfigurationTreeItem'
import {
Property,
PropertyObserver,
StringArrayProperty,
StringProperty,
SupportedType,
} from '../Property'
import { DiscoPoPResults } from '../../discoPoP/classes/DiscoPoPResults'
import { DiscoPoPCMakeWorkflowUI } from '../../runners/workflows/DiscoPoPCMakeWorkflowUI'
import { HotspotDetectionResults } from '../../hotspotDetection/classes/HotspotDetectionResults'
import { HotspotDetectionCMakeWorkflowUI } from '../../runners/workflows/HotspotDetectionCMakeWorkflowUI'
import { AdvancedConfigurationSettings } from './AdvancedConfigurationSettings'

export class ConfigurationCMake
extends Configuration
implements RunCapableConfiguration, PropertyObserver
{
public constructor(
onConfigurationChange: ConfigurationObserver | undefined,
name: string,
projectPath: string,
buildPath: string,
buildArguments: string,
executableName: string,
executableArgumentsForDiscoPoP: string,
executableArgumentsForHotspotDetection: string[],
onConfigurationChange?: ConfigurationObserver
executableArgumentsForDiscoPoP: string = '',
executableArgumentsForHotspotDetection: string[] = [],
buildArguments: string = '',
overrideExplorerArguments: string = '',
overrideOptimizerArguments: string = '',
overrideHotspotDetectionArguments: string = ''
) {
super(name, onConfigurationChange)
this._projectPath = new StringProperty(
Expand Down Expand Up @@ -69,6 +75,12 @@ export class ConfigurationCMake
'Arguments to pass to the executable when running the Hotspot Detection.',
this
)
this._advancedConfigurationSettings = new AdvancedConfigurationSettings(
this,
overrideExplorerArguments,
overrideOptimizerArguments,
overrideHotspotDetectionArguments
)
}

onPropertyChanged(
Expand Down Expand Up @@ -145,6 +157,31 @@ export class ConfigurationCMake
this.refresh()
}

private readonly _advancedConfigurationSettings: AdvancedConfigurationSettings
public get overrideExplorerArguments(): string {
return this._advancedConfigurationSettings.overrideExplorerArguments
}
public set overrideExplorerArguments(value: string) {
this._advancedConfigurationSettings.overrideExplorerArguments = value
this.refresh()
}
public get overrideOptimizerArguments(): string {
return this._advancedConfigurationSettings.overrideOptimizerArguments
}
public set overrideOptimizerArguments(value: string) {
this._advancedConfigurationSettings.overrideOptimizerArguments = value
this.refresh()
}
public get overrideHotspotDetectionArguments(): string {
return this._advancedConfigurationSettings
.overrideHotspotDetectionArguments
}
public set overrideHotspotDetectionArguments(value: string) {
this._advancedConfigurationSettings.overrideHotspotDetectionArguments =
value
this.refresh()
}

// TODO note to self: we should add a PropertyGroup class, which will be collapsible and will contain multiple properties to allow changing advanced settings
// e.g. should another discopop installation be used?
// e.g. should the build directory be cleared?
Expand All @@ -159,11 +196,15 @@ export class ConfigurationCMake
name: this.name,
projectPath: this.projectPath,
buildPath: this.buildPath,
buildArguments: this.buildArguments,
executableName: this.executableName,
executableArgumentsForDiscoPoP: this.executableArgumentsForDiscoPoP,
executableArgumentsForHotspotDetection:
this.executableArgumentsForHotspotDetection,
buildArguments: this.buildArguments,
overrideExplorerArguments: this.overrideExplorerArguments,
overrideOptimizerArguments: this.overrideOptimizerArguments,
overrideHotspotDetectionArguments:
this.overrideHotspotDetectionArguments,
}
}

Expand All @@ -173,14 +214,15 @@ export class ConfigurationCMake
return treeItem
}

public getChildren(): Property<SupportedType | SupportedType[]>[] {
public getChildren(): ConfigurationTreeItem[] {
return [
this._projectPath,
this._buildPath,
this._buildArguments,
this._executableName,
this._executableArgumentsForDiscoPoP,
this._executableArgumentsForHotspotDetection,
this._advancedConfigurationSettings,
]
}

Expand All @@ -192,7 +234,10 @@ export class ConfigurationCMake
this.executableName,
this.executableArgumentsForDiscoPoP,
this.buildPathForDiscoPoP,
this.dotDiscoPoP
this.dotDiscoPoP,
this.buildArguments,
this.overrideExplorerArguments,
this.overrideOptimizerArguments
)
return await dpRunner.run() // await because we want to catch errors here
} catch (error) {
Expand All @@ -210,7 +255,11 @@ export class ConfigurationCMake
this.executableName,
this.executableArgumentsForHotspotDetection,
this.dotDiscoPoP,
this.buildPathForHotspotDetection
this.buildPathForHotspotDetection,
this.buildArguments,
this.overrideHotspotDetectionArguments
? this.overrideHotspotDetectionArguments
: undefined
)
return await hsRunner.run() // await because we want to catch errors here
} catch (error) {
Expand All @@ -219,4 +268,9 @@ export class ConfigurationCMake
this.running = false
}
}

public async runOptimizer(): Promise<DiscoPoPResults> {
const optimizerRunner = new OptimizerWorkflowUI(this.dotDiscoPoP)
return optimizerRunner.run(this.overrideOptimizerArguments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class ConfigurationViewOnly
this.refresh()
}

public get overrideOptimizerArguments(): string | undefined {
return undefined
}

public readonly configurationType = ConfigurationType.ViewOnly

public constructor(
Expand Down
Loading

0 comments on commit d36cf43

Please sign in to comment.