[test determinator] Refactor Java profiler samples and Java method creation

Summary:
- Putting test determinator in own directory
- Putting Java procname creation stuff in its own module

Reviewed By: skcho

Differential Revision: D17929885

fbshipit-source-id: 4f2578566
master
Dulma Churchill 5 years ago committed by Facebook Github Bot
parent 0149c3171e
commit e5f571b097

@ -219,7 +219,9 @@ let issue_of_cost kind CostIssues.{complexity_increase_issue; zero_issue; infini
| _ ->
""
in
let procname = ExternalPerfData.make_void_signature_procname class_name method_name in
let procname =
JProcname.make_void_signature_procname ~classname:class_name ~methodname:method_name
in
let source_file = SourceFile.create ~warn_on_error:false file in
let issue_type =
if CostItem.is_top curr_item then infinite_issue

@ -58,16 +58,6 @@ let pp_perf_profiler_item itm =
itm.p25_inclusive_cpu_time_ms itm.p25_exclusive_cpu_time_ms
let make_void_signature_procname classname methodname =
let signature = JavaProfilerSamples.JNI.void_method_with_no_arguments in
L.(debug Analysis Medium)
"@\n Making procname with void signature for classname = %s methodname = %s @\n" classname
methodname ;
let procname = JavaProfilerSamples.create_procname ~classname ~methodname ~signature in
L.(debug Analysis Medium) " Resulting procname= %a @\n" Typ.Procname.pp procname ;
procname
let _read_file_perf_data fname =
let perf_profiler_data_str =
match Utils.read_file fname with
@ -81,7 +71,7 @@ let _read_file_perf_data fname =
pp_perf_profiler_item itm ;
match split_class_method_name itm.Perf_profiler_t.function_name with
| Some (classname, methodname) ->
let procname = make_void_signature_procname classname methodname in
let procname = JProcname.make_void_signature_procname ~classname ~methodname in
global_perf_profiler_data :=
PerfProfilerDataMap.add procname itm !global_perf_profiler_data
| _ ->

@ -8,5 +8,3 @@
open! IStd
val in_profiler_data_map : Typ.Procname.t -> bool
val make_void_signature_procname : string -> string -> Typ.Procname.t

@ -47,6 +47,7 @@ depend:
-I IR -I absint -I al -I atd -I backend -I base -I biabduction -I bufferoverrun \
-I checkers -I clang -I concurrency -I facebook -I integration -I istd -I java \
-I labs -I nullsafe -I pulse -I scuba -I quandary -I topl -I unit -I unit/clang -I deadcode \
-I test_determinator \
$(ml_src_files) > deadcode/.depend
# circular dependency... not sure how to fix properly

@ -26,6 +26,7 @@ let source_dirs =
; "pulse"
; "quandary"
; "scuba"
; "test_determinator"
; "topl"
; "unit" ] )

@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
module L = Logging
@ -265,7 +264,8 @@ module JNI = struct
end
end
let create_procname ~classname ~methodname ~signature =
let create_procname ~classname ~methodname ~signature ~use_signature =
let signature = if use_signature then signature else JNI.void_method_with_no_arguments in
let name = Typ.Name.Java.from_string classname in
let args, ret_typ = JNI.parse_method_str signature in
let java_type_args = List.map ~f:JNI.to_java_type args in
@ -281,31 +281,6 @@ let create_procname ~classname ~methodname ~signature =
Typ.Procname.Java.Non_Static)
type labeled_profiler_sample = string * Typ.Procname.Set.t [@@deriving compare]
let equal_labeled_profiler_sample = [%compare.equal: labeled_profiler_sample]
let from_java_profiler_samples j ~use_signature =
let process_methods methods =
Typ.Procname.Set.of_list
(List.map
~f:(fun {Java_profiler_samples_t.classname; methodname; signature} ->
let signature =
if use_signature then signature else JNI.void_method_with_no_arguments
in
create_procname ~classname ~methodname ~signature )
methods)
in
List.map j ~f:(fun {Java_profiler_samples_t.test; methods} -> (test, process_methods methods))
let from_json_string str ~use_signature =
from_java_profiler_samples
(Java_profiler_samples_j.java_profiler_samples_of_string str)
~use_signature
let from_json_file file ~use_signature =
from_java_profiler_samples
(Atdgen_runtime.Util.Json.from_file Java_profiler_samples_j.read_java_profiler_samples file)
~use_signature
let make_void_signature_procname ~classname ~methodname =
let signature = JNI.void_method_with_no_arguments in
create_procname ~signature ~classname ~methodname ~use_signature:true

@ -39,12 +39,7 @@ module JNI : sig
end
end
type labeled_profiler_sample = string * Typ.Procname.Set.t [@@deriving compare]
val create_procname :
classname:string -> methodname:string -> signature:string -> use_signature:bool -> Typ.Procname.t
val equal_labeled_profiler_sample : labeled_profiler_sample -> labeled_profiler_sample -> bool
val from_json_string : string -> use_signature:bool -> labeled_profiler_sample list
val from_json_file : string -> use_signature:bool -> labeled_profiler_sample list
val create_procname : classname:string -> methodname:string -> signature:string -> Typ.Procname.t
val make_void_signature_procname : classname:string -> methodname:string -> Typ.Procname.t

