Skip to content

Commit

Permalink
use set of source paths open-telemetry#2
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelewski committed May 31, 2023
1 parent f7de5e2 commit 2a250cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
52 changes: 26 additions & 26 deletions instrgen/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func usage() error {
func makeAnalysis(projectPaths []string, packagePattern string, debug bool, instrgenLog *bufio.Writer) *alib.PackageAnalysis {
var rootFunctions []alib.FuncDescriptor

interfaces := alib.FindInterfaces(projectPaths[0], packagePattern, instrgenLog)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths[0], packagePattern, "AutotelEntryPoint", instrgenLog)...)
funcDecls := alib.FindFuncDecls(projectPaths[0], packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths[0], packagePattern, funcDecls, interfaces, instrgenLog)
interfaces := alib.FindInterfaces(projectPaths, packagePattern, instrgenLog)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths, packagePattern, "AutotelEntryPoint", instrgenLog)...)
funcDecls := alib.FindFuncDecls(projectPaths, packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths, packagePattern, funcDecls, interfaces, instrgenLog)
fmt.Fprintln(instrgenLog, "\n\tchild parent")
for k, v := range backwardCallGraph {
fmt.Fprint(instrgenLog, "\n\t", k)
Expand Down Expand Up @@ -94,19 +94,19 @@ func Prune(projectPaths []string, packagePattern string, debug bool, instrgenLog
return analysis.Execute(&alib.OtelPruner{}, otelPrunerPassSuffix)
}

func makeCallGraph(projectPath string, packagePattern string, instrgenLog *bufio.Writer) map[alib.FuncDescriptor][]alib.FuncDescriptor {
func makeCallGraph(projectPaths []string, packagePattern string, instrgenLog *bufio.Writer) map[alib.FuncDescriptor][]alib.FuncDescriptor {
var funcDecls map[alib.FuncDescriptor]bool
var backwardCallGraph map[alib.FuncDescriptor][]alib.FuncDescriptor

interfaces := alib.FindInterfaces(projectPath, packagePattern, instrgenLog)
funcDecls = alib.FindFuncDecls(projectPath, packagePattern, interfaces, instrgenLog)
backwardCallGraph = alib.BuildCallGraph(projectPath, packagePattern, funcDecls, interfaces, instrgenLog)
interfaces := alib.FindInterfaces(projectPaths, packagePattern, instrgenLog)
funcDecls = alib.FindFuncDecls(projectPaths, packagePattern, interfaces, instrgenLog)
backwardCallGraph = alib.BuildCallGraph(projectPaths, packagePattern, funcDecls, interfaces, instrgenLog)
return backwardCallGraph
}

func makeRootFunctions(projectPath string, packagePattern string, instrgenLog *bufio.Writer) []alib.FuncDescriptor {
func makeRootFunctions(projectPaths []string, packagePattern string, instrgenLog *bufio.Writer) []alib.FuncDescriptor {
var rootFunctions []alib.FuncDescriptor
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPath, packagePattern, "AutotelEntryPoint", instrgenLog)...)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths, packagePattern, "AutotelEntryPoint", instrgenLog)...)
return rootFunctions
}

Expand Down Expand Up @@ -175,11 +175,11 @@ func executeCommand(command string, projectPaths []string, packagePattern string
fmt.Println("\tinstrumentation done")
return nil
case "--dumpcfg":
backwardCallGraph := makeCallGraph(projectPaths[0], packagePattern, instrgenLog)
backwardCallGraph := makeCallGraph(projectPaths, packagePattern, instrgenLog)
dumpCallGraph(backwardCallGraph, instrgenLog)
return nil
case "--rootfunctions":
rootFunctions := makeRootFunctions(projectPaths[0], packagePattern, instrgenLog)
rootFunctions := makeRootFunctions(projectPaths, packagePattern, instrgenLog)
dumpRootFunctions(rootFunctions, instrgenLog)
return nil
case "--prune":
Expand All @@ -190,7 +190,7 @@ func executeCommand(command string, projectPaths []string, packagePattern string
fmt.Println("\tprune done")
return nil
case "--generatecfg":
backwardCallGraph := makeCallGraph(projectPaths[0], packagePattern, instrgenLog)
backwardCallGraph := makeCallGraph(projectPaths, packagePattern, instrgenLog)
alib.GenerateForwardCfg(backwardCallGraph, "cfg")
return nil
case "--server":
Expand Down Expand Up @@ -242,10 +242,10 @@ func reqInject(projectPaths []string, packagePattern string, w http.ResponseWrit
log.Fatal(err)
}
var rootFunctions []alib.FuncDescriptor
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths[0], packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths[0], packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths[0], packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths[0], packagePattern, funcDecls, interfaces, instrgenLog)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths, packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths, packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths, packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths, packagePattern, funcDecls, interfaces, instrgenLog)
fmt.Fprintln(instrgenLog, "\n\tchild parent")
for k, v := range backwardCallGraph {
fmt.Fprint(instrgenLog, "\n\t", k)
Expand All @@ -269,10 +269,10 @@ func reqInject(projectPaths []string, packagePattern string, w http.ResponseWrit
{
// reload
var rootFunctions []alib.FuncDescriptor
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths[0], packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths[0], packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths[0], packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths[0], packagePattern, funcDecls, interfaces, instrgenLog)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths, packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths, packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths, packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths, packagePattern, funcDecls, interfaces, instrgenLog)
alib.GenerateForwardCfg(backwardCallGraph, "./static/index.html")
w.WriteHeader(200)
}
Expand All @@ -288,10 +288,10 @@ func reqPrune(projectPaths []string, packagePattern string, w http.ResponseWrite
}
// reload
var rootFunctions []alib.FuncDescriptor
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths[0], packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths[0], packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths[0], packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths[0], packagePattern, funcDecls, interfaces, instrgenLog)
rootFunctions = append(rootFunctions, alib.FindRootFunctions(projectPaths, packagePattern, "AutotelEntryPoint", instrgenLog)...)
interfaces := alib.FindInterfaces(projectPaths, packagePattern, instrgenLog)
funcDecls := alib.FindFuncDecls(projectPaths, packagePattern, interfaces, instrgenLog)
backwardCallGraph := alib.BuildCallGraph(projectPaths, packagePattern, funcDecls, interfaces, instrgenLog)

