Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit profiling.bin in workspace directory #1539

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions manticore/core/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def newFunction(self, *args, **kw):
"terminate_state",
"kill_state",
"execute_instruction",
"terminate_execution",
}

def __init__(self, initial_state, workspace_url=None, policy="random", **kwargs):
Expand Down Expand Up @@ -814,8 +815,10 @@ def kill(self):
Workers must terminate
RUNNING, STANDBY -> KILLED
"""
self._publish("will_terminate_execution", self._output)
self._killed.value = True
self._lock.notify_all()
self._publish("did_terminate_execution", self._output)

def terminate(self):
logger.warning("manticore.terminate is deprecated (Use manticore.kill)")
Expand Down
4 changes: 4 additions & 0 deletions manticore/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ def did_terminate_worker_callback(self, id):
with self.manticore.locked_context("_profiling_stats", dict) as profiling_stats:
profiling_stats[id] = self.data.profile.stats.items()

def did_terminate_execution_callback(self, output):
with output.save_stream("profiling.bin", binary=True) as f:
self.save_profiling_data(f)

def get_profiling_data(self):
class PstatsFormatted:
def __init__(self, d):
Expand Down
4 changes: 0 additions & 4 deletions manticore/ethereum/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ def ethereum_main(args, logger):
else:
m.kill()

if consts.profile:
with open("profiling.bin", "wb") as f:
profiler.save_profiling_data(f)

for detector in list(m.detectors):
m.unregister_detector(detector)

Expand Down
17 changes: 14 additions & 3 deletions tests/native/test_manticore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import os
import logging
import filecmp

from manticore.native import Manticore
from manticore.utils.log import get_verbosity, set_verbosity
Expand All @@ -18,15 +19,23 @@ def setUp(self):

def test_profiling_data(self):
p = Profiler()
self.m.verbosity(0)
set_verbosity(0)
self.m.register_plugin(p)
self.m.run()
self.m.finalize()
profile_path = os.path.join(self.m.workspace, "profiling.bin")
with open(profile_path, "wb") as f:
p.save_profiling_data(f)
self.assertTrue(os.path.exists(profile_path))
self.assertTrue(os.path.getsize(profile_path) > 0)

profile_path_2 = os.path.join(self.m.workspace, "profiling_2.bin")
with open(profile_path_2, "wb") as f:
p.save_profiling_data(f)

self.assertTrue(os.path.exists(profile_path_2))
self.assertTrue(os.path.getsize(profile_path_2) > 0)

self.assertTrue(filecmp.cmp(profile_path, profile_path_2))

def test_add_hook(self):
def tmp(state):
pass
Expand Down Expand Up @@ -118,3 +127,5 @@ def test_logging(self):
set_verbosity(1)
self.assertEqual(get_verbosity("manticore.native.cpu.abstractcpu"), logging.WARNING)
self.assertEqual(get_verbosity("manticore.ethereum.abi"), logging.INFO)

set_verbosity(0)