Home | History | Annotate | Download | only in xray
      1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2  * Use of this source code is governed by a BSD-style license that can be
      3  * found in the LICENSE file. */
      4 
      5 /* XRay -- a simple profiler for Native Client */
      6 
      7 /* This header file is the private internal interface. */
      8 
      9 #ifndef LIBRARIES_XRAY_XRAY_PRIV_H_
     10 #define LIBRARIES_XRAY_XRAY_PRIV_H_
     11 
     12 #include <stdbool.h>
     13 #include <stdint.h>
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 #include "xray/xray.h"
     17 
     18 #ifdef __cplusplus
     19 extern "C" {
     20 #endif
     21 
     22 #if defined(XRAY)
     23 
     24 #define XRAY_FORCE_INLINE __attribute__((always_inline))
     25 
     26 #define XRAY_TRACE_STACK_SIZE (256)
     27 #define XRAY_TRACE_ANNOTATION_LENGTH (1024)
     28 #define XRAY_TRACE_BUFFER_SIZE (1048576)
     29 #define XRAY_ANNOTATION_STACK_SIZE ((XRAY_TRACE_STACK_SIZE) * \
     30                                     (XRAY_TRACE_ANNOTATION_LENGTH))
     31 #define XRAY_STRING_POOL_NODE_SIZE (32768)
     32 #define XRAY_FRAME_MARKER (0xFFFFFFFF)
     33 #define XRAY_NULL_ANNOTATION (0x0)
     34 #define XRAY_FUNCTION_ALIGNMENT_BITS (4)
     35 #define XRAY_ADDR_MASK (0xFFFFFF00)
     36 #define XRAY_ADDR_SHIFT (4)
     37 #define XRAY_DEPTH_MASK (0x000000FF)
     38 #define XRAY_SYMBOL_TABLE_MAX_RATIO (0.66f)
     39 #define XRAY_LINE_SIZE (1024)
     40 #define XRAY_MAX_FRAMES (60)
     41 #define XRAY_MAX_LABEL (64)
     42 #define XRAY_DEFAULT_SYMBOL_TABLE_SIZE (4096)
     43 #define XRAY_SYMBOL_POOL_NODE_SIZE (1024)
     44 #define XRAY_GUARD_VALUE_0x12345678 (0x12345678)
     45 #define XRAY_GUARD_VALUE_0x87654321 (0x87654321)
     46 #define XRAY_EXTRACT_ADDR(x) (((x) & XRAY_ADDR_MASK) >> XRAY_ADDR_SHIFT)
     47 #define XRAY_EXTRACT_DEPTH(x) ((x) & XRAY_DEPTH_MASK)
     48 #define XRAY_PACK_ADDR(x) (((x) << XRAY_ADDR_SHIFT) & XRAY_ADDR_MASK)
     49 #define XRAY_PACK_DEPTH(x) ((x) & XRAY_DEPTH_MASK)
     50 #define XRAY_PACK_DEPTH_ADDR(d, a) (XRAY_PACK_DEPTH(d) | XRAY_PACK_ADDR(a))
     51 #define XRAY_ALIGN64 __attribute((aligned(64)))
     52 
     53 struct XRayStringPool;
     54 struct XRayHashTable;
     55 struct XRaySymbolPool;
     56 struct XRaySymbol;
     57 struct XRaySymbolTable;
     58 struct XRayTraceCapture;
     59 
     60 struct XRayTraceBufferEntry {
     61   uint32_t depth_addr;
     62   uint32_t annotation_index;
     63   uint64_t start_tick;
     64   uint64_t end_tick;
     65 };
     66 
     67 
     68 /* Important: don't instrument xray itself, so use       */
     69 /*            XRAY_NO_INSTRUMENT on all xray functions   */
     70 
     71 XRAY_NO_INSTRUMENT char* XRayStringPoolAppend(struct XRayStringPool* pool,
     72   const char* src);
     73 XRAY_NO_INSTRUMENT struct XRayStringPool* XRayStringPoolCreate();
     74 XRAY_NO_INSTRUMENT void XRayStringPoolFree(struct XRayStringPool* pool);
     75 
     76 XRAY_NO_INSTRUMENT void* XRayHashTableLookup(struct XRayHashTable* table,
     77     uint32_t addr);
     78 XRAY_NO_INSTRUMENT void* XRayHashTableInsert(struct XRayHashTable* table,
     79     void* data, uint32_t addr);
     80 XRAY_NO_INSTRUMENT void* XRayHashTableAtIndex(
     81   struct XRayHashTable* table, int i);
     82 XRAY_NO_INSTRUMENT int XRayHashTableGetCapacity(struct XRayHashTable* table);
     83 XRAY_NO_INSTRUMENT int XRayHashTableGetCount(struct XRayHashTable* table);
     84 XRAY_NO_INSTRUMENT struct XRayHashTable* XRayHashTableCreate(int capacity);
     85 XRAY_NO_INSTRUMENT void XRayHashTableFree(struct XRayHashTable* table);
     86 XRAY_NO_INSTRUMENT void XRayHashTableHisto(FILE* f);
     87 
     88 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolPoolAlloc(
     89     struct XRaySymbolPool* sympool);
     90 XRAY_NO_INSTRUMENT struct XRaySymbolPool* XRaySymbolPoolCreate();
     91 XRAY_NO_INSTRUMENT void XRaySymbolPoolFree(struct XRaySymbolPool* sympool);
     92 
     93 XRAY_NO_INSTRUMENT const char* XRayDemangle(char* demangle, size_t buffersize,
     94     const char* symbol);
     95 
     96 XRAY_NO_INSTRUMENT const char* XRaySymbolGetName(struct XRaySymbol* symbol);
     97 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolCreate(
     98     struct XRaySymbolPool* sympool, const char* name);
     99 XRAY_NO_INSTRUMENT void XRaySymbolFree(struct XRaySymbol* symbol);
    100 XRAY_NO_INSTRUMENT int XRaySymbolCount(struct XRaySymbolTable* symtab);
    101 
    102 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolTableCreateEntry(
    103     struct XRaySymbolTable* symtab, const char* line);
    104 XRAY_NO_INSTRUMENT void XRaySymbolTableParseMapfile(
    105     struct XRaySymbolTable* symbols, const char* mapfilename);
    106 
    107 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolTableAddByName(
    108     struct XRaySymbolTable* symtab, const char* name, uint32_t addr);
    109 
    110 XRAY_NO_INSTRUMENT int XRaySymbolTableGetCount(struct XRaySymbolTable* symtab);
    111 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolTableLookup(
    112     struct XRaySymbolTable* symbols, uint32_t addr);
    113 XRAY_NO_INSTRUMENT struct XRaySymbol* XRaySymbolTableAtIndex(
    114     struct XRaySymbolTable* symbols, int i);
    115 XRAY_NO_INSTRUMENT struct XRaySymbolTable* XRaySymbolTableCreate(int size);
    116 XRAY_NO_INSTRUMENT void XRaySymbolTableFree(struct XRaySymbolTable* symbtab);
    117 
    118 XRAY_NO_INSTRUMENT struct XRaySymbolTable* XRayGetSymbolTable();
    119 
    120 XRAY_NO_INSTRUMENT void XRayCheckGuards(struct XRayTraceCapture* capture);
    121 
    122 XRAY_NO_INSTRUMENT struct XRayTraceBufferEntry* XRayTraceGetEntry(
    123     struct XRayTraceCapture* capture, int index);
    124 XRAY_NO_INSTRUMENT int XRayTraceIncrementIndex(
    125     struct XRayTraceCapture* capture, int i);
    126 XRAY_NO_INSTRUMENT int XRayTraceDecrementIndex(
    127     struct XRayTraceCapture* capture, int i);
    128 XRAY_NO_INSTRUMENT bool XRayTraceIsAnnotation(
    129     struct XRayTraceCapture* capture, int index);
    130 XRAY_NO_INSTRUMENT void XRayTraceAppendString(
    131     struct XRayTraceCapture* capture, char* src);
    132 XRAY_NO_INSTRUMENT int XRayTraceCopyToString(
    133     struct XRayTraceCapture* capture, int index, char* dst);
    134 XRAY_NO_INSTRUMENT int XRayTraceSkipAnnotation(
    135     struct XRayTraceCapture* capture, int index);
    136 XRAY_NO_INSTRUMENT int XRayTraceNextEntry(
    137     struct XRayTraceCapture* capture, int index);
    138 
    139 XRAY_NO_INSTRUMENT void XRayFrameMakeLabel(struct XRayTraceCapture* capture,
    140                                            int counter,
    141                                            char* label);
    142 XRAY_NO_INSTRUMENT int XRayFrameFindTail(struct XRayTraceCapture* capture);
    143 
    144 XRAY_NO_INSTRUMENT int XRayFrameGetCount(struct XRayTraceCapture* capture);
    145 XRAY_NO_INSTRUMENT int XRayFrameGetHead(struct XRayTraceCapture* capture);
    146 XRAY_NO_INSTRUMENT int XRayFrameGetTail(struct XRayTraceCapture* capture);
    147 XRAY_NO_INSTRUMENT int XRayFrameGetNext(
    148     struct XRayTraceCapture* capture, int index);
    149 XRAY_NO_INSTRUMENT int XRayFrameGetTotalTicks(
    150     struct XRayTraceCapture* capture, int frame);
    151 XRAY_NO_INSTRUMENT int XRayFrameGetTraceCount(
    152     struct XRayTraceCapture* capture, int frame);
    153 XRAY_NO_INSTRUMENT int XRayFrameGetTraceStartIndex(
    154     struct XRayTraceCapture* capture, int frame);
    155 XRAY_NO_INSTRUMENT int XRayFrameGetTraceEndIndex(
    156     struct XRayTraceCapture* capture, int frame);
    157 XRAY_NO_INSTRUMENT int XRayFrameGetAnnotationCount(
    158     struct XRayTraceCapture* capture, int frame);
    159 XRAY_NO_INSTRUMENT bool XRayFrameIsValid(
    160     struct XRayTraceCapture* capture, int frame);
    161 
    162 
    163 XRAY_NO_INSTRUMENT void XRayTraceReport(struct XRayTraceCapture* capture,
    164                                         FILE* f,
    165                                         int frame,
    166                                         char* label,
    167                                         float percent_cutoff,
    168                                         int ticks_cutoff);
    169 XRAY_NO_INSTRUMENT void XRayFrameReport(struct XRayTraceCapture* capture,
    170                                         FILE* f);
    171 
    172 XRAY_NO_INSTRUMENT void* XRayMalloc(size_t t);
    173 XRAY_NO_INSTRUMENT void XRayFree(void* data);
    174 
    175 XRAY_NO_INSTRUMENT void XRaySetMaxStackDepth(
    176     struct XRayTraceCapture* capture, int stack_depth);
    177 XRAY_NO_INSTRUMENT int XRayGetLastFrame(struct XRayTraceCapture* capture);
    178 XRAY_NO_INSTRUMENT void XRayDisableCapture(struct XRayTraceCapture* capture);
    179 XRAY_NO_INSTRUMENT void XRayEnableCapture(struct XRayTraceCapture* capture);
    180 XRAY_NO_INSTRUMENT void XRayLoadMapfile(
    181     struct XRayTraceCapture* capture, const char* mapfilename);
    182 
    183 struct XRayTimestampPair {
    184   uint64_t xray;   /* internal xray timestamp */
    185   int64_t pepper;  /* corresponding timestamp from PPAPI interface */
    186 };
    187 
    188 #ifndef XRAY_DISABLE_BROWSER_INTEGRATION
    189 XRAY_NO_INSTRUMENT void XRayGetTSC(uint64_t* tsc);
    190 XRAY_NO_INSTRUMENT int32_t XRayGetSavedThreadID(
    191     struct XRayTraceCapture* capture);
    192 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetStartTimestampPair(
    193     struct XRayTraceCapture* capture, int frame);
    194 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetEndTimestampPair(
    195     struct XRayTraceCapture* capture, int frame);
    196 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayGenerateTimestampsNow(void);
    197 #endif
    198 
    199 
    200 #endif  /* defined(XRAY) */
    201 
    202 #ifdef __cplusplus
    203 }
    204 #endif
    205 
    206 #endif  /* LIBRARIES_XRAY_XRAY_PRIV_H_ */
    207