Skip to content
Open
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
7 changes: 4 additions & 3 deletions linesman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from inspect import getmodule

import networkx as nx
import networkx.drawing.nx_agraph


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +49,7 @@ def draw_graph(graph, output_path):
``output_path``:
Location to store the rendered output.
"""
nx.to_agraph(graph).draw(output_path, prog="dot")
networkx.drawing.nx_agraph.to_agraph(graph).draw(output_path, prog="dot")
log.info("Wrote output to `%s'" % output_path)


Expand Down Expand Up @@ -85,7 +86,7 @@ def create_graph(stats):
'reccallcount': stat.reccallcount,
'totaltime': stat.totaltime,
}
g.add_node(caller_key, attr_dict=attrs)
g.add_node(caller_key, **attrs)

# Add all the calls as edges
for call in stat.calls or []:
Expand All @@ -102,7 +103,7 @@ def create_graph(stats):
g.add_edge(caller_key, callee_key,
weight=call.totaltime,
label=call.totaltime,
attr_dict=call_attrs)
**call_attrs)

return g

Expand Down
2 changes: 1 addition & 1 deletion linesman/backends/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# You should have received a copy of the GNU General Public License along
# with linesman. If not, see <http://www.gnu.org/licenses/>.
#
import cPickle
import logging

from six.moves import cPickle
from linesman.backends.base import Backend


Expand Down
2 changes: 1 addition & 1 deletion linesman/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# You should have received a copy of the GNU General Public License along
# with linesman. If not, see <http://www.gnu.org/licenses/>.
#
import cPickle
import logging
import sqlite3
import time

from six.moves import cPickle
from linesman.backends.base import Backend


Expand Down
26 changes: 20 additions & 6 deletions linesman/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tempfile import gettempdir

from PIL import Image
from networkx.classes.reportviews import InDegreeView
import networkx as nx
from mako.lookup import TemplateLookup
from paste.urlparser import StaticURLParser
Expand All @@ -30,6 +31,13 @@
from linesman import ProfilingSession, draw_graph


_pil_major = int(Image.__version__.split(".")[0])
if _pil_major >= 10:
ANTIALIAS = Image.Resampling.LANCZOS
else:
ANTIALIAS = Image.ANTIALIAS


log = logging.getLogger(__name__)

# Graphs
Expand Down Expand Up @@ -250,7 +258,7 @@ def render_graph(self, req):
log.debug("Creating thumbnail for %s at %s.", session_uuid,
thumbnail_path)
im = Image.open(path, 'r')
im.thumbnail((600, 600), Image.ANTIALIAS)
im.thumbnail((600, 600), ANTIALIAS)
im.save(thumbnail_path)

return StaticURLParser(GRAPH_DIR)
Expand Down Expand Up @@ -438,13 +446,19 @@ def prepare_graph(source_graph, cutoff_time, break_cycles=False):
# Break cycles
if break_cycles:
for cycle in nx.simple_cycles(graph):
u, v = cycle[0], cycle[1]
if graph.has_edge(u, v):
graph.remove_edge(u, v)
cyclic_breaks.append((u, v))
end = len(cycle) - 1 if len(cycle) > 1 else 1
for i in range(end):
u = cycle[i]
if len(cycle) == 1:
v = u
else:
v = cycle[i + 1]
if graph.has_edge(u, v):
graph.remove_edge(u, v)
cyclic_breaks.append((u, v))

root_nodes = [node
for node, degree in graph.in_degree_iter()
for node, degree in InDegreeView(graph)
if degree == 0]

return graph, root_nodes, cyclic_breaks
Expand Down
2 changes: 1 addition & 1 deletion linesman/templates/tree.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%def name="print_tree(node)">
<%
node_obj = graph.node[node]
node_obj = graph._node[node]
total_time_percentage = round(node_obj.get('totaltime') / session.duration * 100, 2)
inline_time_percentage = round(node_obj.get('inlinetime') / session.duration * 100, 2)
open_or_leaf = 'open' if graph.neighbors(node) else 'leaf'
Expand Down
2 changes: 1 addition & 1 deletion linesman/tests/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestGraphUtils(unittest.TestCase):

@patch("networkx.to_agraph")
@patch("networkx.drawing.nx_agraph.to_agraph")
def test_draw_graph(self, mock_to_agraph):
""" Test that the graph gets converted to an agraph """
mock_draw = Mock()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import sys

install_requires = ["mako", "networkx==1.7", "pillow", "pygraphviz", 'Paste', 'WebOb']
install_requires = ["mako", "networkx>=2.0", "pillow", "pygraphviz", 'Paste', 'WebOb', 'six']

# ordereddict is required for versions < 2.7; its included in collections in
# versions 2.7+ and 3.0+
Expand Down