michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef timecard_h__ michael@0: #define timecard_h__ michael@0: michael@0: #include michael@0: #include "prtime.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: #define STAMP_TIMECARD(card,event) \ michael@0: do { \ michael@0: if (card) { \ michael@0: stamp_timecard((card), (event), __FILE__, __LINE__, __FUNCTION__); \ michael@0: } \ michael@0: } while (0) michael@0: michael@0: #define TIMECARD_INITIAL_TABLE_SIZE 16 michael@0: michael@0: /* michael@0: * The "const char *" members of this structure point to static strings. michael@0: * We do not own them, and should not attempt to deallocate them. michael@0: */ michael@0: michael@0: typedef struct { michael@0: PRTime timestamp; michael@0: const char *event; michael@0: const char *file; michael@0: unsigned int line; michael@0: const char *function; michael@0: } TimecardEntry; michael@0: michael@0: typedef struct Timecard { michael@0: size_t curr_entry; michael@0: size_t entries_allocated; michael@0: TimecardEntry *entries; michael@0: PRTime start_time; michael@0: } Timecard; michael@0: michael@0: /** michael@0: * Creates a new Timecard structure for tracking events. michael@0: */ michael@0: Timecard * michael@0: create_timecard(); michael@0: michael@0: /** michael@0: * Frees the memory associated with a timecard. After returning, the michael@0: * timecard pointed to by tc is no longer valid. michael@0: */ michael@0: void michael@0: destroy_timecard(Timecard *tc); michael@0: michael@0: /** michael@0: * Records a new event in the indicated timecard. This should not be michael@0: * called directly; code should instead use the STAMP_TIMECARD macro, michael@0: * above. michael@0: */ michael@0: void michael@0: stamp_timecard(Timecard *tc, michael@0: const char *event, michael@0: const char *file, michael@0: unsigned int line, michael@0: const char *function); michael@0: michael@0: /** michael@0: * Formats and outputs the contents of a timecard onto stdout. michael@0: */ michael@0: void michael@0: print_timecard(Timecard *tc); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif