Skip to content

Commit de0deba

Browse files
authored
Sort using the processName key instead of label (microsoft#9411)
* Sort using the processName key instead of label * Update detail to commandLine * Forgot some details
1 parent 7bccfea commit de0deba

7 files changed

Lines changed: 181 additions & 62 deletions

File tree

src/client/debugger/extension/attachQuickPick/provider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class AttachProcessProvider implements IAttachProcessProvider {
2020

2121
public getAttachItems(): Promise<IAttachItem[]> {
2222
return this._getInternalProcessEntries().then(processEntries => {
23-
processEntries.sort(({ label: aLabel, detail: aDetail }, { label: bLabel, detail: bDetail }) => {
23+
processEntries.sort(({ processName: aprocessName, commandLine: aCommandLine }, { processName: bProcessName, commandLine: bCommandLine }) => {
2424
const compare = (aString: string, bString: string): number => {
2525
// localeCompare is significantly slower than < and > (2000 ms vs 80 ms for 10,000 elements)
2626
// We can change to localeCompare if this becomes an issue
@@ -34,8 +34,8 @@ export class AttachProcessProvider implements IAttachProcessProvider {
3434
return aLower < bLower ? -1 : 1;
3535
};
3636

37-
const aPython = aLabel.startsWith('python');
38-
const bPython = bLabel.startsWith('python');
37+
const aPython = aprocessName.startsWith('python');
38+
const bPython = bProcessName.startsWith('python');
3939

4040
if (aPython || bPython) {
4141
if (aPython && !bPython) {
@@ -45,10 +45,10 @@ export class AttachProcessProvider implements IAttachProcessProvider {
4545
return 1;
4646
}
4747

48-
return aPython ? compare(aDetail!, bDetail!) : compare(bDetail!, aDetail!);
48+
return aPython ? compare(aCommandLine!, bCommandLine!) : compare(bCommandLine!, aCommandLine!);
4949
}
5050

51-
return compare(aLabel, bLabel);
51+
return compare(aprocessName, bProcessName);
5252
});
5353

5454
return processEntries;

src/client/debugger/extension/attachQuickPick/psProcessParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export namespace PsProcessParser {
9292
label: executable,
9393
description: pid,
9494
detail: cmdline,
95-
id: pid
95+
id: pid,
96+
processName: executable,
97+
commandLine: cmdline
9698
};
9799
}
98100
}

src/client/debugger/extension/attachQuickPick/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type ProcessListCommand = { command: string; args: string[] };
99

1010
export interface IAttachItem extends QuickPickItem {
1111
id: string;
12+
processName: string;
13+
commandLine: string;
1214
}
1315

1416
export interface IAttachProcessProvider {

src/client/debugger/extension/attachQuickPick/wmicProcessParser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export namespace WmicProcessParser {
1313
label: '',
1414
description: '',
1515
detail: '',
16-
id: ''
16+
id: '',
17+
processName: '',
18+
commandLine: ''
1719
};
1820

1921
// Perf numbers on Win10:
@@ -60,6 +62,7 @@ export namespace WmicProcessParser {
6062

6163
if (key === wmicNameTitle) {
6264
currentItem.label = value;
65+
currentItem.processName = value;
6366
} else if (key === wmicPidTitle) {
6467
currentItem.description = value;
6568
currentItem.id = value;
@@ -70,6 +73,7 @@ export namespace WmicProcessParser {
7073
}
7174

7275
currentItem.detail = value;
76+
currentItem.commandLine = value;
7377
}
7478
}
7579

src/test/debugger/extension/attachQuickPick/provider.unit.test.ts

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,25 @@ suite('Attach to process - process provider', () => {
4747
label: 'launchd',
4848
description: '1',
4949
detail: 'launchd',
50-
id: '1'
50+
id: '1',
51+
processName: 'launchd',
52+
commandLine: 'launchd'
5153
},
5254
{
5355
label: 'syslogd',
5456
description: '41',
5557
detail: 'syslogd',
56-
id: '41'
58+
id: '41',
59+
processName: 'syslogd',
60+
commandLine: 'syslogd'
5761
},
5862
{
5963
label: 'kextd',
6064
description: '146',
6165
detail: 'kextd',
62-
id: '146'
66+
id: '146',
67+
processName: 'kextd',
68+
commandLine: 'kextd'
6369
}
6470
];
6571
when(processService.exec(PsProcessParser.psLinuxCommand.command, anything(), anything())).thenResolve({ stdout: psOutput });
@@ -82,19 +88,25 @@ suite('Attach to process - process provider', () => {
8288
label: 'launchd',
8389
description: '1',
8490
detail: 'launchd',
85-
id: '1'
91+
id: '1',
92+
processName: 'launchd',
93+
commandLine: 'launchd'
8694
},
8795
{
8896
label: 'syslogd',
8997
description: '41',
9098
detail: 'syslogd',
91-
id: '41'
99+
id: '41',
100+
processName: 'syslogd',
101+
commandLine: 'syslogd'
92102
},
93103
{
94104
label: 'kextd',
95105
description: '146',
96106
detail: 'kextd',
97-
id: '146'
107+
id: '146',
108+
processName: 'kextd',
109+
commandLine: 'kextd'
98110
}
99111
];
100112
when(processService.exec(PsProcessParser.psDarwinCommand.command, anything(), anything())).thenResolve({ stdout: psOutput });
@@ -125,19 +137,25 @@ ProcessId=5912\r
125137
label: 'System',
126138
description: '4',
127139
detail: '',
128-
id: '4'
140+
id: '4',
141+
processName: 'System',
142+
commandLine: ''
129143
},
130144
{
131145
label: 'sihost.exe',
132146
description: '5728',
133147
detail: 'sihost.exe',
134-
id: '5728'
148+
id: '5728',
149+
processName: 'sihost.exe',
150+
commandLine: 'sihost.exe'
135151
},
136152
{
137153
label: 'svchost.exe',
138154
description: '5912',
139155
detail: 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc',
140-
id: '5912'
156+
id: '5912',
157+
processName: 'svchost.exe',
158+
commandLine: 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc'
141159
}
142160
];
143161
when(platformService.isMac).thenReturn(false);
@@ -162,6 +180,7 @@ ProcessId=5912\r
162180
await expect(promise).to.eventually.be.rejectedWith(`Operating system '${OSType.Unknown}' not supported.`);
163181
});
164182

183+
// tslint:disable-next-line: max-func-body-length
165184
suite('POSIX getAttachItems (Linux)', () => {
166185
setup(() => {
167186
when(platformService.isMac).thenReturn(false);
@@ -179,19 +198,25 @@ ProcessId=5912\r
179198
label: 'kextd',
180199
description: '146',
181200
detail: 'kextd',
182-
id: '146'
201+
id: '146',
202+
processName: 'kextd',
203+
commandLine: 'kextd'
183204
},
184205
{
185206
label: 'launchd',
186207
description: '1',
187208
detail: 'launchd',
188-
id: '1'
209+
id: '1',
210+
processName: 'launchd',
211+
commandLine: 'launchd'
189212
},
190213
{
191214
label: 'syslogd',
192215
description: '41',
193216
detail: 'syslogd',
194-
id: '41'
217+
id: '41',
218+
processName: 'syslogd',
219+
commandLine: 'syslogd'
195220
}
196221
];
197222
when(processService.exec(PsProcessParser.psLinuxCommand.command, anything(), anything())).thenResolve({ stdout: psOutput });
@@ -214,31 +239,41 @@ ProcessId=5912\r
214239
label: 'python',
215240
description: '96',
216241
detail: 'python',
217-
id: '96'
242+
id: '96',
243+
processName: 'python',
244+
commandLine: 'python'
218245
},
219246
{
220247
label: 'python',
221248
description: '31896',
222249
detail: 'python script.py',
223-
id: '31896'
250+
id: '31896',
251+
processName: 'python',
252+
commandLine: 'python script.py'
224253
},
225254
{
226255
label: 'kextd',
227256
description: '146',
228257
detail: 'kextd',
229-
id: '146'
258+
id: '146',
259+
processName: 'kextd',
260+
commandLine: 'kextd'
230261
},
231262
{
232263
label: 'launchd',
233264
description: '1',
234265
detail: 'launchd',
235-
id: '1'
266+
id: '1',
267+
processName: 'launchd',
268+
commandLine: 'launchd'
236269
},
237270
{
238271
label: 'syslogd',
239272
description: '41',
240273
detail: 'syslogd',
241-
id: '41'
274+
id: '41',
275+
processName: 'syslogd',
276+
commandLine: 'syslogd'
242277
}
243278
];
244279
when(processService.exec(PsProcessParser.psLinuxCommand.command, anything(), anything())).thenResolve({ stdout: psOutput });
@@ -277,19 +312,25 @@ ProcessId=5728\r
277312
label: 'sihost.exe',
278313
description: '5728',
279314
detail: 'sihost.exe',
280-
id: '5728'
315+
id: '5728',
316+
processName: 'sihost.exe',
317+
commandLine: 'sihost.exe'
281318
},
282319
{
283320
label: 'svchost.exe',
284321
description: '5372',
285322
detail: '',
286-
id: '5372'
323+
id: '5372',
324+
processName: 'svchost.exe',
325+
commandLine: ''
287326
},
288327
{
289328
label: 'System',
290329
description: '4',
291330
detail: '',
292-
id: '4'
331+
id: '4',
332+
processName: 'System',
333+
commandLine: ''
293334
}
294335
];
295336
when(processService.exec(WmicProcessParser.wmicCommand.command, anything(), anything())).thenResolve({ stdout: windowsOutput });
@@ -334,37 +375,49 @@ ProcessId=8026\r
334375
label: 'python.exe',
335376
description: '8026',
336377
detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py',
337-
id: '8026'
378+
id: '8026',
379+
processName: 'python.exe',
380+
commandLine: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py'
338381
},
339382
{
340383
label: 'python.exe',
341384
description: '6028',
342385
detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py',
343-
id: '6028'
386+
id: '6028',
387+
processName: 'python.exe',
388+
commandLine: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py'
344389
},
345390
{
346391
label: 'sihost.exe',
347392
description: '5728',
348393
detail: 'sihost.exe',
349-
id: '5728'
394+
id: '5728',
395+
processName: 'sihost.exe',
396+
commandLine: 'sihost.exe'
350397
},
351398
{
352399
label: 'svchost.exe',
353400
description: '5372',
354401
detail: '',
355-
id: '5372'
402+
id: '5372',
403+
processName: 'svchost.exe',
404+
commandLine: ''
356405
},
357406
{
358407
label: 'svchost.exe',
359408
description: '5912',
360409
detail: 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc',
361-
id: '5912'
410+
id: '5912',
411+
processName: 'svchost.exe',
412+
commandLine: 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc'
362413
},
363414
{
364415
label: 'System',
365416
description: '4',
366417
detail: '',
367-
id: '4'
418+
id: '4',
419+
processName: 'System',
420+
commandLine: ''
368421
}
369422
];
370423
when(processService.exec(WmicProcessParser.wmicCommand.command, anything(), anything())).thenResolve({ stdout: windowsOutput });

0 commit comments

Comments
 (0)