Skip to content

Commit

Permalink
Added ticks counting.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 4, 2006
1 parent c746b6f commit 0807eae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua_glue.c
Expand Up @@ -73,14 +73,17 @@ boolean MojoLua_runFile(const char *basefname)
void MojoLua_collectGarbage(void)
{
lua_State *L = luaState;
uint32 ticks = 0;
int pre = 0;
int post = 0;

STUBBED("logging!");
pre = (lua_gc(L, LUA_GCCOUNT, 0) * 1024) + lua_gc(L, LUA_GCCOUNTB, 0);
printf("Collecting garbage (currently using %d bytes).\n", pre);
ticks = MojoPlatform_ticks();
lua_gc (L, LUA_GCCOLLECT, 0);
printf("Collection finished (took ??? milliseconds).\n"); // !!! FIXME
ticks = MojoPlatform_ticks() - ticks;
printf("Collection finished (took %d milliseconds).\n", (int) ticks);
post = (lua_gc(L, LUA_GCCOUNT, 0) * 1024) + lua_gc(L, LUA_GCCOUNTB, 0);
printf("Now using %d bytes (%d bytes savings).\n", post, pre - post);
} // MojoLua_collectGarbage
Expand Down
2 changes: 2 additions & 0 deletions platform.h
Expand Up @@ -15,6 +15,8 @@ int MojoSetup_main(int argc, char **argv);
// !!! FIXME: is that a good idea?
const char *MojoPlatform_appBinaryPath(void);

uint32 MojoPlatform_ticks(void);

// Get the current locale, in the format "xx_YY" where "xx" is the language
// (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
// can be omitted. Don't include encoding, it's always UTF-8 at this time.
Expand Down
16 changes: 16 additions & 0 deletions platform/unix.c
Expand Up @@ -9,8 +9,12 @@
#include <sys/stat.h>
#include <sys/param.h>

static struct timeval startup_time;


int main(int argc, char **argv)
{
gettimeofday(&startup_time, NULL);
return MojoSetup_main(argc, argv);
} // main

Expand Down Expand Up @@ -167,5 +171,17 @@ boolean MojoPlatform_osVersion(char *buf, size_t len)
return false;
} // MojoPlatform_osversion


uint32 MojoPlatform_ticks(void)
{
uint64 then_ms, now_ms;
struct timeval now;
gettimeofday(&now, NULL);
then_ms = (((uint64) startup_time.tv_sec) * 1000) +
(((uint64) startup_time.tv_usec) / 1000);
now_ms = (((uint64) now.tv_sec) * 1000) + (((uint64) now.tv_usec) / 1000);
return ((uint32) (now_ms - then_ms));
} // MojoPlatform_ticks

// end of unix.c ...

0 comments on commit 0807eae

Please sign in to comment.