Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
65e55416
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
65e55416
编写于
4月 03, 2019
作者:
R
Rachel Macfarlane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some diagnostics refactoring
上级
06dd68b4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
287 addition
and
224 deletion
+287
-224
src/vs/base/common/processes.ts
src/vs/base/common/processes.ts
+11
-0
src/vs/base/node/cpuUsage.sh
src/vs/base/node/cpuUsage.sh
+1
-1
src/vs/base/node/ps.ts
src/vs/base/node/ps.ts
+3
-14
src/vs/code/electron-browser/issue/issueReporterMain.ts
src/vs/code/electron-browser/issue/issueReporterMain.ts
+15
-14
src/vs/code/electron-browser/issue/issueReporterModel.ts
src/vs/code/electron-browser/issue/issueReporterModel.ts
+11
-7
src/vs/code/electron-browser/issue/test/testReporterModel.test.ts
...ode/electron-browser/issue/test/testReporterModel.test.ts
+13
-2
src/vs/code/electron-browser/processExplorer/processExplorerMain.ts
...e/electron-browser/processExplorer/processExplorerMain.ts
+2
-1
src/vs/platform/diagnostics/common/diagnosticsService.ts
src/vs/platform/diagnostics/common/diagnosticsService.ts
+44
-0
src/vs/platform/diagnostics/electron-main/diagnosticsService.ts
.../platform/diagnostics/electron-main/diagnosticsService.ts
+20
-185
src/vs/platform/diagnostics/node/diagnosticsService.ts
src/vs/platform/diagnostics/node/diagnosticsService.ts
+167
-0
未找到文件。
src/vs/base/common/processes.ts
浏览文件 @
65e55416
...
...
@@ -87,6 +87,17 @@ export const enum TerminateResponseCode {
ProcessNotFound
=
3
,
}
export
interface
ProcessItem
{
name
:
string
;
cmd
:
string
;
pid
:
number
;
ppid
:
number
;
load
:
number
;
mem
:
number
;
children
?:
ProcessItem
[];
}
/**
* Sanitizes a VS Code process environment by removing all Electron/VS Code-related values.
*/
...
...
src/vs/base/node/cpuUsage.sh
浏览文件 @
65e55416
...
...
@@ -56,7 +56,7 @@ for PID in "$@"; do
PROCESS_TIME_BEFORE
=
${
PROCESS_BEFORE_TIMES
[
$ITER
]
}
let
PROCESS_DELTA
=
$PROCESS_TIME_AFTER
-
$PROCESS_TIME_BEFORE
let
TOTAL_DELTA
=
$TOTAL_TIME_AFTER
-
$TOTAL_TIME_BEFORE
CPU_USAGE
=
`
echo
"
100*
$PROCESS_DELTA
/
$TOTAL_DELTA
"
| bc
-l
`
CPU_USAGE
=
`
echo
"
$((
100
*
$PROCESS_DELTA
/
$TOTAL_DELTA
))
"
`
# Parent script reads from stdout, so echo result to be read
echo
$CPU_USAGE
...
...
src/vs/base/node/ps.ts
浏览文件 @
65e55416
...
...
@@ -4,20 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import
{
exec
}
from
'
child_process
'
;
import
{
ProcessItem
}
from
'
vs/base/common/processes
'
;
import
{
getPathFromAmdModule
}
from
'
vs/base/common/amd
'
;
export
interface
ProcessItem
{
name
:
string
;
cmd
:
string
;
pid
:
number
;
ppid
:
number
;
load
:
number
;
mem
:
number
;
children
?:
ProcessItem
[];
}
export
function
listProcesses
(
rootPid
:
number
):
Promise
<
ProcessItem
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -181,7 +170,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
exec
(
CMD
,
{
maxBuffer
:
1000
*
1024
,
env
:
{
LC_NUMERIC
:
'
en_US.UTF-8
'
}
},
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
||
stderr
)
{
reject
(
err
||
stderr
.
toString
(
));
reject
(
err
||
new
Error
(
stderr
.
toString
()
));
}
else
{
const
lines
=
stdout
.
toString
().
split
(
'
\n
'
);
...
...
@@ -214,7 +203,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
exec
(
cmd
,
{},
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
||
stderr
)
{
reject
(
err
||
stderr
.
toString
(
));
reject
(
err
||
new
Error
(
stderr
.
toString
()
));
}
else
{
const
cpuUsage
=
stdout
.
toString
().
split
(
'
\n
'
);
for
(
let
i
=
0
;
i
<
pids
.
length
;
i
++
)
{
...
...
src/vs/code/electron-browser/issue/issueReporterMain.ts
浏览文件 @
65e55416
...
...
@@ -40,6 +40,7 @@ import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import
{
normalizeGitHubUrl
}
from
'
vs/code/electron-browser/issue/issueReporterUtil
'
;
import
{
Button
}
from
'
vs/base/browser/ui/button/button
'
;
import
{
withUndefinedAsNull
}
from
'
vs/base/common/types
'
;
import
{
SystemInfo
}
from
'
vs/platform/diagnostics/common/diagnosticsService
'
;
const
MAX_URL_LENGTH
=
platform
.
isWindows
?
2081
:
5400
;
...
...
@@ -105,7 +106,7 @@ export class IssueReporter extends Disposable {
this
.
updatePreviewButtonState
();
});
ipcRenderer
.
on
(
'
vscode:issueSystemInfoResponse
'
,
(
_
:
unknown
,
info
:
any
)
=>
{
ipcRenderer
.
on
(
'
vscode:issueSystemInfoResponse
'
,
(
_
:
unknown
,
info
:
SystemInfo
)
=>
{
this
.
logService
.
trace
(
'
issueReporter: Received system data
'
);
this
.
issueReporterModel
.
update
({
systemInfo
:
info
});
this
.
receivedSystemInfo
=
true
;
...
...
@@ -902,19 +903,19 @@ export class IssueReporter extends Disposable {
private
updateSystemInfo
(
state
:
IssueReporterModelData
)
{
const
target
=
document
.
querySelector
(
'
.block-system .block-info
'
);
if
(
target
)
{
let
tableHtml
=
''
;
Object
.
keys
(
state
.
systemInfo
).
forEach
(
k
=>
{
const
data
=
typeof
state
.
systemInfo
[
k
]
===
'
object
'
?
Object
.
keys
(
state
.
systemInfo
[
k
]).
map
(
key
=>
`
${
key
}
:
${
state
.
systemInfo
[
k
][
key
]}
`
).
join
(
'
<br>
'
)
:
state
.
systemInfo
[
k
];
tableHtml
+=
`
<
tr>
<td>
${
k
}
</td
>
<td>
${
data
}
</td
>
</tr
>`
;
});
target
.
innerHTML
=
`<table>
${
tableHtml
}
</table>`
;
const
systemInfo
=
state
.
systemInfo
!
;
let
renderedData
=
`
<table>
<tr><td>CPUs</td><td>
${
systemInfo
.
cpus
}
</td></tr>
<tr><td>GPU Status</td><td>
${
Object
.
keys
(
systemInfo
.
gpuStatus
).
map
(
key
=>
`
${
key
}
:
${
systemInfo
.
gpuStatus
[
key
]}
`
).
join
(
'
<br>
'
)}
</td></tr>
<tr><td>Load (avg)</td><td>
${
systemInfo
.
load
}
</td></tr>
<tr><td>Memory (System)</td><td>
${
systemInfo
.
memory
}
</td></tr>
<tr><td>Process Argv</td><td>
${
systemInfo
.
processArgs
}
</td></
tr>
<tr><td>Screen Reader</td><td>
${
systemInfo
.
screenReader
}
</td></tr
>
<tr><td>VM</td><td>
${
systemInfo
.
vmHint
}
</td></tr
>
</table
>`
;
target
.
innerHTML
=
renderedData
;
}
}
...
...
src/vs/code/electron-browser/issue/issueReporterModel.ts
浏览文件 @
65e55416
...
...
@@ -5,13 +5,14 @@
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
IssueType
,
ISettingSearchResult
,
IssueReporterExtensionData
}
from
'
vs/platform/issue/common/issue
'
;
import
{
SystemInfo
}
from
'
vs/platform/diagnostics/common/diagnosticsService
'
;
export
interface
IssueReporterData
{
issueType
:
IssueType
;
issueDescription
?:
string
;
versionInfo
?:
any
;
systemInfo
?:
any
;
systemInfo
?:
SystemInfo
;
processInfo
?:
any
;
workspaceInfo
?:
any
;
...
...
@@ -148,13 +149,16 @@ ${this.getInfos()}
|---|---|
`
;
Object
.
keys
(
this
.
_data
.
systemInfo
).
forEach
(
k
=>
{
const
data
=
typeof
this
.
_data
.
systemInfo
[
k
]
===
'
object
'
?
Object
.
keys
(
this
.
_data
.
systemInfo
[
k
]).
map
(
key
=>
`
${
key
}
:
${
this
.
_data
.
systemInfo
[
k
][
key
]}
`
).
join
(
'
<br>
'
)
:
this
.
_data
.
systemInfo
[
k
];
if
(
this
.
_data
.
systemInfo
)
{
md
+=
`|
${
k
}
|
${
data
}
|\n`
;
});
md
+=
`|CPUs|
${
this
.
_data
.
systemInfo
.
cpus
}
|
|GPU Status|
${
Object
.
keys
(
this
.
_data
.
systemInfo
.
gpuStatus
).
map
(
key
=>
`
${
key
}
:
${
this
.
_data
.
systemInfo
!
.
gpuStatus
[
key
]}
`
).
join
(
'
<br>
'
)}
|
|Load (avg)|
${
this
.
_data
.
systemInfo
.
load
}
|
|Memory (System)|
${
this
.
_data
.
systemInfo
.
memory
}
|
|Process Argv|
${
this
.
_data
.
systemInfo
.
processArgs
}
|
|Screen Reader|
${
this
.
_data
.
systemInfo
.
screenReader
}
|
|VM|
${
this
.
_data
.
systemInfo
.
vmHint
}
|`
;
}
md
+=
'
\n
</details>
'
;
...
...
src/vs/code/electron-browser/issue/test/testReporterModel.test.ts
浏览文件 @
65e55416
...
...
@@ -43,7 +43,13 @@ Extensions: none
const
issueReporterModel
=
new
IssueReporterModel
({
issueType
:
0
,
systemInfo
:
{
'
GPU Status
'
:
{
os
:
'
Darwin
'
,
cpus
:
'
Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2800)
'
,
memory
:
'
16.00GB
'
,
vmHint
:
'
0%
'
,
processArgs
:
''
,
screenReader
:
'
no
'
,
gpuStatus
:
{
'
2d_canvas
'
:
'
enabled
'
,
'
checker_imaging
'
:
'
disabled_off
'
}
...
...
@@ -63,8 +69,13 @@ OS version: undefined
|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2800)|
|GPU Status|2d_canvas: enabled<br>checker_imaging: disabled_off|
|Load (avg)|undefined|
|Memory (System)|16.00GB|
|Process Argv||
|Screen Reader|no|
|VM|0%|
</details>Extensions: none
<!-- generated by issue reporter -->`
);
});
...
...
src/vs/code/electron-browser/processExplorer/processExplorerMain.ts
浏览文件 @
65e55416
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./media/processExplorer
'
;
import
{
listProcesses
,
ProcessItem
}
from
'
vs/base/node/ps
'
;
import
{
listProcesses
}
from
'
vs/base/node/ps
'
;
import
{
webFrame
,
ipcRenderer
,
clipboard
}
from
'
electron
'
;
import
{
repeat
}
from
'
vs/base/common/strings
'
;
import
{
totalmem
}
from
'
os
'
;
...
...
@@ -15,6 +15,7 @@ import * as browser from 'vs/base/browser/browser';
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
{
IContextMenuItem
}
from
'
vs/base/parts/contextmenu/common/contextmenu
'
;
import
{
popup
}
from
'
vs/base/parts/contextmenu/electron-browser/contextmenu
'
;
import
{
ProcessItem
}
from
'
vs/base/common/processes
'
;
let
processList
:
any
[];
let
mapPidToWindowTitle
=
new
Map
<
number
,
string
>
();
...
...
src/vs/platform/diagnostics/common/diagnosticsService.ts
0 → 100644
浏览文件 @
65e55416
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
ProcessItem
}
from
'
vs/base/common/processes
'
;
export
interface
IMachineInfo
{
os
:
string
;
cpus
?:
string
;
memory
:
string
;
vmHint
:
string
;
}
export
interface
IDiagnosticInfo
{
machineInfo
:
IMachineInfo
;
workspaceMetadata
?:
{
[
key
:
string
]:
WorkspaceStats
};
processes
?:
ProcessItem
;
}
export
interface
SystemInfo
extends
IMachineInfo
{
processArgs
:
string
;
gpuStatus
:
any
;
screenReader
:
string
;
load
?:
string
;
}
export
interface
IDiagnosticInfoOptions
{
includeProcesses
?:
boolean
;
folders
?:
UriComponents
[];
includeExtensions
?:
boolean
;
}
export
interface
WorkspaceStatItem
{
name
:
string
;
count
:
number
;
}
export
interface
WorkspaceStats
{
fileTypes
:
WorkspaceStatItem
[];
configFiles
:
WorkspaceStatItem
[];
fileCount
:
number
;
maxFilesReached
:
boolean
;
}
\ No newline at end of file
src/vs/platform/diagnostics/electron-main/diagnosticsService.ts
浏览文件 @
65e55416
...
...
@@ -4,18 +4,20 @@
*--------------------------------------------------------------------------------------------*/
import
{
IMainProcessInfo
,
ILaunchService
}
from
'
vs/platform/launch/electron-main/launchService
'
;
import
{
ProcessItem
,
listProcesses
}
from
'
vs/base/node/ps
'
;
import
{
listProcesses
}
from
'
vs/base/node/ps
'
;
import
product
from
'
vs/platform/product/node/product
'
;
import
pkg
from
'
vs/platform/product/node/package
'
;
import
*
as
os
from
'
os
'
;
import
*
as
os
Lib
from
'
os
'
;
import
{
virtualMachineHint
}
from
'
vs/base/node/id
'
;
import
{
repeat
,
pad
}
from
'
vs/base/common/strings
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
app
}
from
'
electron
'
;
import
{
basename
,
join
}
from
'
vs/base/common/path
'
;
import
{
basename
}
from
'
vs/base/common/path
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
readdir
,
stat
}
from
'
fs
'
;
import
{
WorkspaceStats
,
SystemInfo
}
from
'
vs/platform/diagnostics/common/diagnosticsService
'
;
import
{
collectWorkspaceStats
,
getMachineInfo
}
from
'
vs/platform/diagnostics/node/diagnosticsService
'
;
import
{
ProcessItem
}
from
'
vs/base/common/processes
'
;
export
const
ID
=
'
diagnosticsService
'
;
export
const
IDiagnosticsService
=
createDecorator
<
IDiagnosticsService
>
(
ID
);
...
...
@@ -33,16 +35,6 @@ export interface VersionInfo {
os
:
string
;
}
export
interface
SystemInfo
{
CPUs
?:
string
;
'
Memory (System)
'
:
string
;
'
Load (avg)
'
?:
string
;
VM
:
string
;
'
Screen Reader
'
:
string
;
'
Process Argv
'
:
string
;
'
GPU Status
'
:
Electron
.
GPUFeatureStatus
;
}
export
interface
ProcessInfo
{
cpu
:
number
;
memory
:
number
;
...
...
@@ -65,14 +57,14 @@ export class DiagnosticsService implements IDiagnosticsService {
const
output
:
string
[]
=
[];
output
.
push
(
`Version:
${
pkg
.
name
}
${
pkg
.
version
}
(
${
product
.
commit
||
'
Commit unknown
'
}
,
${
product
.
date
||
'
Date unknown
'
}
)`
);
output
.
push
(
`OS Version:
${
os
.
type
()}
${
os
.
arch
()}
${
os
.
release
()}
`
);
const
cpus
=
os
.
cpus
();
output
.
push
(
`OS Version:
${
os
Lib
.
type
()}
${
osLib
.
arch
()}
${
osLib
.
release
()}
`
);
const
cpus
=
os
Lib
.
cpus
();
if
(
cpus
&&
cpus
.
length
>
0
)
{
output
.
push
(
`CPUs:
${
cpus
[
0
].
model
}
(
${
cpus
.
length
}
x
${
cpus
[
0
].
speed
}
)`
);
}
output
.
push
(
`Memory (System):
${(
os
.
totalmem
()
/
GB
).
toFixed
(
2
)}
GB (
${(
os
.
freemem
()
/
GB
).
toFixed
(
2
)}
GB free)`
);
output
.
push
(
`Memory (System):
${(
os
Lib
.
totalmem
()
/
GB
).
toFixed
(
2
)}
GB (
${(
osLib
.
freemem
()
/
GB
).
toFixed
(
2
)}
GB free)`
);
if
(
!
isWindows
)
{
output
.
push
(
`Load (avg):
${
os
.
loadavg
().
map
(
l
=>
Math
.
round
(
l
)).
join
(
'
,
'
)}
`
);
// only provided on Linux/macOS
output
.
push
(
`Load (avg):
${
os
Lib
.
loadavg
().
map
(
l
=>
Math
.
round
(
l
)).
join
(
'
,
'
)}
`
);
// only provided on Linux/macOS
}
output
.
push
(
`VM:
${
Math
.
round
((
virtualMachineHint
.
value
()
*
100
))}
%`
);
output
.
push
(
`Screen Reader:
${
app
.
isAccessibilitySupportEnabled
()
?
'
yes
'
:
'
no
'
}
`
);
...
...
@@ -95,24 +87,20 @@ export class DiagnosticsService implements IDiagnosticsService {
async
getSystemInfo
(
launchService
:
ILaunchService
):
Promise
<
SystemInfo
>
{
const
info
=
await
launchService
.
getMainProcessInfo
();
const
MB
=
1024
*
1024
;
const
GB
=
1024
*
MB
;
const
{
memory
,
vmHint
,
os
,
cpus
}
=
getMachineInfo
();
const
systemInfo
:
SystemInfo
=
{
'
Memory (System)
'
:
`
${(
os
.
totalmem
()
/
GB
).
toFixed
(
2
)}
GB (
${(
os
.
freemem
()
/
GB
).
toFixed
(
2
)}
GB free)`
,
VM
:
`
${
Math
.
round
((
virtualMachineHint
.
value
()
*
100
))}
%`
,
'
Screen Reader
'
:
`
${
app
.
isAccessibilitySupportEnabled
()
?
'
yes
'
:
'
no
'
}
`
,
'
Process Argv
'
:
`
${
info
.
mainArguments
.
join
(
'
'
)}
`
,
'
GPU Status
'
:
app
.
getGPUFeatureStatus
()
os
,
memory
,
cpus
,
vmHint
,
processArgs
:
`
${
info
.
mainArguments
.
join
(
'
'
)}
`
,
gpuStatus
:
app
.
getGPUFeatureStatus
(),
screenReader
:
`
${
app
.
isAccessibilitySupportEnabled
()
?
'
yes
'
:
'
no
'
}
`
};
const
cpus
=
os
.
cpus
();
if
(
cpus
&&
cpus
.
length
>
0
)
{
systemInfo
.
CPUs
=
`
${
cpus
[
0
].
model
}
(
${
cpus
.
length
}
x
${
cpus
[
0
].
speed
}
)`
;
}
if
(
!
isWindows
)
{
systemInfo
[
'
Load (avg)
'
]
=
`
${
os
.
loadavg
().
map
(
l
=>
Math
.
round
(
l
)).
join
(
'
,
'
)}
`
;
systemInfo
.
load
=
`
${
osLib
.
loadavg
().
map
(
l
=>
Math
.
round
(
l
)).
join
(
'
,
'
)}
`
;
}
return
Promise
.
resolve
(
systemInfo
);
...
...
@@ -270,7 +258,7 @@ export class DiagnosticsService implements IDiagnosticsService {
name
=
`
${
name
}
(
${
mapPidToWindowTitle
.
get
(
item
.
pid
)}
)`
;
}
}
const
memory
=
process
.
platform
===
'
win32
'
?
item
.
mem
:
(
os
.
totalmem
()
*
(
item
.
mem
/
100
));
const
memory
=
process
.
platform
===
'
win32
'
?
item
.
mem
:
(
os
Lib
.
totalmem
()
*
(
item
.
mem
/
100
));
output
.
push
(
`
${
pad
(
Number
(
item
.
load
.
toFixed
(
0
)),
5
,
'
'
)}
\t
${
pad
(
Number
((
memory
/
MB
).
toFixed
(
0
)),
6
,
'
'
)}
\t
${
pad
(
Number
((
item
.
pid
).
toFixed
(
0
)),
6
,
'
'
)}
\t
${
name
}
`
);
// Recurse into children if any
...
...
@@ -280,25 +268,6 @@ export class DiagnosticsService implements IDiagnosticsService {
}
}
interface
WorkspaceStatItem
{
name
:
string
;
count
:
number
;
}
interface
WorkspaceStats
{
fileTypes
:
WorkspaceStatItem
[];
configFiles
:
WorkspaceStatItem
[];
fileCount
:
number
;
maxFilesReached
:
boolean
;
// launchConfigFiles: WorkspaceStatItem[];
}
function
asSortedItems
(
map
:
Map
<
string
,
number
>
):
WorkspaceStatItem
[]
{
const
a
:
WorkspaceStatItem
[]
=
[];
map
.
forEach
((
value
,
index
)
=>
a
.
push
({
name
:
index
,
count
:
value
}));
return
a
.
sort
((
a
,
b
)
=>
b
.
count
-
a
.
count
);
}
// function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> {
// const launchConfigs = new Map<string, number>();
...
...
@@ -339,137 +308,3 @@ function asSortedItems(map: Map<string, number>): WorkspaceStatItem[] {
// });
// });
// }
function
collectWorkspaceStats
(
folder
:
string
,
filter
:
string
[]):
Promise
<
WorkspaceStats
>
{
const
configFilePatterns
=
[
{
'
tag
'
:
'
grunt.js
'
,
'
pattern
'
:
/^
gruntfile
\
.
js$
/
i
},
{
'
tag
'
:
'
gulp.js
'
,
'
pattern
'
:
/^
gulpfile
\
.
js$
/
i
},
{
'
tag
'
:
'
tsconfig.json
'
,
'
pattern
'
:
/^
tsconfig
\
.
json$
/
i
},
{
'
tag
'
:
'
package.json
'
,
'
pattern
'
:
/^
package
\
.
json$
/
i
},
{
'
tag
'
:
'
jsconfig.json
'
,
'
pattern
'
:
/^
jsconfig
\
.
json$
/
i
},
{
'
tag
'
:
'
tslint.json
'
,
'
pattern
'
:
/^
tslint
\
.
json$
/
i
},
{
'
tag
'
:
'
eslint.json
'
,
'
pattern
'
:
/^
eslint
\
.
json$
/
i
},
{
'
tag
'
:
'
tasks.json
'
,
'
pattern
'
:
/^
tasks
\
.
json$
/
i
},
{
'
tag
'
:
'
launch.json
'
,
'
pattern
'
:
/^
launch
\
.
json$
/
i
},
{
'
tag
'
:
'
settings.json
'
,
'
pattern
'
:
/^
settings
\
.
json$
/
i
},
{
'
tag
'
:
'
webpack.config.js
'
,
'
pattern
'
:
/^
webpack
\
.
config
\
.
js$
/
i
},
{
'
tag
'
:
'
project.json
'
,
'
pattern
'
:
/^
project
\
.
json$
/
i
},
{
'
tag
'
:
'
makefile
'
,
'
pattern
'
:
/^
makefile$
/
i
},
{
'
tag
'
:
'
sln
'
,
'
pattern
'
:
/^
.
+
\
.
sln$
/
i
},
{
'
tag
'
:
'
csproj
'
,
'
pattern
'
:
/^
.
+
\
.
csproj$
/
i
},
{
'
tag
'
:
'
cmake
'
,
'
pattern
'
:
/^
.
+
\
.
cmake$
/
i
}
];
const
fileTypes
=
new
Map
<
string
,
number
>
();
const
configFiles
=
new
Map
<
string
,
number
>
();
const
MAX_FILES
=
20000
;
function
walk
(
dir
:
string
,
filter
:
string
[],
token
:
{
count
:
any
;
maxReached
:
any
;
},
done
:
(
allFiles
:
string
[])
=>
void
):
void
{
let
results
:
string
[]
=
[];
readdir
(
dir
,
async
(
err
,
files
)
=>
{
// Ignore folders that can't be read
if
(
err
)
{
return
done
(
results
);
}
let
pending
=
files
.
length
;
if
(
pending
===
0
)
{
return
done
(
results
);
}
for
(
const
file
of
files
)
{
if
(
token
.
maxReached
)
{
return
done
(
results
);
}
stat
(
join
(
dir
,
file
),
(
err
,
stats
)
=>
{
// Ignore files that can't be read
if
(
err
)
{
if
(
--
pending
===
0
)
{
return
done
(
results
);
}
}
else
{
if
(
stats
.
isDirectory
())
{
if
(
filter
.
indexOf
(
file
)
===
-
1
)
{
walk
(
join
(
dir
,
file
),
filter
,
token
,
(
res
:
string
[])
=>
{
results
=
results
.
concat
(
res
);
if
(
--
pending
===
0
)
{
return
done
(
results
);
}
});
}
else
{
if
(
--
pending
===
0
)
{
done
(
results
);
}
}
}
else
{
if
(
token
.
count
>=
MAX_FILES
)
{
token
.
maxReached
=
true
;
}
token
.
count
++
;
results
.
push
(
file
);
if
(
--
pending
===
0
)
{
done
(
results
);
}
}
}
});
}
});
}
const
addFileType
=
(
fileType
:
string
)
=>
{
if
(
fileTypes
.
has
(
fileType
))
{
fileTypes
.
set
(
fileType
,
fileTypes
.
get
(
fileType
)
!
+
1
);
}
else
{
fileTypes
.
set
(
fileType
,
1
);
}
};
const
addConfigFiles
=
(
fileName
:
string
)
=>
{
for
(
const
each
of
configFilePatterns
)
{
if
(
each
.
pattern
.
test
(
fileName
))
{
if
(
configFiles
.
has
(
each
.
tag
))
{
configFiles
.
set
(
each
.
tag
,
configFiles
.
get
(
each
.
tag
)
!
+
1
);
}
else
{
configFiles
.
set
(
each
.
tag
,
1
);
}
}
}
};
const
acceptFile
=
(
name
:
string
)
=>
{
if
(
name
.
lastIndexOf
(
'
.
'
)
>=
0
)
{
const
suffix
:
string
|
undefined
=
name
.
split
(
'
.
'
).
pop
();
if
(
suffix
)
{
addFileType
(
suffix
);
}
}
addConfigFiles
(
name
);
};
const
token
:
{
count
:
number
,
maxReached
:
boolean
}
=
{
count
:
0
,
maxReached
:
false
};
return
new
Promise
((
resolve
,
reject
)
=>
{
walk
(
folder
,
filter
,
token
,
async
(
files
)
=>
{
files
.
forEach
(
acceptFile
);
// TODO@rachel commented out due to severe performance issues
// see https://github.com/Microsoft/vscode/issues/70563
// const launchConfigs = await collectLaunchConfigs(folder);
resolve
({
configFiles
:
asSortedItems
(
configFiles
),
fileTypes
:
asSortedItems
(
fileTypes
),
fileCount
:
token
.
count
,
maxFilesReached
:
token
.
maxReached
,
// launchConfigFiles: launchConfigs
});
});
});
}
\ No newline at end of file
src/vs/platform/diagnostics/node/diagnosticsService.ts
0 → 100644
浏览文件 @
65e55416
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
os
from
'
os
'
;
import
{
virtualMachineHint
}
from
'
vs/base/node/id
'
;
import
{
IMachineInfo
,
WorkspaceStats
,
WorkspaceStatItem
}
from
'
vs/platform/diagnostics/common/diagnosticsService
'
;
import
{
readdir
,
stat
}
from
'
fs
'
;
import
{
join
}
from
'
vs/base/common/path
'
;
export
function
getMachineInfo
():
IMachineInfo
{
const
MB
=
1024
*
1024
;
const
GB
=
1024
*
MB
;
const
machineInfo
:
IMachineInfo
=
{
os
:
`
${
os
.
type
()}
${
os
.
arch
()}
${
os
.
release
()}
`
,
memory
:
`
${(
os
.
totalmem
()
/
GB
).
toFixed
(
2
)}
GB (
${(
os
.
freemem
()
/
GB
).
toFixed
(
2
)}
GB free)`
,
vmHint
:
`
${
Math
.
round
((
virtualMachineHint
.
value
()
*
100
))}
%`
,
};
const
cpus
=
os
.
cpus
();
if
(
cpus
&&
cpus
.
length
>
0
)
{
machineInfo
.
cpus
=
`
${
cpus
[
0
].
model
}
(
${
cpus
.
length
}
x
${
cpus
[
0
].
speed
}
)`
;
}
return
machineInfo
;
}
export
function
collectWorkspaceStats
(
folder
:
string
,
filter
:
string
[]):
Promise
<
WorkspaceStats
>
{
const
configFilePatterns
=
[
{
'
tag
'
:
'
grunt.js
'
,
'
pattern
'
:
/^
gruntfile
\
.
js$
/
i
},
{
'
tag
'
:
'
gulp.js
'
,
'
pattern
'
:
/^
gulpfile
\
.
js$
/
i
},
{
'
tag
'
:
'
tsconfig.json
'
,
'
pattern
'
:
/^
tsconfig
\
.
json$
/
i
},
{
'
tag
'
:
'
package.json
'
,
'
pattern
'
:
/^
package
\
.
json$
/
i
},
{
'
tag
'
:
'
jsconfig.json
'
,
'
pattern
'
:
/^
jsconfig
\
.
json$
/
i
},
{
'
tag
'
:
'
tslint.json
'
,
'
pattern
'
:
/^
tslint
\
.
json$
/
i
},
{
'
tag
'
:
'
eslint.json
'
,
'
pattern
'
:
/^
eslint
\
.
json$
/
i
},
{
'
tag
'
:
'
tasks.json
'
,
'
pattern
'
:
/^
tasks
\
.
json$
/
i
},
{
'
tag
'
:
'
launch.json
'
,
'
pattern
'
:
/^
launch
\
.
json$
/
i
},
{
'
tag
'
:
'
settings.json
'
,
'
pattern
'
:
/^
settings
\
.
json$
/
i
},
{
'
tag
'
:
'
webpack.config.js
'
,
'
pattern
'
:
/^
webpack
\
.
config
\
.
js$
/
i
},
{
'
tag
'
:
'
project.json
'
,
'
pattern
'
:
/^
project
\
.
json$
/
i
},
{
'
tag
'
:
'
makefile
'
,
'
pattern
'
:
/^
makefile$
/
i
},
{
'
tag
'
:
'
sln
'
,
'
pattern
'
:
/^
.
+
\
.
sln$
/
i
},
{
'
tag
'
:
'
csproj
'
,
'
pattern
'
:
/^
.
+
\
.
csproj$
/
i
},
{
'
tag
'
:
'
cmake
'
,
'
pattern
'
:
/^
.
+
\
.
cmake$
/
i
}
];
const
fileTypes
=
new
Map
<
string
,
number
>
();
const
configFiles
=
new
Map
<
string
,
number
>
();
const
MAX_FILES
=
20000
;
function
walk
(
dir
:
string
,
filter
:
string
[],
token
:
{
count
:
number
,
maxReached
:
boolean
},
done
:
(
allFiles
:
string
[])
=>
void
):
void
{
let
results
:
string
[]
=
[];
readdir
(
dir
,
async
(
err
,
files
)
=>
{
// Ignore folders that can't be read
if
(
err
)
{
return
done
(
results
);
}
let
pending
=
files
.
length
;
if
(
pending
===
0
)
{
return
done
(
results
);
}
for
(
const
file
of
files
)
{
if
(
token
.
maxReached
)
{
return
done
(
results
);
}
stat
(
join
(
dir
,
file
),
(
err
,
stats
)
=>
{
// Ignore files that can't be read
if
(
err
)
{
if
(
--
pending
===
0
)
{
return
done
(
results
);
}
}
else
{
if
(
stats
.
isDirectory
())
{
if
(
filter
.
indexOf
(
file
)
===
-
1
)
{
walk
(
join
(
dir
,
file
),
filter
,
token
,
(
res
:
string
[])
=>
{
results
=
results
.
concat
(
res
);
if
(
--
pending
===
0
)
{
return
done
(
results
);
}
});
}
else
{
if
(
--
pending
===
0
)
{
done
(
results
);
}
}
}
else
{
if
(
token
.
count
>=
MAX_FILES
)
{
token
.
maxReached
=
true
;
}
token
.
count
++
;
results
.
push
(
file
);
if
(
--
pending
===
0
)
{
done
(
results
);
}
}
}
});
}
});
}
const
addFileType
=
(
fileType
:
string
)
=>
{
if
(
fileTypes
.
has
(
fileType
))
{
fileTypes
.
set
(
fileType
,
fileTypes
.
get
(
fileType
)
!
+
1
);
}
else
{
fileTypes
.
set
(
fileType
,
1
);
}
};
const
addConfigFiles
=
(
fileName
:
string
)
=>
{
for
(
const
each
of
configFilePatterns
)
{
if
(
each
.
pattern
.
test
(
fileName
))
{
if
(
configFiles
.
has
(
each
.
tag
))
{
configFiles
.
set
(
each
.
tag
,
configFiles
.
get
(
each
.
tag
)
!
+
1
);
}
else
{
configFiles
.
set
(
each
.
tag
,
1
);
}
}
}
};
const
acceptFile
=
(
name
:
string
)
=>
{
if
(
name
.
lastIndexOf
(
'
.
'
)
>=
0
)
{
const
suffix
:
string
|
undefined
=
name
.
split
(
'
.
'
).
pop
();
if
(
suffix
)
{
addFileType
(
suffix
);
}
}
addConfigFiles
(
name
);
};
const
token
:
{
count
:
number
,
maxReached
:
boolean
}
=
{
count
:
0
,
maxReached
:
false
};
return
new
Promise
((
resolve
,
reject
)
=>
{
walk
(
folder
,
filter
,
token
,
async
(
files
)
=>
{
files
.
forEach
(
acceptFile
);
// TODO@rachel commented out due to severe performance issues
// see https://github.com/Microsoft/vscode/issues/70563
// const launchConfigs = await collectLaunchConfigs(folder);
resolve
({
configFiles
:
asSortedItems
(
configFiles
),
fileTypes
:
asSortedItems
(
fileTypes
),
fileCount
:
token
.
count
,
maxFilesReached
:
token
.
maxReached
,
// launchConfigFiles: launchConfigs
});
});
});
}
function
asSortedItems
(
map
:
Map
<
string
,
number
>
):
WorkspaceStatItem
[]
{
const
a
:
WorkspaceStatItem
[]
=
[];
map
.
forEach
((
value
,
index
)
=>
a
.
push
({
name
:
index
,
count
:
value
}));
return
a
.
sort
((
a
,
b
)
=>
b
.
count
-
a
.
count
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录