Blender Logic Source
Without using a script, you can create a tick count property and use the property actuator to increment it each frame. With the always sensor you can set the frequency (now called skip) to trigger the update every frame, or two frames...



If you place that in a common object that is always in the game, such as the ground, when you want to know the tick count in a script you can get the ground object from the scene.

scn = bge.logic.getCurrentScene()
grnd = scn['ground']
tick_count = grnd['ticker']


For forking your own version of blender, you will find the main loop at the bottom of wm.c. You can add a property to the GameData struct in DNA_scene_types.h, then add it in rna_scene.c to access it via python. Note that changes to any structs need to maintain a multiple of eight bytes in length for alignment, builds will fail if you don't get it right, and moving any existing properties will break reading blend files. It has been a while since I looked at this so I may be missing a change needed, start here for info about changing the data structures.