Jelajahi Sumber

Memory Profiling

Snej69420 4 bulan lalu
induk
melakukan
e2eda2ffb2
2 mengubah file dengan 46 tambahan dan 46 penghapusan
  1. 27 27
      src/AtomicDEVS.jl
  2. 19 19
      src/CoupledDEVS.jl

+ 27 - 27
src/AtomicDEVS.jl

@@ -28,7 +28,7 @@ time_advance(agent, model) = error("time_advance not implemented for $(typeof(ag
 output!(agent, model) = nothing
 
 function simulate_devs!(model, duration::Float64=Inf)
-#     @timeit Timer "Simulation Loop" begin
+    @timeit Timer "Simulation Loop" begin
         if model.logging !== nothing && isempty(model.event_logs)
             if model.logging == ""
                 print_initial_conditions(model)
@@ -58,14 +58,14 @@ function simulate_devs!(model, duration::Float64=Inf)
                 export_trace_to_csv(model, model.logging)
             end
         end
-#     end
-#     show(Timer)
-#     println()
-#     reset_timer!(Timer)
+    end
+    show(Timer)
+    println()
+    reset_timer!(Timer)
 end
 
 function send_message!(agent, model, port::Symbol, msg)
-#     @timeit Timer "Send Message" begin
+    @timeit Timer "Send Message" begin
         if model.logging !== nothing
             if !haskey(model.out_log, agent.id)
                 model.out_log[agent.id] = Dict{Symbol, Vector{Any}}()
@@ -90,7 +90,7 @@ function send_message!(agent, model, port::Symbol, msg)
                 end
             end
         end
-#     end
+    end
 end
 
 function route_outputs!(model)
@@ -171,33 +171,33 @@ function transition!(model, current_time, triggering_agent_id)
     empty!(model.requeue_buffer)
 
     for id in model.imminent
-#         @timeit Timer "Process Imminent" process_imminent!(
-#             model[id],
-#             model,
-#             current_time,
-#             triggering_agent_id
-#         )
-        process_imminent!(
+        @timeit Timer "Process Imminent" process_imminent!(
             model[id],
             model,
             current_time,
             triggering_agent_id
         )
-    end
-
-    for id in model.active_receivers
-#         @timeit Timer "Process Receivers" process_receiver!(
+#         process_imminent!(
 #             model[id],
 #             model,
 #             current_time,
 #             triggering_agent_id
 #         )
-        process_receiver!(
+    end
+
+    for id in model.active_receivers
+        @timeit Timer "Process Receivers" process_receiver!(
             model[id],
             model,
             current_time,
             triggering_agent_id
         )
+#         process_receiver!(
+#             model[id],
+#             model,
+#             current_time,
+#             triggering_agent_id
+#         )
     end
 
     for id in model.imminent
@@ -211,13 +211,13 @@ function transition!(model, current_time, triggering_agent_id)
     empty!(model.imminent)
     empty!(model.active_receivers)
 
-#     @timeit Timer "Requeue Events" begin
+    @timeit Timer "Requeue Events" begin
         for req_id in model.requeue_buffer
             agent = model[req_id]
-            Agents.add_event!(agent, model)
-#             @timeit Timer "Agents.jl Add Event" Agents.add_event!(agent, model)
+#             Agents.add_event!(agent, model)
+            @timeit Timer "Agents.jl Add Event" Agents.add_event!(agent, model)
         end
-#     end
+    end
 end
 
 function devs_step!(agent, model)
@@ -247,10 +247,10 @@ function devs_step!(agent, model)
     end
 
     if is_last_in_batch && !isempty(model.imminent)
-#         @timeit Timer "Route Outputs" route_outputs!(model)
-#         @timeit Timer "Transitions" transition!(model, current_time, agent.id)
-        route_outputs!(model)
-        transition!(model, current_time, agent.id)
+        @timeit Timer "Route Outputs" route_outputs!(model)
+        @timeit Timer "Transitions" transition!(model, current_time, agent.id)
+#         route_outputs!(model)
+#         transition!(model, current_time, agent.id)
     end
 end
 

+ 19 - 19
src/CoupledDEVS.jl

@@ -185,8 +185,8 @@ function build_standalone_agents(top_model::CoupledDEVS; routing_tables=Dict{Int
     path_to_id = Dict{String, Int}()
     current_id = Ref(1)
 
-    instantiate_tree!(top_model, string(top_model.name), path_to_id, agent_list, current_id, routing_tables)
-#     @timeit Builder "Instantiate Tree" instantiate_tree!(top_model, string(top_model.name), path_to_id, agent_list, current_id, routing_tables)
+#     instantiate_tree!(top_model, string(top_model.name), path_to_id, agent_list, current_id, routing_tables)
+    @timeit Builder "Instantiate Tree" instantiate_tree!(top_model, string(top_model.name), path_to_id, agent_list, current_id, routing_tables)
 
     return agent_list, path_to_id
 end
@@ -314,17 +314,17 @@ function build_routing_tables(couplings::Dict, agent_list)
 end
 
 function compile_devs(top_model::CoupledDEVS; logging::Union{Nothing, String}=nothing)
-#     @timeit Builder "Compile DEVS" begin
-        dummy_agents, path_to_id = build_standalone_agents(top_model)
-#         @timeit Builder "Build Dummy Agents" dummy_agents, path_to_id = build_standalone_agents(top_model)
+    @timeit Builder "Compile DEVS" begin
+#         dummy_agents, path_to_id = build_standalone_agents(top_model)
+        @timeit Builder "Build Dummy Agents" dummy_agents, path_to_id = build_standalone_agents(top_model)
 
         # Resolve direct couplings using raw data (NO EventQueueABM creation!)$
-        couplings = resolve_direct_couplings(top_model, path_to_id, dummy_agents)
-        routing_tables = build_routing_tables(couplings, dummy_agents)
-        final_agents, final_paths = build_standalone_agents(top_model; routing_tables=routing_tables)
-#         @timeit Builder "Resolve Couplings" couplings = resolve_direct_couplings(top_model, path_to_id, dummy_agents)
-#         @timeit Builder "Build Routing Tables" routing_tables = build_routing_tables(couplings, dummy_agents)
-#         @timeit Builder "Build Final Agents" final_agents, final_paths = build_standalone_agents(top_model; routing_tables=routing_tables)
+#         couplings = resolve_direct_couplings(top_model, path_to_id, dummy_agents)
+#         routing_tables = build_routing_tables(couplings, dummy_agents)
+#         final_agents, final_paths = build_standalone_agents(top_model; routing_tables=routing_tables)
+        @timeit Builder "Resolve Couplings" couplings = resolve_direct_couplings(top_model, path_to_id, dummy_agents)
+        @timeit Builder "Build Routing Tables" routing_tables = build_routing_tables(couplings, dummy_agents)
+        @timeit Builder "Build Final Agents" final_agents, final_paths = build_standalone_agents(top_model; routing_tables=routing_tables)
 
         unique_types = unique(typeof(a) for a in final_agents)
         AgentUnion = Union{unique_types...}
@@ -334,17 +334,17 @@ function compile_devs(top_model::CoupledDEVS; logging::Union{Nothing, String}=no
             logging = logging,
             path_to_id = final_paths
         )
-        final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props, autogenerate_after_action = false)
-#         @timeit Builder "Build Model" final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props)
+#         final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props, autogenerate_after_action = false)
+        @timeit Builder "Build Model" final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props)
 
         typed_agents = Vector{AgentUnion}(final_agents)
         for agent in typed_agents
-            add_agent!(agent, final_model)
-#             @timeit Builder "Agents.jl Add Agent" add_agent!(agent, final_model)
+#             add_agent!(agent, final_model)
+            @timeit Builder "Agents.jl Add Agent" add_agent!(agent, final_model)
         end
-#     end
-#     show(Builder)
-#     println()
-#     reset_timer!(Builder)
+    end
+    show(Builder)
+    println()
+    reset_timer!(Builder)
     return final_model
 end