Bläddra i källkod

added some stats

Nicolas Cannasse 13 år sedan
förälder
incheckning
f882badb8a
4 ändrade filer med 29 tillägg och 4 borttagningar
  1. 15 0
      common.ml
  2. 10 4
      main.ml
  3. 3 0
      typeload.ml
  4. 1 0
      typer.ml

+ 15 - 0
common.ml

@@ -44,6 +44,13 @@ type basic_types = {
 	mutable tarray : t -> t;
 }
 
+type stats = {
+	s_files_parsed : int ref;
+	s_classes_built : int ref;
+	s_methods_typed : int ref;
+	s_macros_called : int ref;
+}
+
 type context = {
 	(* config *)
 	version : int;
@@ -88,6 +95,14 @@ exception Abort of string * Ast.pos
 let display_default = ref false
 let default_print = ref print_string
 
+let stats =
+	{
+		s_files_parsed = ref 0;
+		s_classes_built = ref 0;
+		s_methods_typed = ref 0;
+		s_macros_called = ref 0;
+	}
+
 let create v args =
 	let m = Type.mk_mono() in
 	{

+ 10 - 4
main.ml

@@ -532,6 +532,10 @@ and wait_loop boot_com host port =
 				Parser.resume_display := Ast.null_pos;
 				measure_times := false;
 				close_times();
+				stats.s_files_parsed := 0;
+				stats.s_classes_built := 0;
+				stats.s_methods_typed := 0;
+				stats.s_macros_called := 0;
 				Hashtbl.clear Common.htimers;
 				let _ = Common.timer "other" in
 				Hashtbl.clear modules_added;
@@ -543,13 +547,15 @@ and wait_loop boot_com host port =
 				if verbose then print_endline ("Completion Response =\n" ^ str);
 				ssend sin str
 			);
-			if verbose then Printf.printf "Time spent : %.3fs\n" (get_time() -. t0);
+			if verbose then begin
+				print_endline (Printf.sprintf "Stats = %d files, %d classes, %d methods, %d macros" !(stats.s_files_parsed) !(stats.s_classes_built) !(stats.s_methods_typed) !(stats.s_macros_called));
+				print_endline (Printf.sprintf "Time spent : %.3fs" (get_time() -. t0));
+			end
 		with Unix.Unix_error _ ->
 			if verbose then print_endline "Connection Aborted");
-		if verbose then print_endline "Closing connection";
 		Unix.close sin;
 		(* prevent too much fragmentation by doing some compactions every X run *)
-		incr run_count;		
+		incr run_count;
 		if !run_count mod 1 = 50 then begin
 			let t0 = get_time() in
 			Gc.compact();
@@ -558,7 +564,7 @@ and wait_loop boot_com host port =
 				let size = (float_of_int stat.Gc.heap_words) *. 4. in
 				print_endline (Printf.sprintf "Compacted memory %.3fs %.1fMB" (get_time() -. t0) (size /. (1024. *. 1024.)));
 			end
-		end
+		end else Gc.minor();
 	done
 
 and do_connect host port args =

+ 3 - 0
typeload.ml

@@ -25,6 +25,7 @@ let parse_file com file p =
 	let ch = (try open_in_bin file with _ -> error ("Could not open " ^ file) p) in
 	let t = Common.timer "parsing" in
 	Lexer.init file;
+	incr stats.s_files_parsed;
 	let data = (try Parser.parse com (Lexing.from_channel ch) with e -> close_in ch; t(); raise e) in
 	close_in ch;
 	t();
@@ -736,6 +737,7 @@ let build_module_def ctx mt meta fvars fbuild =
 		display_error ctx msg p
 
 let init_class ctx c p herits fields =
+	incr stats.s_classes_built;
 	let fields = patch_class ctx c fields in
 	let ctx = { ctx with type_params = c.cl_types } in
 	c.cl_extern <- List.mem HExtern herits;
@@ -974,6 +976,7 @@ let init_class ctx c p herits fields =
 			} in
 			let r = exc_protect (fun r ->
 				r := (fun() -> t);
+				incr stats.s_methods_typed;
 				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ s_type_path c.cl_path ^ "." ^ name);
 				let e , fargs = type_function ctx args ret (if constr then FConstructor else if stat then FStatic else FMember) fd p in
 				let f = {

+ 1 - 0
typer.ml

@@ -2459,6 +2459,7 @@ let load_macro ctx cpath f p =
 	t();
 	let call args =
 		let t = macro_timer ctx (s_type_path cpath ^ "." ^ f) in
+		incr stats.s_macros_called;
 		let r = Interp.call_path mctx ((fst cpath) @ [snd cpath]) f args api in
 		t();
 		r