Skip to content

Commit

Permalink
Merge branch 'memory-profile' into memory_profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltherealyang committed Jul 13, 2023
2 parents d528a69 + 96bb99f commit 8e4e520
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
13 changes: 12 additions & 1 deletion config/slips.conf
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,19 @@ cpu_profiler_output_limit = 20
# set the wait time between sampling sequences in seconds (live mode only)
cpu_profiler_sampling_interval = 20

# [12] Memory Profiling

# enable memory profiling [yes,no]
memory_profiler_enable = yes

# set profiling mode [dev,live]
memory_profiler_mode = dev

# profile all subprocesses in dev mode [yes,no]
memory_profiler_multiprocess = yes

####################
# [12] enable or disable p2p for slips
# [13] enable or disable p2p for slips
[P2P]

# create p2p.log with additional info about peer communications? yes or no
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ termcolor
communityid
viztracer
yappi
pytest-sugar
memray
10 changes: 10 additions & 0 deletions slips.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import multiprocessing
from slips_files.common.imports import *
from slips_files.common.cpu_profiler import CPUProfiler
from slips_files.common.memory_profiler import MemoryProfiler
from exclusiveprocess import Lock, CannotAcquireLock
from redis_manager import RedisManager
from metadata_manager import MetadataManager
Expand Down Expand Up @@ -682,6 +683,12 @@ def sig_handler(sig, frame):
####################
if __name__ == '__main__':
slips = Main()
memoryProfilerEnabled = slips.conf.get_memory_profiler_enable() == "yes"
memoryProfilerMode = slips.conf.get_memory_profiler_mode()
memoryProfilerMultiprocess = slips.conf.get_memory_profiler_multiprocess() == "yes"
if memoryProfilerEnabled:
memoryProfiler = MemoryProfiler("memraytest/output.bin", mode=memoryProfilerMode)
memoryProfiler.start()
if slips.args.stopdaemon:
# -S is provided
daemon = Daemon(slips)
Expand All @@ -707,3 +714,6 @@ def sig_handler(sig, frame):
# interactive mode
slips.start()
slips.cpu_profiler_release()

if memoryProfilerEnabled:
memoryProfiler.stop()
11 changes: 10 additions & 1 deletion slips_files/common/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,13 @@ def get_cpu_profiler_sampling_interval(self) -> int:
return int(self.read_configuration('Profiling', 'cpu_profiler_sampling_interval', 5))

def get_cpu_profiler_dev_mode_entries(self) -> int:
return int(self.read_configuration('Profiling', 'cpu_profiler_dev_mode_entries', 1000000))
return int(self.read_configuration('Profiling', 'cpu_profiler_dev_mode_entries', 1000000))

def get_memory_profiler_enable(self):
return self.read_configuration('Profiling', 'memory_profiler_enable', 'no')

def get_memory_profiler_mode(self):
return self.read_configuration('Profiling', 'memory_profiler_mode', 'dev')

def get_memory_profiler_multiprocess(self):
return self.read_configuration('Profiling', 'memory_profiler_multiprocess', 'yes')
2 changes: 1 addition & 1 deletion slips_files/common/cpu_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CPUProfiler(ProfilerInterface):
def __init__(self, db, output, mode="dev", limit=20, interval=20):
valid_modes = ["dev", "live"]
if mode not in valid_modes:
raise Exception("cpu_profiler_mode = " + mode + " is invalid, must be one of " +
print("cpu_profiler_mode = " + mode + " is invalid, must be one of " +
str(valid_modes) + ", CPU Profiling will be disabled")
if mode == "dev":
self.profiler = DevProfiler(output)
Expand Down

0 comments on commit 8e4e520

Please sign in to comment.