@@ -82,26 +82,34 @@ export const getJanExtensionsPath = (): string => {
8282 */
8383export const physicalCpuCount = async ( ) : Promise < number > => {
8484 const platform = os . platform ( )
85- if ( platform === 'linux' ) {
86- const output = await exec ( 'lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l' )
87- return parseInt ( output . trim ( ) , 10 )
88- } else if ( platform === 'darwin' ) {
89- const output = await exec ( 'sysctl -n hw.physicalcpu_max' )
90- return parseInt ( output . trim ( ) , 10 )
91- } else if ( platform === 'win32' ) {
92- const output = await exec ( 'WMIC CPU Get NumberOfCores' )
93- return output
94- . split ( os . EOL )
95- . map ( ( line : string ) => parseInt ( line ) )
96- . filter ( ( value : number ) => ! isNaN ( value ) )
97- . reduce ( ( sum : number , number : number ) => sum + number , 1 )
98- } else {
99- const cores = os . cpus ( ) . filter ( ( cpu : any , index : number ) => {
100- const hasHyperthreading = cpu . model . includes ( 'Intel' )
101- const isOdd = index % 2 === 1
102- return ! hasHyperthreading || isOdd
103- } )
104- return cores . length
85+ try {
86+ if ( platform === 'linux' ) {
87+ const output = await exec ( 'lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l' )
88+ return parseInt ( output . trim ( ) , 10 )
89+ } else if ( platform === 'darwin' ) {
90+ const output = await exec ( 'sysctl -n hw.physicalcpu_max' )
91+ return parseInt ( output . trim ( ) , 10 )
92+ } else if ( platform === 'win32' ) {
93+ const output = await exec ( 'WMIC CPU Get NumberOfCores' )
94+ return output
95+ . split ( os . EOL )
96+ . map ( ( line : string ) => parseInt ( line ) )
97+ . filter ( ( value : number ) => ! isNaN ( value ) )
98+ . reduce ( ( sum : number , number : number ) => sum + number , 1 )
99+ } else {
100+ const cores = os . cpus ( ) . filter ( ( cpu : any , index : number ) => {
101+ const hasHyperthreading = cpu . model . includes ( 'Intel' )
102+ const isOdd = index % 2 === 1
103+ return ! hasHyperthreading || isOdd
104+ } )
105+ return cores . length
106+ }
107+ } catch ( err ) {
108+ console . warn ( 'Failed to get physical CPU count' , err )
109+ // Divide by 2 to get rid of hyper threading
110+ const coreCount = Math . ceil ( os . cpus ( ) . length / 2 )
111+ console . debug ( 'Using node API to get physical CPU count:' , coreCount )
112+ return coreCount
105113 }
106114}
107115
0 commit comments