Improve logging a bit more

Per Inge Mathisen <per-0/[email protected]> Mon, 21 Mar 2005 14:09:55 +0000 (GMT)
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
Add more TIMING_LOG calls around, and fix a smallish problem with
TIMING_LOG itself.

  - Per
logging.diff (text/plain, 2.6 KB)
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.60
diff -u -r1.60 aidata.c
--- ai/aidata.c	21 Mar 2005 13:38:11 -0000	1.60
+++ ai/aidata.c	21 Mar 2005 14:08:47 -0000
@@ -223,6 +223,8 @@
       } movemap_vector_iterate_end;
     }
   } whole_map_iterate_end;
+
+  TIMING_LOG(LOG_DEBUG, NULL, "Done generating movemap");
 }
 
 /**************************************************************************
@@ -396,6 +398,8 @@
 
   /*** Threats ***/
 
+  TIMING_LOG(LOG_DEBUG, pplayer, "Generating aidata");
+
   ai->num_continents    = map.num_continents;
   ai->num_oceans        = map.num_oceans;
   ai->threats.continent = fc_calloc(ai->num_continents + 1, sizeof(bool));
@@ -633,8 +637,6 @@
   ai->angry_priority = TRADE_WEIGHTING * 3; /* grave danger */
   ai->pollution_priority = POLLUTION_WEIGHTING;
 
-  ai_best_government(pplayer);
-
   /*** Interception engine ***/
 
   /* We are tracking a unit if punit->ai.cur_pos is not NULL. If we
@@ -665,6 +667,9 @@
   } else {
     ai->wants_no_science = FALSE;
   }
+
+  /* Government */
+  ai_best_government(pplayer);
 }
 
 /**************************************************************************
Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.108
diff -u -r1.108 aihand.c
--- ai/aihand.c	21 Mar 2005 12:55:06 -0000	1.108
+++ ai/aihand.c	21 Mar 2005 14:08:47 -0000
@@ -286,6 +286,7 @@
   }
 
   if (ai->govt_reeval == 0) {
+    TIMING_LOG(LOG_DEBUG, pplayer, "Finding best government");
     government_iterate(gov) {
       int val = 0;
       int dist;
Index: ai/ailog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/ailog.c,v
retrieving revision 1.21
diff -u -r1.21 ailog.c
--- ai/ailog.c	21 Mar 2005 13:38:11 -0000	1.21
+++ ai/ailog.c	21 Mar 2005 14:08:47 -0000
@@ -258,6 +258,7 @@
   char buffer[500];
   int minlevel = MIN(LOGLEVEL_BODYGUARD, level);
   static struct timer *t = NULL;
+  static int turn = -1;
 
   if (t == NULL) {
     t = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
@@ -270,6 +271,12 @@
     return;
   }
 
+  /* So that the first log won't be displayed ridiculously high */
+  if (turn != game.turn) {
+    turn = game.turn;
+    clear_timer_start(t);
+  }
+
   my_snprintf(buffer, sizeof(buffer), "... %g seconds. %s: ",
               read_timer_seconds(t), pplayer ? pplayer->name : "(all)");
   clear_timer_start(t);