[Freeciv-Dev] [PATCH] CHRONO
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch changes CHRONO to use getrusage and implements handy
macros. With getrusage you are somewhat immune to other load on
the machine. Macro interface is somewhat tricky. But I think
that should not be problem, as this interface is purely to
developers.
1999-06-27 Markus Linnala <maage@xxxxxxxxx>
* ai/aiunit.c (ai_manage_units): use new chrono
* server/autoattack.c (auto_attack): use new chrono
* server/settlers.c (auto_settlers_player): use new chrono
* ai/aiunit.c, server/autoattack.c, server/settlers.c: include chrono.h
* common/chrono.h: new file
(CHRONO_START): macro to start
(CHRONO_END): macro to end
diff -u --recursive --new-file --exclude-from=.diffignore --exclude=support
freeciv-cvs/ai/aiunit.c freeciv-chrono/ai/aiunit.c
--- freeciv-cvs/ai/aiunit.c Thu Jun 24 14:55:19 1999
+++ freeciv-chrono/ai/aiunit.c Sun Jun 27 20:49:21 1999
@@ -16,11 +16,11 @@
#include <string.h>
#include <assert.h>
-#ifdef CHRONO
-#include <sys/time.h>
-#include <unistd.h>
+#if 0
+#define CHRONO 1
#endif
+#include "chrono.h"
#include "city.h"
#include "game.h"
#include "log.h"
@@ -1518,12 +1518,8 @@
void ai_manage_units(struct player *pplayer)
{
-#ifdef CHRONO
- int sec, usec;
- struct timeval tv;
- gettimeofday(&tv, 0);
- sec = tv.tv_sec; usec = tv.tv_usec;
-#endif
+ CHRONO_START
+
freelog(LOG_DEBUG, "Managing units for %s", pplayer->name);
unit_list_iterate(pplayer->units, punit) {
freelog(LOG_DEBUG, "Managing %s's %s %d@(%d,%d)", pplayer->name,
@@ -1534,11 +1530,8 @@
}
unit_list_iterate_end;
freelog(LOG_DEBUG, "Managed units successfully.");
-#ifdef CHRONO
- gettimeofday(&tv, 0);
- freelog(LOG_VERBOSE, "%s's units consumed %ld microseconds.", pplayer->name,
- (long)((tv.tv_sec - sec) * 1000000 + (tv.tv_usec - usec)));
-#endif
+
+ CHRONO_END("%s's autosettlers consumed",, pplayer->name)
}
/**************************************************************************
diff -u --recursive --new-file --exclude-from=.diffignore --exclude=support
freeciv-cvs/common/chrono.h freeciv-chrono/common/chrono.h
--- freeciv-cvs/common/chrono.h Thu Jan 1 02:00:00 1970
+++ freeciv-chrono/common/chrono.h Sun Jun 27 20:47:52 1999
@@ -0,0 +1,48 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__CHRONO_H
+#define FC__CHRONO_H
+
+#if defined(CHRONO) && defined(__GNUC__)
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+#define CHRONO_START \
+ long chrono_u_sec, chrono_s_sec; \
+ long chrono_u_usec, chrono_s_usec; \
+ struct rusage rv; \
+ getrusage(RUSAGE_SELF, &rv); \
+ chrono_u_sec = rv.ru_utime.tv_sec; \
+ chrono_u_usec = rv.ru_utime.tv_usec; \
+ chrono_s_sec = rv.ru_stime.tv_sec; \
+ chrono_s_usec = rv.ru_stime.tv_usec;
+
+#define CHRONO_END(mess, args...) \
+ getrusage(RUSAGE_SELF, &rv); \
+ freelog(LOG_VERBOSE, mess " user: %ld µs system: %ld µs.\n" \
+ ##args, \
+ (rv.ru_utime.tv_sec - chrono_u_sec) * 1000000 + \
+ (rv.ru_utime.tv_usec - chrono_u_usec), \
+ (rv.ru_stime.tv_sec - chrono_s_sec) * 1000000 + \
+ (rv.ru_stime.tv_usec - chrono_s_usec));
+
+#else
+
+#define CHRONO_START
+#define CHRONO_END(mess)
+
+#endif
+
+#endif /* FC__CHRONO_H */
diff -u --recursive --new-file --exclude-from=.diffignore --exclude=support
freeciv-cvs/server/autoattack.c freeciv-chrono/server/autoattack.c
--- freeciv-cvs/server/autoattack.c Thu Jun 24 14:55:20 1999
+++ freeciv-chrono/server/autoattack.c Sun Jun 27 20:50:52 1999
@@ -29,11 +29,11 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef CHRONO
-#include <sys/time.h>
-#include <unistd.h>
+#if 0
+#define CHRONO 1
#endif
+#include "chrono.h"
#include "events.h"
#include "game.h"
#include "log.h"
@@ -240,12 +240,8 @@
void auto_attack(void)
{
int i;
-#if CHRONO
- int sec, usec;
- struct timeval tv;
- gettimeofday(&tv, 0);
- sec = tv.tv_sec; usec = tv.tv_usec;
-#endif
+
+ CHRONO_START
/* re-use shuffle order from civserver.c */
for (i = 0; i < game.nplayers; i++) {
@@ -253,10 +249,5 @@
auto_attack_player(shuffled[i]);
}
}
-
-#if CHRONO
- gettimeofday(&tv, 0);
- freelog(LOG_VERBOSE, "autoattack consumed %ld microseconds.",
- (long)((tv.tv_sec - sec) * 1000000 + (tv.tv_usec - usec)));
-#endif
+ CHRONO_END("autoattack consumed", "")
}
diff -u --recursive --new-file --exclude-from=.diffignore --exclude=support
freeciv-cvs/server/settlers.c freeciv-chrono/server/settlers.c
--- freeciv-cvs/server/settlers.c Thu Jun 24 14:55:21 1999
+++ freeciv-chrono/server/settlers.c Sun Jun 27 20:50:32 1999
@@ -14,11 +14,11 @@
#include <string.h>
#include <assert.h>
-#ifdef CHRONO
-#include <sys/time.h>
-#include <unistd.h>
+#if 0
+#define CHRONO 1
#endif
+#include "chrono.h"
#include "game.h"
#include "log.h"
#include "map.h"
@@ -1175,12 +1175,8 @@
**************************************************************************/
void auto_settlers_player(struct player *pplayer)
{
-#ifdef CHRONO
- int sec, usec;
- struct timeval tv;
- gettimeofday(&tv, 0);
- sec = tv.tv_sec; usec = tv.tv_usec;
-#endif
+ CHRONO_START
+
city_list_iterate(pplayer->cities, pcity)
initialize_infrastructure_cache(pcity); /* saves oodles of time -- Syela */
city_list_iterate_end;
@@ -1204,12 +1200,7 @@
}
}
unit_list_iterate_end;
-#ifdef CHRONO
- gettimeofday(&tv, 0);
- freelog(LOG_VERBOSE, "%s's autosettlers consumed %ld microseconds.",
- pplayer->name, (long)((tv.tv_sec - sec) * 1000000
- + (tv.tv_usec - usec)));
-#endif
+ CHRONO_END("%s's autosettlers consumed",, pplayer->name)
}
void assign_settlers_player(struct player *pplayer)
--
//Markus
- [Freeciv-Dev] [PATCH] CHRONO,
Markus Linnala <=
|
|