-
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.
Allowing to trace an already running program
- Loading branch information
Showing
11 changed files
with
172 additions
and
1,578 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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#region GPLv3 notice | ||
# Copyright 2014 Damian Quiroga | ||
# | ||
# This file is part of dissect. | ||
# | ||
# dissect is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# dissect is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with dissect. If not, see <http://www.gnu.org/licenses/>. | ||
#endregion | ||
|
||
import threading | ||
from Queue import Queue | ||
|
||
from dissect.consolidation.util.json_to_entity import JsonToEntity | ||
|
||
|
||
class AsyncPublisher(object): | ||
|
||
def __init__(self, callback): | ||
self.queue = Queue() | ||
self.callback = callback | ||
self._stop_sentinel = None | ||
self.json_to_entity = JsonToEntity() | ||
|
||
def start(self): | ||
self.thread = threading.Thread(target=self._process_queue) | ||
self.thread.setDaemon(True) | ||
self.thread.start() | ||
|
||
def on_entity(self, entity): | ||
self.queue.put(entity) | ||
|
||
def stop(self): | ||
self.queue.put_nowait(self._stop_sentinel) | ||
self.thread.join() | ||
|
||
def _process_queue(self): | ||
while True: | ||
try: | ||
entity = self.queue.get() | ||
if entity is self._stop_sentinel: | ||
return | ||
self.callback(entity) | ||
except KeyError: | ||
pass |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#region GPLv3 notice | ||
# Copyright 2014 Damian Quiroga | ||
# | ||
# This file is part of dissect. | ||
# | ||
# dissect is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# dissect is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with dissect. If not, see <http://www.gnu.org/licenses/>. | ||
#endregion | ||
|
||
import threading | ||
|
||
from dissect.consolidation.async_publisher import AsyncPublisher | ||
from dissect.test.object_factory import fake | ||
from mock import Mock, call | ||
|
||
|
||
class TestAsyncPublisher(object): | ||
def test_it_invokes_the_callback_for_one_entity(self): | ||
# Given | ||
callback = Mock() | ||
fake_entity = fake('Function') | ||
async_publisher = AsyncPublisher(callback) | ||
async_publisher.start() | ||
|
||
# When | ||
async_publisher.on_entity(fake_entity) | ||
async_publisher.stop() | ||
|
||
# Then | ||
callback.assert_called_once_with(fake_entity) | ||
|
||
def test_it_invokes_the_callback_for_two_entities(self): | ||
# Given | ||
callback = Mock() | ||
fake_class = fake('Class_') | ||
fake_function = fake('Function') | ||
async_publisher = AsyncPublisher(callback) | ||
async_publisher.start() | ||
|
||
# When | ||
async_publisher.on_entity(fake_class) | ||
async_publisher.on_entity(fake_function) | ||
async_publisher.stop() | ||
|
||
# Then | ||
callback.assert_has_calls([call(fake_class), | ||
call(fake_function)]) | ||
|
||
def test_on_entity_returns_before_the_callback_completes(self): | ||
# Given | ||
finish = threading.Event() | ||
callback = Mock() | ||
callback.side_effect = lambda entity: finish.wait() | ||
fake_entity = fake('Function') | ||
async_publisher = AsyncPublisher(callback) | ||
async_publisher.start() | ||
|
||
# When | ||
async_publisher.on_entity(fake_entity) | ||
finish.set() | ||
|
||
# Then | ||
async_publisher.stop() |
Oops, something went wrong.