[Avida-cvs] [Avida2-svn] r274 - trunk/source/cpu

kaben@myxo.css.msu.edu kaben at myxo.css.msu.edu
Thu Aug 4 16:02:53 PDT 2005


Author: kaben
Date: 2005-08-04 19:02:52 -0400 (Thu, 04 Aug 2005)
New Revision: 274

Modified:
   trunk/source/cpu/cpu_test_info.cc
   trunk/source/cpu/cpu_test_info.hh
   trunk/source/cpu/hardware_4stack.cc
   trunk/source/cpu/hardware_base.cc
   trunk/source/cpu/hardware_base.hh
   trunk/source/cpu/hardware_cpu.cc
   trunk/source/cpu/hardware_status_printer.cc
   trunk/source/cpu/test_cpu.cc
Log:

Restored hardware status printing.



Modified: trunk/source/cpu/cpu_test_info.cc
===================================================================
--- trunk/source/cpu/cpu_test_info.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/cpu_test_info.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -25,6 +25,7 @@
   , trace_task_order(false)
   , use_random_inputs(false)
   , org_array(max_tests)
+  , m_tracer(NULL)
 {
   org_array.SetAll(NULL);
   Clear();
@@ -55,15 +56,13 @@
 }
  
 
-void cCPUTestInfo::SetTraceExecution(const cString & filename)
+void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
 {
-  trace_execution = true;
-  trace_fp.open(filename);
-  assert (trace_fp.good() == true); // Unable to open trace file.
+  trace_execution = (tracer)?(true):(false);
+  m_tracer = tracer;
 }
 
 
-
 double cCPUTestInfo::GetGenotypeFitness()
 {
   if (org_array[0] != NULL) return org_array[0]->GetPhenotype().GetFitness();

Modified: trunk/source/cpu/cpu_test_info.hh
===================================================================
--- trunk/source/cpu/cpu_test_info.hh	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/cpu_test_info.hh	2005-08-04 23:02:52 UTC (rev 274)
@@ -8,8 +8,6 @@
 #ifndef CPU_TEST_INFO_HH
 #define CPU_TEST_INFO_HH
 
-#include <fstream>
-
 #ifndef CPU_DEFS_HH
 #include "cpu_defs.hh"
 #endif
@@ -20,6 +18,7 @@
 #include "tArray.hh"
 #endif
 
+class cHardwareTracer;
 class cOrganism;
 class cString;
 
@@ -33,7 +32,7 @@
   bool trace_execution;       // Should we trace this CPU?
   bool trace_task_order;      // Should we keep track of ordering of tasks?
   bool use_random_inputs;     // Should we give the organism random inputs?
-  std::ofstream trace_fp;
+  cHardwareTracer *m_tracer;
 
   // Outputs...
   bool is_viable;         // Is this organism colony forming?
@@ -58,7 +57,7 @@
   void PrintThreads(bool _print=true) { print_threads = _print; }
   void TraceTaskOrder(bool _trace=true) { trace_task_order = _trace; }
   void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; }
-  void SetTraceExecution(const cString & filename="trace.dat");
+  void SetTraceExecution(cHardwareTracer *tracer = NULL);
 
   // Input Accessors
   int GetGenerationTests() const { return generation_tests; }
@@ -67,7 +66,7 @@
   bool GetTraceTaskOrder() const { return trace_task_order; }
   bool GetUseRandomInputs() const { return use_random_inputs; }
   bool GetTraceExecution() const { return trace_execution; }
-  std::ofstream & GetTraceFP() { return trace_fp; }
+  cHardwareTracer *GetTracer() { return m_tracer; }
 
 
   // Output Accessors

Modified: trunk/source/cpu/hardware_4stack.cc
===================================================================
--- trunk/source/cpu/hardware_4stack.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/hardware_4stack.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -376,8 +376,13 @@
 #endif
     
     // Print the status of this CPU at each step...
-    const cString & next_name = inst_set->GetName(IP().GetInst())();
-    if (trace_fp != NULL) organism->PrintStatus(*trace_fp, next_name);
+    if (m_tracer != NULL) {
+      if (cHardwareTracer_4Stack * tracer
+          = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+      ){
+        tracer->TraceHardware_4Stack(*this);
+      }
+    }
     
     // Find the instruction to be executed
     const cInstruction & cur_inst = IP().GetInst();
@@ -484,10 +489,14 @@
 
   // @CAO FIX PRINTING TO INDICATE THIS IS A BONUS
   // Print the status of this CPU at each step...
-  cString next_name = cStringUtil::Stringf("%s (bonus instruction)",
-					   inst_set->GetName(inst)());
-  if (trace_fp != NULL) organism->PrintStatus(*trace_fp, next_name);
-      
+  if (m_tracer != NULL) {
+    if (cHardwareTracer_4Stack * tracer
+        = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+    ){
+      tracer->TraceHardware_4StackBonus(*this);
+    }
+  }
+    
   SingleProcess_ExecuteInst(inst);
 
   organism->SetRunning(prev_run_state);

Modified: trunk/source/cpu/hardware_base.cc
===================================================================
--- trunk/source/cpu/hardware_base.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/hardware_base.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -17,7 +17,7 @@
   : organism(in_organism)
   , inst_set(in_inst_set)
   , viewer_lock(-1)