alib.GenerateForwardCfg(backwardCallGraph, "./static/index.html")

Expand Down Expand Up @@ -406,7 +406,7 @@ func reqTerminal(projectPaths []string, packagePattern string, w http.ResponseWr
}

func server(projectPaths []string, packagePattern string, instrgenLog *bufio.Writer) {
backwardCallGraph := makeCallGraph(projectPaths[0], packagePattern, instrgenLog)
backwardCallGraph := makeCallGraph(projectPaths, packagePattern, instrgenLog)
alib.GenerateForwardCfg(backwardCallGraph, "./static/index.html")
var fileOffset int64
fileOffset = 0
Expand Down
16 changes: 8 additions & 8 deletions instrgen/lib/callgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func getPkgs(projectPath string, packagePattern string, fset *token.FileSet, ins
// FindRootFunctions looks for all root functions eg. entry points.
// Currently an entry point is a function that contains call of function
// passed as functionLabel paramaterer.
func FindRootFunctions(projectPath string, packagePattern string, functionLabel string, instrgenLog *bufio.Writer) []FuncDescriptor {
func FindRootFunctions(projectPaths []string, packagePattern string, functionLabel string, instrgenLog *bufio.Writer) []FuncDescriptor {
fset := token.NewFileSet()
pkgs, _ := getPkgs(projectPath, packagePattern, fset, instrgenLog)
pkgs, _ := getPkgs(projectPaths[0], packagePattern, fset, instrgenLog)
var currentFun FuncDescriptor
var rootFunctions []FuncDescriptor
for _, pkg := range pkgs {
Expand Down Expand Up @@ -261,12 +261,12 @@ func GetPkgPathForFunction(pkg *packages.Package,
// BuildCallGraph builds an information about flow graph
// in the following form child->parent.
func BuildCallGraph(
projectPath string,
projectPaths []string,
packagePattern string,
funcDecls map[FuncDescriptor]bool,
interfaces map[string]bool, instrgenLog *bufio.Writer) map[FuncDescriptor][]FuncDescriptor {
fset := token.NewFileSet()
pkgs, _ := getPkgs(projectPath, packagePattern, fset, instrgenLog)
pkgs, _ := getPkgs(projectPaths[0], packagePattern, fset, instrgenLog)
fmt.Fprint(instrgenLog, "BuildCallGraph")
currentFun := FuncDescriptor{"nil", "", false}
backwardCallGraph := make(map[FuncDescriptor][]FuncDescriptor)
Expand Down Expand Up @@ -326,9 +326,9 @@ func BuildCallGraph(
}

// FindFuncDecls looks for all function declarations.
func FindFuncDecls(projectPath string, packagePattern string, interfaces map[string]bool, instrgenLog *bufio.Writer) map[FuncDescriptor]bool {
func FindFuncDecls(projectPaths []string, packagePattern string, interfaces map[string]bool, instrgenLog *bufio.Writer) map[FuncDescriptor]bool {
fset := token.NewFileSet()
pkgs, _ := getPkgs(projectPath, packagePattern, fset, instrgenLog)
pkgs, _ := getPkgs(projectPaths[0], packagePattern, fset, instrgenLog)
fmt.Fprintln(instrgenLog, "FindFuncDecls")
funcDecls := make(map[FuncDescriptor]bool)
for _, pkg := range pkgs {
Expand All @@ -353,9 +353,9 @@ func FindFuncDecls(projectPath string, packagePattern string, interfaces map[str
}

// FindInterfaces looks for all interfaces.
func FindInterfaces(projectPath string, packagePattern string, instrgenLog *bufio.Writer) map[string]bool {
func FindInterfaces(projectPaths []string, packagePattern string, instrgenLog *bufio.Writer) map[string]bool {
fset := token.NewFileSet()
pkgs, _ := getPkgs(projectPath, packagePattern, fset, instrgenLog)
pkgs, _ := getPkgs(projectPaths[0], packagePattern, fset, instrgenLog)
fmt.Fprintln(instrgenLog, "FindInterfaces")
interaceTable := make(map[string]bool)
for _, pkg := range pkgs {
Expand Down

0 comments on commit 2a250cc

Please sign in to comment.