当前IDF在编译时,ninja默认使用全部的CPU来编译,导致电脑发热严重,能否显示它使用的CPU数量?
当前我的解决方案是:
在编译时,手动中断编译,然后 cd build:ninja -j2 all .
【已解决】IDF如何限制ninja使用的CPU数量?
-
- Posts: 156
- Joined: Tue Jul 11, 2023 6:55 am
Re: IDF如何限制ninja使用的CPU数量?
在之前版本中可以使用 make 限制 CPU 的数量,现在使用 CMake 就一直默认使用所有 CPU 了。
Re: IDF如何限制ninja使用的CPU数量?
我在idf的github找到一个example,自己尝试修改了下,发现可行。
使用了一下系统环境变量来设置ninja的并发编译,
Code: Select all
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import collections
import multiprocessing
import os
import platform
from typing import Dict, Union
GENERATORS: Dict[str, Union[str, Dict, list]] = collections.OrderedDict([
# - command: build command line
# - version: version command line
# - dry_run: command to run in dry run mode
# - verbose_flag: verbose flag
# - force_progression: one liner status of the progress
('Ninja', {
'command': ['ninja'],
'version': ['ninja', '--version'],
'dry_run': ['ninja', '-n'],
'verbose_flag': '-v',
# as opposed to printing the status updates each in a in new line
'force_progression': True,
}),
])
# 添加了下面这两句
if os.getenv("IDF_JOB_POOL_COMPILE"):
GENERATORS['Ninja']['command'] = ['ninja' , "-j" + os.getenv('IDF_JOB_POOL_COMPILE')]
if os.name != 'nt':
MAKE_CMD = 'gmake' if platform.system() == 'FreeBSD' else 'make'
GENERATORS['Unix Makefiles'] = {'command': [MAKE_CMD, '-j', str(multiprocessing.cpu_count() + 2)],
'version': [MAKE_CMD, '--version'],
'dry_run': [MAKE_CMD, '-n'],
'verbose_flag': 'VERBOSE=1',
'force_progression': False}
URL_TO_DOC = 'https://docs.espressif.com/projects/esp-idf'
SUPPORTED_TARGETS = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2']
PREVIEW_TARGETS = ['linux', 'esp32h2']
Code: Select all
# 默认
$ export IDF_JOB_POOL_COMPILE=
#等同于ninja -j2
$ export IDF_JOB_POOL_COMPILE=2
Who is online
Users browsing this forum: No registered users and 101 guests