Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Oct 23, 2022
1 parent 1af40cc commit a343a59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions tests/FSharp.Compiler.Service.Tests2/DepResolving.fs
Expand Up @@ -339,7 +339,6 @@ module internal AutomatedDependencyResolving =
DepsResult.Files = nodes
DepsResult.Graph = graph
}
log "Done"
res

/// <summary>
Expand Down Expand Up @@ -383,4 +382,4 @@ let analyseEfficiency (result : DepsResult) : unit =
|> Array.map (fun f -> depthDfs f.Idx)
|> Array.max

printfn $"Total file size: {totalFileSize}. Max depth: {maxDepth}. Max Depth/Size = %.2f{double(maxDepth) / double(totalFileSize)}"
log $"Total file size: {totalFileSize}. Max depth: {maxDepth}. Max Depth/Size = %.1f{100.0 * double(maxDepth) / double(totalFileSize)}%%"
1 change: 1 addition & 0 deletions tests/FSharp.Compiler.Service.Tests2/Program.fs
Expand Up @@ -11,6 +11,7 @@ let main _ =
TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
//runCompiler ()
//TestDepResolving.TestHardcodedFiles()
printfn ""
TestDepResolving.TestProject(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")
//RunCompiler.runGrapher()
0
19 changes: 10 additions & 9 deletions tests/FSharp.Compiler.Service.Tests2/TestDepResolving.fs
Expand Up @@ -107,20 +107,19 @@ let TestHardcodedFiles() =
analyseEfficiency graph

let private parseProjectAndGetSourceFiles (projectFile : string) =
log "building project"
let m = AnalyzerManager()
let analyzer = m.GetProject(projectFile)
let results = analyzer.Build()
// TODO Generalise for multiple TFMs
let res = results.Results |> Seq.head
let files = res.SourceFiles
log "built"
log "built project using Buildalyzer"
files

[<TestCase(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")>]
[<TestCase(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")>]
let TestProject (projectFile : string) =
log "start"
log $"Start finding file dependency graph for {projectFile}"
let files = parseProjectAndGetSourceFiles projectFile
let files =
files
Expand All @@ -130,22 +129,24 @@ let TestProject (projectFile : string) =
{Name = f; Code = code; AST = ast}
)
|> Array.filter (fun x ->
ASTVisit.extractModuleRefs x.AST
|> Array.forall (function | ReferenceOrAbbreviation.Reference _ -> true | ReferenceOrAbbreviation.Abbreviation _ -> false)
true
//ASTVisit.extractModuleRefs x.AST
//|> Array.forall (function | ReferenceOrAbbreviation.Reference _ -> true | ReferenceOrAbbreviation.Abbreviation _ -> false)
)
let N = files.Length
log $"{N} files read and parsed"

let graph = AutomatedDependencyResolving.detectFileDependencies files
log "deps detected"
log "Deps detected"

let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(idx, deps)) -> deps.Length)
let maxPossibleDeps = (N * (N-1)) / 2

let graphJson = graph.Graph |> Seq.map (fun (KeyValue(idx, deps)) -> graph.Files[idx].Name, deps |> Array.map (fun d -> graph.Files[d].Name)) |> dict
let json = JsonConvert.SerializeObject(graphJson, Formatting.Indented)
System.IO.File.WriteAllText("deps_graph.json", json)
let path = $"{System.IO.Path.GetFileName(projectFile)}.deps.json"
System.IO.File.WriteAllText(path, json)

printfn $"Analysed {N} files, detected {totalDeps}/{maxPossibleDeps} file dependencies."
printfn "Wrote graph as json in deps_graph.json"
log $"Analysed {N} files, detected {totalDeps}/{maxPossibleDeps} file dependencies (%.1f{100.0 * double(totalDeps) / double(maxPossibleDeps)}%%)."
log $"Wrote graph in {path}"
analyseEfficiency graph

0 comments on commit a343a59

Please sign in to comment.