tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

timecard.h (1975B)


      1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef timecard_h__
      8 #define timecard_h__
      9 
     10 #include "prtime.h"
     11 
     12 #ifdef __cplusplus
     13 extern "C" {
     14 #endif
     15 
     16 #define STAMP_TIMECARD(card, event)                                      \
     17  do {                                                                   \
     18    if (card) {                                                          \
     19      stamp_timecard((card), (event), __FILE__, __LINE__, __FUNCTION__); \
     20    }                                                                    \
     21  } while (0)
     22 
     23 #define TIMECARD_INITIAL_TABLE_SIZE 16
     24 
     25 /*
     26 * The "const char *" members of this structure point to static strings.
     27 * We do not own them, and should not attempt to deallocate them.
     28 */
     29 
     30 typedef struct {
     31  PRTime timestamp;
     32  const char* event;
     33  const char* file;
     34  unsigned int line;
     35  const char* function;
     36 } TimecardEntry;
     37 
     38 typedef struct Timecard {
     39  size_t curr_entry;
     40  size_t entries_allocated;
     41  TimecardEntry* entries;
     42  PRTime start_time;
     43 } Timecard;
     44 
     45 /**
     46 * Creates a new Timecard structure for tracking events.
     47 */
     48 Timecard* create_timecard();
     49 
     50 /**
     51 * Frees the memory associated with a timecard. After returning, the
     52 * timecard pointed to by tc is no longer valid.
     53 */
     54 void destroy_timecard(Timecard* tc);
     55 
     56 /**
     57 * Records a new event in the indicated timecard. This should not be
     58 * called directly; code should instead use the STAMP_TIMECARD macro,
     59 * above.
     60 */
     61 void stamp_timecard(Timecard* tc, const char* event, const char* file,
     62                    unsigned int line, const char* function);
     63 
     64 /**
     65 * Formats and outputs the contents of a timecard onto stdout.
     66 */
     67 void print_timecard(Timecard* tc);
     68 
     69 #ifdef __cplusplus
     70 }
     71 #endif
     72 
     73 #endif