-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Semalab/release_12_3
Release_12_3 -> main
- Loading branch information
Showing
6 changed files
with
58 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,45 @@ | ||
import logging | ||
import multiprocessing | ||
|
||
from agent.utils import run_logged | ||
|
||
GB_PER_THREAD = 2 | ||
|
||
|
||
class GBOM: | ||
""" | ||
runs AI Code monitor on given directories | ||
""" | ||
|
||
def freemem(self): | ||
""" | ||
Returns the free memory in GB. | ||
Note that this is Linux-specific, which is fine because we are always | ||
running in a Docker container. | ||
""" | ||
with open("/proc/meminfo") as file: | ||
for line in file: | ||
if "MemAvailable" in line: | ||
kbfree = line.split()[1] | ||
return float(kbfree) / (1024 * 1024) | ||
|
||
def run(self, directories): | ||
# We can use as many threads as available CPUs, but we need to cap the | ||
# number so that each thread has GB_PER_THREAD of memory available. | ||
gbfree = self.freemem() or GB_PER_THREAD | ||
threads = min(multiprocessing.cpu_count(), max(1, int(gbfree / GB_PER_THREAD))) | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.info(f"Running GBOM with {threads} threads (free memory: {gbfree:.2f} GB)") | ||
|
||
run_logged( | ||
[ | ||
"ai_engine", | ||
directories.repository, | ||
"--output-dir", directories.mkdir("GBOM"), | ||
"--output-dir", | ||
directories.mkdir("GBOM"), | ||
"--cpu_count", | ||
str(threads), | ||
], | ||
log_dir=directories.log_dir | ||
log_dir=directories.log_dir, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters