<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57050>57050</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            analyze-build doesn’t honor cgroup CPU limitations if launched inside a container
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dsilakov
      </td>
    </tr>
</table>

<pre>
    When launched without debug, analyze-build creates a pool of size None:

https://github.com/llvm/llvm-project/blob/main/clang/tools/scan-build-py/lib/libscanbuild/analyze.py#L238

In this case, python creates a pool of `os.cpu_count()` items. Unfortunately, `cpu_count()` doesn’t honor cgroup limitations – this is a known cpython issue (https://github.com/python/cpython/issues/80235) and it doesn’t look like it will be fixed in the near future.

This provides significant server load if you launch analyzer inside a container on some powerful machine.

At the same time, pylint has developed its own implementation of cpu counter which is aware of cgroups: `_query_cpu()`, https://github.com/PyCQA/pylint/blob/main/pylint/lint/run.py#L34 

It would be nice to take `_query_cpu()` from pylint (or provide a similar solution) and call it instead of using None in https://github.com/llvm/llvm-project/blob/main/clang/tools/scan-build-py/lib/libscanbuild/analyze.py#L238

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVE2P0zAQ_TXJxdoqdZs2OeSwLCAhIQQSiOPKcSaNWccO_mgpv57n9INd7WolbkhRnMzYM2_em3Fru2PzfSDDtIhGDtSxgwqDjYF11MZdxu-YMEIff9NNG5XumHQkAnkm2GStZrZnXv0m9skayla3WfE2K87vIYTJJxt_j2eHsLFdSDviR-v9ZbmZnP1BMuC31bbFMgplsEgtDPK_D0jjsXopzAnDzXRMh1V7eifHbMfvGesi7Vh95KvqMaAPhoVBeSaFp1TYdESl5oWKsk1h_UJO8V7aaACtyngNI1OBRr9g30xvXYgGx_QxRYLvhd2dJW-ydzyriqyuA0My65jcORsnptWoggjKGs8ue1YnfCpheTD2AGxnjMr7SAyhXyH1tDUxd_2ajyXyqoKvSsCCmB2qeAZNW_sASA-UnAelNWuJ9eoX-kEl1ogZEo71MURHi8ekfk2IoeFedeDQq51RvYIigXlye3IILRCkZ0cbz0126SiH2B7HUK20JkB2mFCstyNBiwO5Pmo2CjnA8yTpbZgxeYGNQY1nNbVC1kF4tO6etJ0S-OBZ4lGNk6aRzInxpDH0YrNeyHkYFFAl2g_C0eydRUpEJ23vf0Zyx3scuYqbMr6ixefj3ZfbWZME6llvX83nxUVzbtnVmj1pWahhI8YOchglUa1lQUCml1Gx3tnxwgSsaLezNODYo-M0RPRWx8TCpR2kgNyQHWIEglYoP3pldvNMJ_n_o0HOqVluNsVyXfCK512z6upVLfKggqbm6UX16vTdff72ZALRn9cL8HlT5tHp5p9ZuA5fuS3KIh-atuaylEVXrCtJneiW5banbbnhleg2Nee5Fi1p32Tlm4xzQ4fT2OM7K9_mquEF50W1TNWv18tFUfNiK7e0rni5rMtNti4IlOtFwrGwbpe7ZoaEe9zDqZUP_q9T-DSsRHM6xBcRl4ZrOo8mebD7fM7dzNj_ABq3CLg">