@ -0,0 +1 @@
../java/JProcname.ml

@ -0,0 +1 @@
../java/JProcname.mli

@ -1 +0,0 @@
../java/JavaProfilerSamples.ml

@ -1 +0,0 @@
../java/JavaProfilerSamples.mli

@ -0,0 +1,34 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
type labeled_profiler_sample = string * Typ.Procname.Set.t [@@deriving compare]
let equal_labeled_profiler_sample = [%compare.equal: labeled_profiler_sample]
let from_java_profiler_samples j ~use_signature =
let process_methods methods =
Typ.Procname.Set.of_list
(List.map
~f:(fun {Java_profiler_samples_t.classname; methodname; signature} ->
JProcname.create_procname ~classname ~methodname ~signature ~use_signature )
methods)
in
List.map j ~f:(fun {Java_profiler_samples_t.test; methods} -> (test, process_methods methods))
let from_json_string str ~use_signature =
from_java_profiler_samples
(Java_profiler_samples_j.java_profiler_samples_of_string str)
~use_signature
let from_json_file file ~use_signature =
from_java_profiler_samples
(Atdgen_runtime.Util.Json.from_file Java_profiler_samples_j.read_java_profiler_samples file)
~use_signature

@ -0,0 +1,16 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
type labeled_profiler_sample = string * Typ.Procname.Set.t [@@deriving compare]
val equal_labeled_profiler_sample : labeled_profiler_sample -> labeled_profiler_sample -> bool
val from_json_string : string -> use_signature:bool -> labeled_profiler_sample list
val from_json_file : string -> use_signature:bool -> labeled_profiler_sample list

@ -8,11 +8,10 @@
open! IStd
module L = Logging
module F = Format
module JPS = JavaProfilerSamples
module YB = Yojson.Basic
(* a flag used to make the method search signature sensitive *)
let use_method_signature = false
let use_signature = false
module MethodRangeMap = struct
let split_class_method_name qualified_method_name =
@ -47,13 +46,9 @@ module MethodRangeMap = struct
let classname, methodname = split_class_method_name decl.method_name in
match decl.signature with
| Some signature ->
let signature =
if use_method_signature then signature
else
(* When we should not use the signature we use 'void ()' *)
JPS.JNI.void_method_with_no_arguments
let key =
JProcname.create_procname ~use_signature ~classname ~methodname ~signature
in
let key = JPS.create_procname ~classname ~methodname ~signature in
Typ.Procname.Map.add key range acc
| None ->
acc )
@ -102,7 +97,7 @@ module TestSample = struct
| Some test_samples_file ->
L.(debug TestDeterminator Medium)
"Reading Profiler Samples File '%s'....@\n" test_samples_file ;
JPS.from_json_file test_samples_file ~use_signature:use_method_signature
JavaProfilerSamples.from_json_file test_samples_file ~use_signature
| None ->
L.die UserError "Missing profiler samples argument"

@ -7,7 +7,7 @@
open! IStd
open OUnit2
module T = JavaProfilerSamples.JNI.VISIBLE_FOR_TESTING_DO_NOT_USE_DIRECTLY
module T = JProcname.JNI.VISIBLE_FOR_TESTING_DO_NOT_USE_DIRECTLY
let mk_split (pkg, typ) = Typ.Name.Java.Split.make ?package:pkg typ
@ -100,7 +100,7 @@ let test_jni_parse_str_with_valid_input =
)) ]
, Void ) ] )
; ( "test_jni_parse_str_with_empty_method_signature"
, JavaProfilerSamples.JNI.void_method_with_no_arguments
, JProcname.JNI.void_method_with_no_arguments
, T.[Method ([], Void)] )
; ("test_jni_parse_str_with_empty_input", "", []) ]
|> List.map ~f:(fun (name, test_input, expected_output) ->
@ -174,7 +174,7 @@ let test_from_json_string_with_valid_input =
\"methodOne\",\"signature\": \"%s\",\"wat\": \"\"},{\"class\": \"ddd.eee.Fff\",\"boo\": \
\"\",\"method\": \"methodTwo\",\"signature\": \"(Ljava/lang/String;[IJ)[[C\",\"wat\": \
\"\"}]}]"
JavaProfilerSamples.JNI.void_method_with_no_arguments
JProcname.JNI.void_method_with_no_arguments
in
let expected2 =
[ ( "label1"
@ -264,7 +264,7 @@ let test_from_json_string_with_invalid_input =
, Printf.sprintf
"{\"whatever\": {}, \"methods\": [{\"class\": \"aaa.bbb.Ccc\", \"boo\": \"\", \"method\": \
\"methodOne\", \"signature\": \"%s\"}], \"foo\": {}}"
JavaProfilerSamples.JNI.void_method_with_no_arguments
JProcname.JNI.void_method_with_no_arguments
, Yojson.Json_error
"Line 1, bytes 0-33:\nExpected '[' but found '{\"whatever\": {}, \"methods\": [{\"cl'" )
; ( "test_from_json_string_3"

Loading…
Cancel
Save