Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin J. Thompson
Tor
Commits
2123f0a2
Commit
2123f0a2
authored
9 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Make the callgraph module-aware
parent
3014bfb6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/maint/analyze_callgraph.py
+45
-5
45 additions, 5 deletions
scripts/maint/analyze_callgraph.py
scripts/maint/display_callgraph.py
+2
-0
2 additions, 0 deletions
scripts/maint/display_callgraph.py
with
47 additions
and
5 deletions
scripts/maint/analyze_callgraph.py
+
45
−
5
View file @
2123f0a2
...
...
@@ -9,19 +9,28 @@ import os
class
Parser
:
def
__init__
(
self
):
self
.
calls
=
{}
self
.
definedIn
=
{}
def
enter_func
(
self
,
name
):
if
self
.
infunc
and
not
self
.
extern
:
if
self
.
infunc
and
not
self
.
extern
and
self
.
calledfns
:
if
self
.
infunc
in
self
.
definedIn
:
#print "{}: {} or {}?".format(
# self.infunc, self.definedIn[self.infunc], self.module)
self
.
definedIn
[
self
.
infunc
]
=
'
nil
'
else
:
self
.
definedIn
[
self
.
infunc
]
=
self
.
module
self
.
calls
.
setdefault
(
self
.
infunc
,
set
()).
update
(
self
.
calledfns
)
self
.
calledfns
=
set
()
self
.
infunc
=
name
self
.
extern
=
False
def
parse_callgraph_file
(
self
,
inp
):
def
parse_callgraph_file
(
self
,
inp
,
module
):
self
.
infunc
=
None
self
.
extern
=
False
self
.
calledfns
=
set
()
self
.
module
=
module
for
line
in
inp
:
m
=
re
.
match
(
r
"
Call graph node for function:
'
([^
'
]+)
'"
,
line
)
if
m
:
...
...
@@ -189,13 +198,27 @@ def connection_bottlenecks(callgraph):
if
__name__
==
'
__main__
'
:
p
=
Parser
()
for
fname
in
sys
.
argv
[
1
:]:
modname
=
re
.
sub
(
r
'
.*/
'
,
''
,
fname
).
replace
(
'
.callgraph
'
,
'
.c
'
)
with
open
(
fname
,
'
r
'
)
as
f
:
p
.
parse_callgraph_file
(
f
)
p
.
parse_callgraph_file
(
f
,
modname
)
sys
.
stdout
.
flush
sys
.
stdout
.
flush
()
print
"
Building callgraph
"
callgraph
=
p
.
extract_callgraph
()
inModule
=
p
.
definedIn
print
"
Deriving module callgraph
"
modCallgraph
=
{}
for
fn
in
callgraph
:
fnMod
=
inModule
[
fn
]
for
called
in
callgraph
[
fn
]:
try
:
calledMod
=
inModule
[
called
]
except
KeyError
:
continue
modCallgraph
.
setdefault
(
fnMod
,
set
()).
add
(
calledMod
)
del
modCallgraph
[
'
nil
'
]
print
"
Finding strongly connected components
"
sccs
=
strongly_connected_components
(
callgraph
)
...
...
@@ -206,11 +229,28 @@ if __name__ == '__main__':
print
"
Finding bottlenecks...
"
bottlenecks
=
connection_bottlenecks
(
callgraph
)
print
"
Finding module SCCs
"
modSCCS
=
strongly_connected_components
(
modCallgraph
)
print
"
Finding module TC
"
modTC
=
transitive_closure
(
modCallgraph
)
print
"
Finding module bottlenecks
"
modB
=
connection_bottlenecks
(
modCallgraph
)
data
=
{
'
callgraph
'
:
callgraph
,
'
sccs
'
:
sccs
,
'
closure
'
:
closure
,
'
bottlenecks
'
:
bottlenecks
}
'
bottlenecks
'
:
bottlenecks
,
'
modules
'
:
p
.
definedIn
,
'
modItems
'
:
{
'
callgraph
'
:
modCallgraph
,
'
sccs
'
:
modSCCS
,
'
closure
'
:
modTC
,
'
bottlenecks
'
:
modB
,
}
}
with
open
(
'
callgraph.pkl
'
,
'
w
'
)
as
f
:
cPickle
.
dump
(
data
,
f
)
...
...
This diff is collapsed.
Click to expand it.
scripts/maint/display_callgraph.py
+
2
−
0
View file @
2123f0a2
...
...
@@ -4,6 +4,8 @@ import cPickle
data
=
cPickle
.
load
(
open
(
"
callgraph.pkl
"
))
# data = data['modItems']
callgraph
=
data
[
'
callgraph
'
]
closure
=
data
[
'
closure
'
]
sccs
=
data
[
'
sccs
'
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment