-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Dependency cycles can be bad for Flow performance. This diff introduces a new subcommand that makes it easier to extract useful information from Flow's dependency information. In particular, users can point to any file in a cycle and the command will output a DOT file to stdout. This file can be fed into a program like Gephi to to further analysis. Reviewed By: gabelevi Differential Revision: D6202923 fbshipit-source-id: 94f6c7862443f0cf0ee8fbfdd22e79504e584dda
- Loading branch information
1 parent
622bbc4
commit e6a10b1
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*) | ||
|
||
open CommandUtils | ||
|
||
let print_endlinef = Utils_js.print_endlinef | ||
let prerr_endlinef = Utils_js.prerr_endlinef | ||
|
||
let spec = { | ||
CommandSpec. | ||
name = "cycle"; | ||
doc = "Output .dot file for cycle containing the given file"; | ||
usage = Printf.sprintf | ||
"Usage: %s cycle [OPTION]...\n\n\ | ||
e.g. %s cycle path/to/file.js \n" | ||
Utils_js.exe_name | ||
Utils_js.exe_name; | ||
args = CommandSpec.ArgSpec.( | ||
empty | ||
|> server_flags | ||
|> root_flag | ||
|> strip_root_flag | ||
|> anon "FILE..." (required string) | ||
~doc:"File contained in the cycle" | ||
) | ||
} | ||
|
||
let main option_values root strip_root file () = | ||
let file = expand_path file in | ||
let root = guess_root root in | ||
let strip_root f = | ||
if strip_root | ||
then Files.relative_path (Path.to_string root) f | ||
else f | ||
in | ||
(* connect to server *) | ||
let request = ServerProt.Request.CYCLE file in | ||
match connect_and_make_request option_values root request with | ||
| ServerProt.Response.CYCLE (Error msg) -> | ||
prerr_endline msg | ||
| ServerProt.Response.CYCLE (Ok dep_graph) -> | ||
(* print .dot file to stdout *) | ||
print_endline "digraph {"; | ||
List.iter (fun (f, dep_fs) -> | ||
List.iter (fun dep_f -> | ||
print_endlinef " \"%s\" -> \"%s\"" | ||
(strip_root f) | ||
(strip_root dep_f) | ||
) dep_fs | ||
) dep_graph; | ||
print_endline "}" | ||
| response -> failwith_bad_response ~request ~response | ||
|
||
let command = CommandSpec.command spec main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters