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

Running callGraph on mac #1

Closed
lukemmtt opened this issue Jul 27, 2021 · 3 comments
Closed

Running callGraph on mac #1

lukemmtt opened this issue Jul 27, 2021 · 3 comments

Comments

@lukemmtt
Copy link

lukemmtt commented Jul 27, 2021

Hi there,

This is a very useful looking tool, but I'm having trouble running it on mac.

I've run brew install graphviz as well as sudo cpan install GraphViz, copied callGraph's executable into /usr/local/Cellar/graphviz/2.48.0/bin, and called it like so, with the following error:

macbook ~ % callgraph /Users/username/Developer/Project/FileToGraph.swift
ERROR: Install GraphViz and the CPAN GraphViz module to create the call graph
sudo apt-get install Graphviz
and
sudo cpan install GraphViz

Am I doing something wrong? Is it possible to use callGraph on macOS?

Thanks,
Luke

@koknat
Copy link
Owner

koknat commented Jul 28, 2021

Hi,
I don't have a mac, but I'd like to help you figure this out.
The message is printed because the perl eval fails:

eval 'use GraphViz ()';
if ($@) {
say "ERROR: Install GraphViz and the CPAN GraphViz module to create the call graph";
...
}

To troubleshoot, you could try to get a basic Perl GraphViz example running

@lukemmtt
Copy link
Author

lukemmtt commented Jul 28, 2021

Thanks for the pointer: that helped a lot and I got everything working.

Side note: This tool works fantastically well—thank you!

Here's the output generated for my project. It's a bit cluttered, but all-encompassing and extremely helpful.
CallGraphSwiftOutput

———
For the record, here's some background on how I got this working.

Full disclosure: I'm out of my element here—I know nothing about Perl, GraphViz, or how any of these things are supposed to work together on Mac. I basically just followed the error messages and moved files to where the errors told me they should be. Ugly and wrong, yes, but it works for now.

Things I tried:

  1. brew install graphviz
  2. sudo cpan install GraphViz
  3. Downloaded callGraph, perl_call_graph, graphviz-perl, and IPC-Run directly.
  4. Ran perl_call_graph, which returned the following error

user@lmbp ~ % /Users/user/Downloads/callGraph-main/perl_call_graph-master/bin/perl_call_graph
Can't locate GraphViz.pm in @inc (you may need to install the GraphViz module) (@inc contains: /Library/Perl/5.30/darwin-thread-multi-2level [...]

  1. Navigated to /Library/Perl/5.30 and transferred the IPC-Run and GraphViz components there
  2. Ran perl_call_graph again, this time successfully

user@lmbp ~ % /Users/lukememet/Downloads/callGraph-main/perl_call_graph-master/bin/perl_call_graph
Please specify some files to parse!

  1. Ran callGraph successfully

user@lmbp ~ % callGraph /Users/user/Developer/Project/Models/DataModel.swift
Generating: /tmp/call_graph_rdzg/DataModel.swift.dot
Converting to /tmp/call_graph_rdzg/DataModel.swift.png
Displaying /tmp/call_graph_rdzg/DataModel.swift.png using 'open'

Lastly, to generate the image shown above, I navigated to my project's directory, searched for all .swift files within the directory, selected all of them, typed callGraph in terminal, drag & dropped the selected files into terminal and hit enter.

@koknat
Copy link
Owner

koknat commented Jul 28, 2021

I'm glad you were able to figure it out.
Thank you for providing your notes.

You may be able to clean up your image by providing options such as:
-start __MAIN__ -ignore '(topViewController|dateStringForDate)'

I've enhanced the callGraph error message to include the "@inc contains" message

If anyone else has problems getting Perl GraphViz to work, I suggest creating the Perl GraphViz example program "Graphviz_example.pl" to aid in troubleshooting:

use GraphViz;
my $g = GraphViz->new();
$g->add_node('London');
$g->add_node('Paris', label => 'City of\nlurve');
$g->add_node('New York');
$g->add_edge('London' => 'Paris');
$g->add_edge('London' => 'New York', label => 'Far');
$g->add_edge('Paris' => 'London');
print $g->as_png;

Save this in a text editor and run it using:
perl Graphviz_example.pl > Graphviz_example.png

Once this works, then 'callGraph' should also work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants