
# 11 "plugins/ltac/profile_ltac_tactics.mlg"
 

(** Ltac profiling entrypoints *)

open Profile_tactic
open Stdarg


# 12 "plugins/ltac/profile_ltac_tactics.ml"

let _ = Mltop.add_known_module "rocq-runtime.plugins.ltac"

# 22 "plugins/ltac/profile_ltac_tactics.mlg"
 

let tclSET_PROFILING b =
   Proofview.tclLIFT (Proofview.NonLogical.make (fun () -> set_profiling b))

let tclRESET_PROFILE =
   Proofview.tclLIFT (Proofview.NonLogical.make reset_profile)

let tclSHOW_PROFILE ~cutoff =
   Proofview.tclLIFT (Proofview.NonLogical.make (fun () -> print_results ~cutoff))

let tclSHOW_PROFILE_TACTIC s =
   Proofview.tclLIFT (Proofview.NonLogical.make (fun () -> print_results_tactic s))

let tclRESTART_TIMER s =
   Proofview.tclLIFT (Proofview.NonLogical.make (fun () -> restart_timer s))

let tclFINISH_TIMING ?(prefix="Timer") (s : string option) =
   Proofview.tclLIFT (Proofview.NonLogical.make (fun () -> finish_timing ~prefix s))


# 38 "plugins/ltac/profile_ltac_tactics.ml"

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "start_ltac_profiling" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("start", Tacentries.TyIdent ("ltac", 
                                                         Tacentries.TyIdent ("profiling", 
                                                         Tacentries.TyNil))), 
           (fun ist -> 
# 45 "plugins/ltac/profile_ltac_tactics.mlg"
                                      tclSET_PROFILING true 
# 47 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "stop_ltac_profiling" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("stop", Tacentries.TyIdent ("ltac", 
                                                        Tacentries.TyIdent ("profiling", 
                                                        Tacentries.TyNil))), 
           (fun ist -> 
# 49 "plugins/ltac/profile_ltac_tactics.mlg"
                                     tclSET_PROFILING false 
# 57 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "reset_ltac_profile" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("reset", Tacentries.TyIdent ("ltac", 
                                                         Tacentries.TyIdent ("profile", 
                                                         Tacentries.TyNil))), 
           (fun ist -> 
# 53 "plugins/ltac/profile_ltac_tactics.mlg"
                                    tclRESET_PROFILE 
# 67 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "show_ltac_profile" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("show", Tacentries.TyIdent ("ltac", 
                                                        Tacentries.TyIdent ("profile", 
                                                        Tacentries.TyNil))), 
           (fun ist -> 
# 57 "plugins/ltac/profile_ltac_tactics.mlg"
                                   tclSHOW_PROFILE ~cutoff:None 
# 77 "plugins/ltac/profile_ltac_tactics.ml"
)));
         (Tacentries.TyML (Tacentries.TyIdent ("show", Tacentries.TyIdent ("ltac", 
                                                       Tacentries.TyIdent ("profile", 
                                                       Tacentries.TyIdent ("cutoff", 
                                                       Tacentries.TyArg (
                                                       Extend.TUentry (Genarg.get_arg_tag wit_integer), 
                                                       Tacentries.TyNil))))), 
          (fun n ist -> 
# 58 "plugins/ltac/profile_ltac_tactics.mlg"
                                                       tclSHOW_PROFILE ~cutoff:(Some (float_of_int n)) 
# 88 "plugins/ltac/profile_ltac_tactics.ml"
)));
         (Tacentries.TyML (Tacentries.TyIdent ("show", Tacentries.TyIdent ("ltac", 
                                                       Tacentries.TyIdent ("profile", 
                                                       Tacentries.TyArg (
                                                       Extend.TUentry (Genarg.get_arg_tag wit_string), 
                                                       Tacentries.TyNil)))), 
          (fun s ist -> 
# 59 "plugins/ltac/profile_ltac_tactics.mlg"
                                             tclSHOW_PROFILE_TACTIC s 
# 98 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "restart_timer" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("restart_timer", Tacentries.TyArg (
                                                                 Extend.TUopt (
                                                                 Extend.TUentry (Genarg.get_arg_tag wit_string)), 
                                                                 Tacentries.TyNil)), 
           (fun s ist -> 
# 63 "plugins/ltac/profile_ltac_tactics.mlg"
                                         tclRESTART_TIMER s 
# 109 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Tacentries.tactic_extend "rocq-runtime.plugins.ltac" "finish_timing" ~level:0 
         [(Tacentries.TyML (Tacentries.TyIdent ("finish_timing", Tacentries.TyArg (
                                                                 Extend.TUopt (
                                                                 Extend.TUentry (Genarg.get_arg_tag wit_string)), 
                                                                 Tacentries.TyNil)), 
           (fun s ist -> 
# 67 "plugins/ltac/profile_ltac_tactics.mlg"
                                         tclFINISH_TIMING ~prefix:"Timer" s 
# 120 "plugins/ltac/profile_ltac_tactics.ml"
)));
         (Tacentries.TyML (Tacentries.TyIdent ("finish_timing", Tacentries.TyIdent ("(", 
                                                                Tacentries.TyArg (
                                                                Extend.TUentry (Genarg.get_arg_tag wit_string), 
                                                                Tacentries.TyIdent (")", 
                                                                Tacentries.TyArg (
                                                                Extend.TUopt (
                                                                Extend.TUentry (Genarg.get_arg_tag wit_string)), 
                                                                Tacentries.TyNil))))), 
          (fun prefix s ist -> 
# 68 "plugins/ltac/profile_ltac_tactics.mlg"
                                                                tclFINISH_TIMING ~prefix s 
# 133 "plugins/ltac/profile_ltac_tactics.ml"
)))]

let () = Vernacextend.static_vernac_extend ~plugin:(Some "rocq-runtime.plugins.ltac") ~command:"ResetLtacProfiling" ~classifier:(fun ~atts:_ _ -> Vernacextend.classify_as_sideeff) ?entry:None 
         [(Vernacextend.TyML
         (false,
          Vernacextend.TyTerminal
          ("Reset",
           Vernacextend.TyTerminal
           ("Ltac", Vernacextend.TyTerminal ("Profile", Vernacextend.TyNil))),
          (let coqpp_body () = Vernactypes.vtdefault (fun () -> 
# 72 "plugins/ltac/profile_ltac_tactics.mlg"
                                    reset_profile () 
# 146 "plugins/ltac/profile_ltac_tactics.ml"
) in
            fun ?loc ~atts () ->
            coqpp_body (Attributes.unsupported_attributes atts)),
          None))]

let () = Vernacextend.static_vernac_extend ~plugin:(Some "rocq-runtime.plugins.ltac") ~command:"ShowLtacProfile" ~classifier:(fun ~atts:_ _ -> Vernacextend.classify_as_query) ?entry:None 
         [(Vernacextend.TyML
         (false,
          Vernacextend.TyTerminal
          ("Show",
           Vernacextend.TyTerminal
           ("Ltac", Vernacextend.TyTerminal ("Profile", Vernacextend.TyNil))),
          (let coqpp_body () = Vernactypes.vtdefault (fun () -> 
# 76 "plugins/ltac/profile_ltac_tactics.mlg"
                                   print_results ~cutoff:None 
# 162 "plugins/ltac/profile_ltac_tactics.ml"
) in
            fun ?loc ~atts () ->
            coqpp_body (Attributes.unsupported_attributes atts)),
          None));
         (Vernacextend.TyML
         (false,
          Vernacextend.TyTerminal
          ("Show",
           Vernacextend.TyTerminal
           ("Ltac",
            Vernacextend.TyTerminal
            ("Profile",
             Vernacextend.TyTerminal
             ("CutOff",
              Vernacextend.TyNonTerminal (Extend.TUentry (Genarg.get_arg_tag wit_integer),
              Vernacextend.TyNil))))),
          (let coqpp_body n () = Vernactypes.vtdefault (fun () -> 
# 77 "plugins/ltac/profile_ltac_tactics.mlg"
                                                       print_results ~cutoff:(Some (float_of_int n)) 
# 182 "plugins/ltac/profile_ltac_tactics.ml"
) in
            fun n ?loc ~atts () ->
            coqpp_body n (Attributes.unsupported_attributes atts)),
          None))]

let () = Vernacextend.static_vernac_extend ~plugin:(Some "rocq-runtime.plugins.ltac") ~command:"ShowLtacProfileTactic" ~classifier:(fun ~atts:_ _ -> Vernacextend.classify_as_query) ?entry:None 
         [(Vernacextend.TyML
         (false,
          Vernacextend.TyTerminal
          ("Show",
           Vernacextend.TyTerminal
           ("Ltac",
            Vernacextend.TyTerminal
            ("Profile",
             Vernacextend.TyNonTerminal (Extend.TUentry (Genarg.get_arg_tag wit_string),
             Vernacextend.TyNil)))),
          (let coqpp_body s () = Vernactypes.vtdefault (fun () -> 
# 81 "plugins/ltac/profile_ltac_tactics.mlg"
                                             print_results_tactic s 
# 202 "plugins/ltac/profile_ltac_tactics.ml"
) in
            fun s ?loc ~atts () ->
            coqpp_body s (Attributes.unsupported_attributes atts)),
          None))]

