Просмотр исходного кода

added profiling option for Agents and added simulator used to output csv

Snej69420 6 месяцев назад
Родитель
Сommit
41333ba427
2 измененных файлов с 22 добавлено и 16 удалено
  1. 17 15
      benchmarks/Agents/main.jl
  2. 5 1
      benchmarks/testPyPDEVS.py

+ 17 - 15
benchmarks/Agents/main.jl

@@ -59,6 +59,9 @@ function parse_commandline()
         "--stats", "-s"
             help = "Enable Event Tracking"
             action = :store_true
+        "--profile", "-P"
+            help = "Runs the simulation with a simple Profiler"
+            action = :store_true
         "--logging", "-L"
             help = "Enables and print model traces to the console"
             action = :store_true
@@ -72,7 +75,7 @@ function parse_commandline()
 end
 
 # --- Single Simulation Runner ---
-function run_single_simulation(topology_type::Structure, type_str::String, depth::Int, width::Int, stats::Bool, logging::Bool)
+function run_single_simulation(topology_type::Structure, type_str::String, depth::Int, width::Int, stats::Bool, logging::Bool, profile::Bool)
     int_delay = 0.0
     ext_delay = 0.0
 
@@ -84,19 +87,17 @@ function run_single_simulation(topology_type::Structure, type_str::String, depth
 
     # Setup
     AgentUnion = Union{DelayedAtomic, Generator}
-    model = compile_devs(env, AgentUnion, (UniversalEvent, ); logging)
+    model = compile_devs(env, AgentUnion, (UniversalEvent, ); logging=false)
     engine_setup_time = time()
 
-#     simulate_devs!(warmup)
-#     model = compile_devs(env, AgentUnion, (UniversalEvent, ); logging=false)
-
-#     Profile.clear()
-
-    # Simulate
-    simulate_devs!(model)
-#     @profile simulate_devs!(model)
+    if profile
+#         Profile.clear()
+        @time simulate_devs!(model)
+#         Profile.print(format=:flat, sortedby=:count)
+    else
+        simulate_devs!(model)
+    end
     sim_time = time()
-#     Profile.print(format=:flat, sortedby=:count)
 
     t_creation = model_created_time - start_time
     t_setup = engine_setup_time - model_created_time
@@ -110,6 +111,7 @@ function main()
     args = parse_commandline()
     stats = args["stats"]
     logging = args["logging"]
+    profile = args["profile"]
 
     # Process step sizes
     ds = args["depth-stepsize"] > 0 ? args["depth-stepsize"] : args["max-depth"]
@@ -138,7 +140,7 @@ function main()
         open(file_path, file_mode) do file
             # Write Header if new file
             if !args["append"] || filesize(file_path) == 0
-                write(file, "model_type,depth,width,run,creation_time,setup_time,simulation_time\n")
+                write(file, "simulator,model_type,depth,width,run,creation_time,setup_time,simulation_time\n")
             end
 
             # Grid Search Loop
@@ -152,14 +154,14 @@ function main()
 
                         # WARM-UP PASS (Only for the very first execution of the script to compile)
                         if run == 0 && depth == ds && width == ws && repetitions != 1
-                            run_single_simulation(topology_type, model_str, 2, 2, false, false)
+                            run_single_simulation(topology_type, model_str, 2, 2, false, false, false)
                         end
 
                         # Actual measured run
-                        t_creation, t_setup, t_sim, model = run_single_simulation(topology_type, model_str, depth, width, stats, logging)
+                        t_creation, t_setup, t_sim, model = run_single_simulation(topology_type, model_str, depth, width, stats, logging, profile)
 
                         # Log to CSV
-                        write(file, "$model_str,$depth,$width,$run,$t_creation,$t_setup,$t_sim\n")
+                        write(file, "agents,$model_str,$depth,$width,$run,$t_creation,$t_setup,$t_sim\n")
 
                         if args["output"] || args["stats"]
                             println("  Creation: $(round(t_creation, digits=4))s | Setup: $(round(t_setup, digits=4))s | Sim: $(round(t_sim, digits=4))s")

+ 5 - 1
benchmarks/testPyPDEVS.py

@@ -211,6 +211,7 @@ def run(writer, csvfile, model_type, d, w, args, mem_cmd, extra):
                 # Only write to CSV if a writer was provided
                 if writer and creation is not None:
                     row = {
+                        "simulator": sim_id,
                         "model_type": model_type, "depth": depth, "width": width, "run": run,
                         "creation_time": creation, "setup_time": setup, "simulation_time": sim,
                     }
@@ -232,14 +233,17 @@ if __name__ == "__main__":
     if w[0] % w[1] != 0:
         raise RuntimeError("Invalid width stepsize.")
 
-    fieldnames = ["model_type", "depth", "width", "run",
+    fieldnames = ["simulator", "model_type", "depth", "width", "run",
                   "creation_time", "setup_time", "simulation_time"]
+
     mode = args.mode
     if mode == "dynamic":
         if args.classic:
             mode += "-classic"
         fieldnames += ["number", "generator_mode"]
 
+    sim_id = f"pypdevs-{mode}"
+
     extra = {
         "classic": False if not hasattr(args, "classic") else args.classic,
         "gen_mode": "uniform" if not hasattr(args, "gen_mode") else args.gen_mode,