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, no_instrument_function))
     25 
     26 #define XRAY_TRACE_STACK_SIZE (256)
     27 #define XRAY_TRACE_ANNOTATION_LENGTH (2048)
     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, 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     struct XRayTraceCapture* capture);
    120 
    121 XRAY_NO_INSTRUMENT void XRayCheckGuards(struct XRayTraceCapture* capture);
    122 
    123 XRAY_NO_INSTRUMENT struct XRayTraceBufferEntry* XRayTraceGetEntry(
    124     struct XRayTraceCapture* capture, int index);
    125 XRAY_NO_INSTRUMENT int XRayTraceIncrementIndex(
    126     struct XRayTraceCapture* capture, int i);
    127 XRAY_NO_INSTRUMENT int XRayTraceDecrementIndex(
    128     struct XRayTraceCapture* capture, int i);
    129 XRAY_NO_INSTRUMENT bool XRayTraceIsAnnotation(
    130     struct XRayTraceCapture* capture, int index);
    131 XRAY_NO_INSTRUMENT void XRayTraceAppendString(
    132     struct XRayTraceCapture* capture, char* src);
    133 XRAY_NO_INSTRUMENT int XRayTraceCopyToString(
    134     struct XRayTraceCapture* capture, int index, char* dst);
    135 XRAY_NO_INSTRUMENT int XRayTraceSkipAnnotation(
    136     struct XRayTraceCapture* capture, int index);
    137 XRAY_NO_INSTRUMENT int XRayTraceNextEntry(
    138     struct XRayTraceCapture* capture, int index);
    139 
    140 XRAY_NO_INSTRUMENT void XRayFrameMakeLabel(struct XRayTraceCapture* capture,
    141                                            int counter,
    142                                            char* label);
    143 XRAY_NO_INSTRUMENT int XRayFrameFindTail(struct XRayTraceCapture* capture);
    144 
    145 XRAY_NO_INSTRUMENT int XRayFrameGetCount(struct XRayTraceCapture* capture);
    146 XRAY_NO_INSTRUMENT int XRayFrameGetHead(struct XRayTraceCapture* capture);
    147 XRAY_NO_INSTRUMENT int XRayFrameGetTail(struct XRayTraceCapture* capture);
    148 XRAY_NO_INSTRUMENT int XRayFrameGetNext(
    149     struct XRayTraceCapture* capture, int index);
    150 XRAY_NO_INSTRUMENT uint64_t XRayFrameGetTotalTicks(
    151     struct XRayTraceCapture* capture, int frame);
    152 XRAY_NO_INSTRUMENT int XRayFrameGetTraceCount(
    153     struct XRayTraceCapture* capture, int frame);
    154 XRAY_NO_INSTRUMENT int XRayFrameGetTraceStartIndex(
    155     struct XRayTraceCapture* capture, int frame);
    156 XRAY_NO_INSTRUMENT int XRayFrameGetTraceEndIndex(
    157     struct XRayTraceCapture* capture, int frame);
    158 XRAY_NO_INSTRUMENT int XRayFrameGetAnnotationCount(
    159     struct XRayTraceCapture* capture, int frame);
    160 XRAY_NO_INSTRUMENT bool XRayFrameIsValid(
    161     struct XRayTraceCapture* capture, int frame);
    162 
    163 
    164 XRAY_NO_INSTRUMENT void XRayTraceReport(struct XRayTraceCapture* capture,
    165                                         FILE* f,
    166                                         int frame,
    167                                         char* label,
    168                                         float percent_cutoff,
    169                                         int ticks_cutoff);
    170 XRAY_NO_INSTRUMENT void XRayFrameReport(struct XRayTraceCapture* capture,
    171                                         FILE* f);
    172 
    173 XRAY_NO_INSTRUMENT void* XRayMalloc(size_t t);
    174 XRAY_NO_INSTRUMENT void XRayFree(void* data);
    175 
    176 XRAY_NO_INSTRUMENT void XRaySetMaxStackDepth(
    177     struct XRayTraceCapture* capture, int stack_depth);
    178 XRAY_NO_INSTRUMENT int XRayGetLastFrame(struct XRayTraceCapture* capture);
    179 XRAY_NO_INSTRUMENT void XRayDisableCapture(struct XRayTraceCapture* capture);
    180 XRAY_NO_INSTRUMENT void XRayEnableCapture(struct XRayTraceCapture* capture);
    181 XRAY_NO_INSTRUMENT void XRayLoadMapfile(
    182     struct XRayTraceCapture* capture, const char* mapfilename);
    183 
    184 struct XRayTimestampPair {
    185   uint64_t xray;   /* internal xray timestamp */
    186   int64_t pepper;  /* corresponding timestamp from PPAPI interface */
    187 };
    188 
    189 #ifndef XRAY_DISABLE_BROWSER_INTEGRATION
    190 XRAY_NO_INSTRUMENT void XRayGetTSC(uint64_t* tsc);
    191 XRAY_NO_INSTRUMENT int32_t XRayGetSavedThreadID(
    192     struct XRayTraceCapture* capture);
    193 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetStartTimestampPair(
    194     struct XRayTraceCapture* capture, int frame);
    195 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayFrameGetEndTimestampPair(
    196     struct XRayTraceCapture* capture, int frame);
    197 XRAY_NO_INSTRUMENT struct XRayTimestampPair XRayGenerateTimestampsNow(void);
    198 #endif
    199 
    200 
    201 #endif  /* defined(XRAY) */
    202 
    203 #ifdef __cplusplus
    204 }
    205 #endif
    206 
    207 #endif  /* LIBRARIES_XRAY_XRAY_PRIV_H_ */
    208