1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/signaling/src/common/time_profiling/timecard.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef timecard_h__ 1.11 +#define timecard_h__ 1.12 + 1.13 +#include <stdlib.h> 1.14 +#include "prtime.h" 1.15 + 1.16 +#ifdef __cplusplus 1.17 +extern "C" { 1.18 +#endif 1.19 + 1.20 +#define STAMP_TIMECARD(card,event) \ 1.21 + do { \ 1.22 + if (card) { \ 1.23 + stamp_timecard((card), (event), __FILE__, __LINE__, __FUNCTION__); \ 1.24 + } \ 1.25 + } while (0) 1.26 + 1.27 +#define TIMECARD_INITIAL_TABLE_SIZE 16 1.28 + 1.29 +/* 1.30 + * The "const char *" members of this structure point to static strings. 1.31 + * We do not own them, and should not attempt to deallocate them. 1.32 + */ 1.33 + 1.34 +typedef struct { 1.35 + PRTime timestamp; 1.36 + const char *event; 1.37 + const char *file; 1.38 + unsigned int line; 1.39 + const char *function; 1.40 +} TimecardEntry; 1.41 + 1.42 +typedef struct Timecard { 1.43 + size_t curr_entry; 1.44 + size_t entries_allocated; 1.45 + TimecardEntry *entries; 1.46 + PRTime start_time; 1.47 +} Timecard; 1.48 + 1.49 +/** 1.50 + * Creates a new Timecard structure for tracking events. 1.51 + */ 1.52 +Timecard * 1.53 +create_timecard(); 1.54 + 1.55 +/** 1.56 + * Frees the memory associated with a timecard. After returning, the 1.57 + * timecard pointed to by tc is no longer valid. 1.58 + */ 1.59 +void 1.60 +destroy_timecard(Timecard *tc); 1.61 + 1.62 +/** 1.63 + * Records a new event in the indicated timecard. This should not be 1.64 + * called directly; code should instead use the STAMP_TIMECARD macro, 1.65 + * above. 1.66 + */ 1.67 +void 1.68 +stamp_timecard(Timecard *tc, 1.69 + const char *event, 1.70 + const char *file, 1.71 + unsigned int line, 1.72 + const char *function); 1.73 + 1.74 +/** 1.75 + * Formats and outputs the contents of a timecard onto stdout. 1.76 + */ 1.77 +void 1.78 +print_timecard(Timecard *tc); 1.79 + 1.80 +#ifdef __cplusplus 1.81 +} 1.82 +#endif 1.83 + 1.84 +#endif