-  , trace_fp(NULL)
+  , m_tracer(NULL)
 {
   assert(inst_set->OK());
   assert(organism != NULL);

Modified: trunk/source/cpu/hardware_base.hh
===================================================================
--- trunk/source/cpu/hardware_base.hh	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/hardware_base.hh	2005-08-04 23:02:52 UTC (rev 274)
@@ -31,7 +31,7 @@
   int viewer_lock;            // Used if the viewer should only lock onto
                               //  one aspect of the hardware.
 
-  ostream * trace_fp;         // Set this if you want execution traced.
+  cHardwareTracer * m_tracer;         // Set this if you want execution traced.
 
   static int instance_count;
 public:
@@ -73,7 +73,7 @@
   virtual void SaveState(std::ostream & fp) = 0;
   virtual void LoadState(std::istream & fp) = 0;
 
-  void SetTrace(ostream * in_fp) { trace_fp = in_fp; }
+  void SetTrace(cHardwareTracer * tracer) { m_tracer = tracer; }
 
 
   // --------  Mutations (Must be Virtual)  --------

Modified: trunk/source/cpu/hardware_cpu.cc
===================================================================
--- trunk/source/cpu/hardware_cpu.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/hardware_cpu.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -476,9 +476,13 @@
 #endif
     
     // Print the status of this CPU at each step...
-    const cString & next_name = inst_set->GetName(IP().GetInst())();
-    if (trace_fp != NULL) organism->PrintStatus(*trace_fp, next_name);
-
+    if (m_tracer != NULL) {
+      if (cHardwareTracer_CPU * tracer
+          = dynamic_cast<cHardwareTracer_CPU *>(m_tracer)
+      ){
+        tracer->TraceHardware_CPU(*this);
+      }
+    }
     
     // Find the instruction to be executed
     const cInstruction & cur_inst = IP().GetInst();
@@ -586,9 +590,13 @@
 
   // @CAO FIX PRINTING TO INDICATE THIS IS A BONUS
   // Print the status of this CPU at each step...
-  cString next_name = cStringUtil::Stringf("%s (bonus instruction)",
-					   inst_set->GetName(inst)());
-  if (trace_fp != NULL) organism->PrintStatus(*trace_fp, next_name);
+  if (m_tracer != NULL) {
+    if (cHardwareTracer_CPU * tracer
+        = dynamic_cast<cHardwareTracer_CPU *>(m_tracer)
+    ){
+      tracer->TraceHardware_CPUBonus(*this);
+    }
+  }
     
   SingleProcess_ExecuteInst(inst);
 

Modified: trunk/source/cpu/hardware_status_printer.cc
===================================================================
--- trunk/source/cpu/hardware_status_printer.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/hardware_status_printer.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -65,14 +65,14 @@
   const cString &child_memory
 ){
   if (time_used == time_allocated) {
-    m_trace_fp << endl << "TIMEOUT: No offspring produced." << endl;
+    m_trace_fp << endl << "# TIMEOUT: No offspring produced." << endl;
   }
   else if (size == 0) {
-    m_trace_fp << endl << "ORGANISM DEATH: No offspring produced." << endl;
+    m_trace_fp << endl << "# ORGANISM DEATH: No offspring produced." << endl;
   }
   else {
     m_trace_fp
-    << endl << "Final Memory: " << final_memory
-    << endl << "Child Memory: " << child_memory << endl;
+    << endl << "# Final Memory: " << final_memory
+    << endl << "# Child Memory: " << child_memory << endl;
   }
 }

Modified: trunk/source/cpu/test_cpu.cc
===================================================================
--- trunk/source/cpu/test_cpu.cc	2005-08-04 15:38:52 UTC (rev 273)
+++ trunk/source/cpu/test_cpu.cc	2005-08-04 23:02:52 UTC (rev 274)
@@ -142,17 +142,18 @@
 
   // Prepare the inputs...
   cur_input = 0;
+  cur_receive = 0;
 
   // Determine if we're tracing and what we need to print.
-  ostream * trace_fp =
-    test_info.GetTraceExecution() ? &(test_info.GetTraceFP()) : NULL;
+  cHardwareTracer * tracer =
+    test_info.GetTraceExecution() ? (test_info.GetTracer()) : NULL;
 
   int time_used = 0;
   while (time_used < time_allocated &&
 	 organism.GetHardware().GetMemory().GetSize() &&
 	 organism.GetPhenotype().GetNumDivides() == 0) {
     time_used++;
-    organism.GetHardware().SetTrace(trace_fp);
+    organism.GetHardware().SetTrace(tracer);
     organism.GetHardware().SingleProcess();
     organism.GetHardware().SetTrace(NULL);
     //resource_count.Update(1/cConfig::GetAveTimeslice());
@@ -160,24 +161,22 @@
   }
 
   // Print out some final info in trace...
-  if (trace_fp != NULL) {
-    if (time_used == time_allocated) {
-      *trace_fp << endl << "# TIMEOUT: No offspring produced." << endl;
+  if (tracer != NULL) {
+    if (cHardwareTracer_TestCPU * tracer_test_cpu
+        = dynamic_cast<cHardwareTracer_TestCPU *>(tracer)
+    ){
+      tracer_test_cpu->TraceHardware_TestCPU(
+        time_used,
+        time_allocated,
+        organism.GetHardware().GetMemory().GetSize(),
+        organism.GetHardware().GetMemory().AsString(),
+        organism.ChildGenome().AsString()
+      );
     }
-    else if (organism.GetHardware().GetMemory().GetSize() == 0) {
-      *trace_fp << endl << "# ORGANISM DEATH: No offspring produced." << endl;
-    }
-    else {
-      *trace_fp << endl << "# Final Memory: "
-		<< organism.GetHardware().GetMemory().AsString() << endl
-		<< "# Child Memory: " << organism.ChildGenome().AsString()
-		<< endl;
-    }
   }
 
   // For now, always return true.
   return true;
-
 }
 
 




More information about the Avida-cvs mailing list