1+ import merge from 'lodash/merge' ;
2+
3+ import { DeepPartial } from 'sentry/types/utils' ;
4+
15import { makeTestingBoilerplate } from './profile.spec' ;
26import { SentrySampledProfile } from './sentrySampledProfile' ;
3- import { makeSentrySampledProfile } from './sentrySampledProfile.specutil' ;
47import { createSentrySampleProfileFrameIndex } from './utils' ;
58
9+ export const makeSentrySampledProfile = (
10+ profile ?: DeepPartial < Profiling . SentrySampledProfile >
11+ ) => {
12+ return merge (
13+ {
14+ event_id : '1' ,
15+ version : '1' ,
16+ os : {
17+ name : 'iOS' ,
18+ version : '16.0' ,
19+ build_number : '19H253' ,
20+ } ,
21+ device : {
22+ architecture : 'arm64e' ,
23+ is_emulator : false ,
24+ locale : 'en_US' ,
25+ manufacturer : 'Apple' ,
26+ model : 'iPhone14,3' ,
27+ } ,
28+ timestamp : '2022-09-01T09:45:00.000Z' ,
29+ release : '0.1 (199)' ,
30+ platform : 'cocoa' ,
31+ profile : {
32+ samples : [
33+ {
34+ stack_id : 0 ,
35+ thread_id : '0' ,
36+ elapsed_since_start_ns : '0' ,
37+ } ,
38+ {
39+ stack_id : 1 ,
40+ thread_id : '0' ,
41+ elapsed_since_start_ns : '1000' ,
42+ } ,
43+ ] ,
44+ frames : [
45+ {
46+ function : 'foo' ,
47+ instruction_addr : '' ,
48+ lineno : 2 ,
49+ colno : 2 ,
50+ file : 'main.c' ,
51+ } ,
52+ {
53+ function : 'main' ,
54+ instruction_addr : '' ,
55+ lineno : 1 ,
56+ colno : 1 ,
57+ file : 'main.c' ,
58+ } ,
59+ ] ,
60+ stacks : [ [ 0 ] , [ 0 , 1 ] ] ,
61+ } ,
62+ } ,
63+ profile
64+ ) as Profiling . SentrySampledProfile ;
65+ } ;
66+
667describe ( 'SentrySampledProfile' , ( ) => {
768 it ( 'constructs a profile' , ( ) => {
869 const sampledProfile : Profiling . SentrySampledProfile = makeSentrySampledProfile ( ) ;
@@ -26,6 +87,134 @@ describe('SentrySampledProfile', () => {
2687 expect ( profile . endedAt ) . toEqual ( 1000 ) ;
2788 } ) ;
2889
90+ it ( 'tracks discarded samples' , ( ) => {
91+ const sampledProfile = makeSentrySampledProfile ( {
92+ transactions : [
93+ {
94+ id : '' ,
95+ name : 'foo' ,
96+ active_thread_id : '1' ,
97+ relative_start_ns : '0' ,
98+ relative_end_ns : '1000000' ,
99+ trace_id : '1' ,
100+ } ,
101+ ] ,
102+ profile : {
103+ samples : [
104+ {
105+ stack_id : 0 ,
106+ elapsed_since_start_ns : '1000' ,
107+ thread_id : '0' ,
108+ } ,
109+ {
110+ stack_id : 0 ,
111+ elapsed_since_start_ns : '1000' ,
112+ thread_id : '0' ,
113+ } ,
114+ ] ,
115+ thread_metadata : {
116+ '0' : {
117+ name : 'bar' ,
118+ } ,
119+ } ,
120+ } ,
121+ } ) ;
122+
123+ const profile = SentrySampledProfile . FromProfile (
124+ sampledProfile ,
125+ createSentrySampleProfileFrameIndex ( sampledProfile . profile . frames )
126+ ) ;
127+
128+ expect ( profile . stats . discardedSamplesCount ) . toBe ( 1 ) ;
129+ } ) ;
130+
131+ it ( 'tracks negative samples' , ( ) => {
132+ const sampledProfile = makeSentrySampledProfile ( {
133+ transactions : [
134+ {
135+ id : '' ,
136+ name : 'foo' ,
137+ active_thread_id : '1' ,
138+ relative_start_ns : '0' ,
139+ relative_end_ns : '1000000' ,
140+ trace_id : '1' ,
141+ } ,
142+ ] ,
143+ profile : {
144+ samples : [
145+ {
146+ stack_id : 0 ,
147+ elapsed_since_start_ns : '1000' ,
148+ thread_id : '0' ,
149+ } ,
150+ {
151+ stack_id : 0 ,
152+ elapsed_since_start_ns : '-1000' ,
153+ thread_id : '0' ,
154+ } ,
155+ ] ,
156+ thread_metadata : {
157+ '0' : {
158+ name : 'bar' ,
159+ } ,
160+ } ,
161+ } ,
162+ } ) ;
163+
164+ const profile = SentrySampledProfile . FromProfile (
165+ sampledProfile ,
166+ createSentrySampleProfileFrameIndex ( sampledProfile . profile . frames )
167+ ) ;
168+
169+ expect ( profile . stats . negativeSamplesCount ) . toBe ( 1 ) ;
170+ } ) ;
171+
172+ it ( 'tracks raw weights' , ( ) => {
173+ const sampledProfile = makeSentrySampledProfile ( {
174+ transactions : [
175+ {
176+ id : '' ,
177+ name : 'foo' ,
178+ active_thread_id : '1' ,
179+ relative_start_ns : '0' ,
180+ relative_end_ns : '1000000' ,
181+ trace_id : '1' ,
182+ } ,
183+ ] ,
184+ profile : {
185+ samples : [
186+ {
187+ stack_id : 0 ,
188+ elapsed_since_start_ns : '1000' ,
189+ thread_id : '0' ,
190+ } ,
191+ {
192+ stack_id : 0 ,
193+ elapsed_since_start_ns : '2000' ,
194+ thread_id : '0' ,
195+ } ,
196+ {
197+ stack_id : 0 ,
198+ elapsed_since_start_ns : '3000' ,
199+ thread_id : '0' ,
200+ } ,
201+ ] ,
202+ thread_metadata : {
203+ '0' : {
204+ name : 'bar' ,
205+ } ,
206+ } ,
207+ } ,
208+ } ) ;
209+
210+ const profile = SentrySampledProfile . FromProfile (
211+ sampledProfile ,
212+ createSentrySampleProfileFrameIndex ( sampledProfile . profile . frames )
213+ ) ;
214+
215+ expect ( profile . rawWeights . length ) . toBe ( 3 ) ;
216+ } ) ;
217+
29218 it ( 'derives a profile name from the transaction.name and thread_id' , ( ) => {
30219 const sampledProfile = makeSentrySampledProfile ( {
31220 transactions : [
0 commit comments