github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/models/flamebearer.ts (about) 1 import { Units } from '@pyroscope/models/src'; 2 import { deltaDiffWrapper } from '@webapp/util/flamebearer'; 3 4 export type Flamebearer = { 5 /** 6 * List of names 7 */ 8 names: string[]; 9 /** 10 * List of level 11 * 12 * This is NOT the same as in the flamebearer 13 * that we receive from the server. 14 * As in there are some transformations required 15 * (see deltaDiffWrapper) 16 */ 17 levels: number[][]; 18 numTicks: number; 19 /** 20 * Sample Rate, used in text information 21 */ 22 sampleRate: number; 23 units: Units; 24 spyName: 25 | 'dotneyspy' 26 | 'ebpfspy' 27 | 'gospy' 28 | 'phpspy' 29 | 'pyspy' 30 | 'rbspy' 31 | string; 32 format: 'double' | 'single'; 33 leftTicks?: number; 34 rightTicks?: number; 35 }; 36 37 export type addTicks = 38 | { format: 'double'; leftTicks: number; rightTicks: number } 39 | { format: 'single' }; 40 41 interface DecodeFlamebearerProps { 42 flamebearer: Flamebearer; 43 metadata: { 44 format: 'single' | 'double'; 45 spyName: string; 46 sampleRate: number; 47 units: Units; 48 }; 49 leftTicks?: number; 50 rightTicks?: number; 51 version?: number; 52 } 53 54 // Hopefully these type assertions won't be required once we enable strictNullChecks in the ompiler 55 export function decodeFlamebearer({ 56 flamebearer, 57 metadata, 58 leftTicks, 59 rightTicks, 60 }: DecodeFlamebearerProps): Flamebearer { 61 const fb = { 62 ...flamebearer, 63 format: metadata.format, 64 spyName: metadata.spyName, 65 sampleRate: metadata.sampleRate, 66 units: metadata.units, 67 }; 68 69 if (fb.format === 'double') { 70 (fb as ShamefulAny).leftTicks = leftTicks; 71 (fb as ShamefulAny).rightTicks = rightTicks; 72 } 73 74 fb.levels = deltaDiffWrapper(fb.format, fb.levels); 75 return fb as Flamebearer; 76 } 77 78 export type FlamebearerProfile = { 79 flamebearer: Flamebearer; 80 81 /** 82 * Format version. 83 */ 84 version: number; 85 86 metadata: { 87 appName: string; 88 startTime: string; 89 endTime: string; 90 query: string; 91 maxNodes: number; 92 }; 93 }; 94 95 // RawFlamebearerProfile represents the exact FlamebearerProfile it's gotten from the backend 96 export interface RawFlamebearerProfile { 97 version: number; 98 99 metadata: { 100 // Optional fields since adhoc may be missing them 101 // they are added on /render and /render-diff response 102 // https://github.com/pyroscope-io/pyroscope/blob/main/pkg/server/render.go#L114-L131 103 appName?: string; 104 startTime?: number; 105 endTime?: number; 106 query?: string; 107 maxNodes?: number; 108 }; 109 110 flamebearer: { 111 /** 112 * List of names 113 */ 114 names: string[]; 115 /** 116 * List of level 117 * 118 * This is NOT the same as in the flamebearer 119 * that we receive from the server. 120 * As in there are some transformations required 121 * (see deltaDiffWrapper) 122 */ 123 levels: number[][]; 124 numTicks: number; 125 }; 126 }