22
22
23
23
#include " oi/ContainerInfo.h"
24
24
25
+ using ObjectIntrospection::Feature;
26
+ using ObjectIntrospection::FeatureSet;
27
+
25
28
namespace {
26
29
27
30
const std::string typedValueFunc = R"(
@@ -235,29 +238,47 @@ void FuncGen::DefineTopLevelGetObjectSize(std::string& testCode,
235
238
}
236
239
237
240
void FuncGen::DefineTopLevelGetSizeRef (std::string& testCode,
238
- const std::string& rawType) {
241
+ const std::string& rawType,
242
+ FeatureSet features) {
239
243
std::string func = R"(
240
244
#pragma GCC diagnostic push
241
245
#pragma GCC diagnostic ignored "-Wunknown-attributes"
242
246
/* RawType: %1% */
243
247
void __attribute__((used, retain)) getSize_%2$016x(const OIInternal::__ROOT_TYPE__& t)
244
248
#pragma GCC diagnostic pop
245
249
{
250
+ )" ;
251
+ if (features[Feature::JitTiming]) {
252
+ func += " const auto startTime = std::chrono::steady_clock::now();\n " ;
253
+ }
254
+ func += R"(
246
255
pointers.initialize();
247
256
pointers.add((uintptr_t)&t);
248
257
auto data = reinterpret_cast<uintptr_t*>(dataBase);
249
- data[0] = oidMagicId;
250
- data[1] = cookieValue;
251
- data[2] = 0;
252
258
253
- size_t dataSegOffset = 3 * sizeof(uintptr_t);
259
+ size_t dataSegOffset = 0;
260
+ data[dataSegOffset++] = oidMagicId;
261
+ data[dataSegOffset++] = cookieValue;
262
+ uintptr_t& writtenSize = data[dataSegOffset++];
263
+ writtenSize = 0;
264
+ uintptr_t& timeTakenNs = data[dataSegOffset++];
265
+
266
+ dataSegOffset *= sizeof(uintptr_t);
254
267
JLOG("%1% @");
255
268
JLOGPTR(&t);
256
269
OIInternal::getSizeType(t, dataSegOffset);
257
270
OIInternal::StoreData((uintptr_t)123456789, dataSegOffset);
258
271
OIInternal::StoreData((uintptr_t)123456789, dataSegOffset);
259
- data[2] = dataSegOffset;
272
+ writtenSize = dataSegOffset;
260
273
dataBase += dataSegOffset;
274
+ )" ;
275
+ if (features[Feature::JitTiming]) {
276
+ func += R"(
277
+ timeTakenNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
278
+ std::chrono::steady_clock::now() - startTime).count();
279
+ )" ;
280
+ }
281
+ func += R"(
261
282
}
262
283
)" ;
263
284
@@ -267,25 +288,34 @@ void FuncGen::DefineTopLevelGetSizeRef(std::string& testCode,
267
288
}
268
289
269
290
void FuncGen::DefineTopLevelGetSizeRefTyped (std::string& testCode,
270
- const std::string& rawType) {
291
+ const std::string& rawType,
292
+ FeatureSet features) {
271
293
std::string func = R"(
272
294
#pragma GCC diagnostic push
273
295
#pragma GCC diagnostic ignored "-Wunknown-attributes"
274
296
/* RawType: %1% */
275
297
void __attribute__((used, retain)) getSize_%2$016x(const OIInternal::__ROOT_TYPE__& t)
276
298
#pragma GCC diagnostic pop
277
299
{
300
+ )" ;
301
+ if (features[Feature::JitTiming]) {
302
+ func += " const auto startTime = std::chrono::steady_clock::now();\n " ;
303
+ }
304
+ func += R"(
278
305
pointers.initialize();
279
306
pointers.add((uintptr_t)&t);
280
307
auto data = reinterpret_cast<uintptr_t*>(dataBase);
281
308
282
309
// TODO: Replace these with types::st::Uint64 once the VarInt decoding
283
310
// logic is moved out of OIDebugger and into new TreeBuilder.
284
- data[0] = oidMagicId;
285
- data[1] = cookieValue;
286
- data[2] = 0;
287
-
288
- size_t dataSegOffset = 3 * sizeof(uintptr_t);
311
+ size_t dataSegOffset = 0;
312
+ data[dataSegOffset++] = oidMagicId;
313
+ data[dataSegOffset++] = cookieValue;
314
+ uintptr_t& writtenSize = data[dataSegOffset++];
315
+ writtenSize = 0;
316
+ uintptr_t& timeTakenNs = data[dataSegOffset++];
317
+
318
+ dataSegOffset *= sizeof(uintptr_t);
289
319
JLOG("%1% @");
290
320
JLOGPTR(&t);
291
321
@@ -310,8 +340,16 @@ void FuncGen::DefineTopLevelGetSizeRefTyped(std::string& testCode,
310
340
.write(123456789);
311
341
312
342
dataSegOffset = end.offset();
313
- data[2] = dataSegOffset;
343
+ writtenSize = dataSegOffset;
314
344
dataBase += dataSegOffset;
345
+ )" ;
346
+ if (features[Feature::JitTiming]) {
347
+ func += R"(
348
+ timeTakenNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
349
+ std::chrono::steady_clock::now() - startTime).count();
350
+ )" ;
351
+ }
352
+ func += R"(
315
353
}
316
354
)" ;
317
355
@@ -342,27 +380,45 @@ void FuncGen::DefineTopLevelGetSizeRefRet(std::string& testCode,
342
380
}
343
381
344
382
void FuncGen::DefineTopLevelGetSizeSmartPtr (std::string& testCode,
345
- const std::string& rawType) {
383
+ const std::string& rawType,
384
+ FeatureSet features) {
346
385
std::string func = R"(
347
386
#pragma GCC diagnostic push
348
387
#pragma GCC diagnostic ignored "-Wunknown-attributes"
349
388
/* RawType: %1% */
350
389
void __attribute__((used, retain)) getSize_%2$016x(const OIInternal::__ROOT_TYPE__& t)
351
390
#pragma GCC diagnostic pop
352
391
{
392
+ )" ;
393
+ if (features[Feature::JitTiming]) {
394
+ func += " const auto startTime = std::chrono::steady_clock::now();\n " ;
395
+ }
396
+ func += R"(
353
397
pointers.initialize();
354
398
auto data = reinterpret_cast<uintptr_t*>(dataBase);
355
- data[0] = oidMagicId;
356
- data[1] = cookieValue;
357
- data[2] = 0;
358
399
359
- size_t dataSegOffset = 3 * sizeof(uintptr_t);
400
+ size_t dataSegOffset = 0;
401
+ data[dataSegOffset++] = oidMagicId;
402
+ data[dataSegOffset++] = cookieValue;
403
+ uintptr_t& writtenSize = data[dataSegOffset++];
404
+ writtenSize = 0;
405
+ uintptr_t& timeTakenNs = data[dataSegOffset++];
406
+
407
+ dataSegOffset *= sizeof(uintptr_t);
360
408
361
409
OIInternal::getSizeType(t, dataSegOffset);
362
410
OIInternal::StoreData((uintptr_t)123456789, dataSegOffset);
363
411
OIInternal::StoreData((uintptr_t)123456789, dataSegOffset);
364
- data[2] = dataSegOffset;
412
+ writtenSize = dataSegOffset;
365
413
dataBase += dataSegOffset;
414
+ )" ;
415
+ if (features[Feature::JitTiming]) {
416
+ func += R"(
417
+ timeTakenNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
418
+ std::chrono::steady_clock::now() - startTime).count();
419
+ )" ;
420
+ }
421
+ func += R"(
366
422
}
367
423
)" ;
368
424
@@ -373,7 +429,7 @@ void FuncGen::DefineTopLevelGetSizeSmartPtr(std::string& testCode,
373
429
374
430
bool FuncGen::DeclareGetSizeFuncs (std::string& testCode,
375
431
const ContainerInfoRefSet& containerInfo,
376
- bool chaseRawPointers ) {
432
+ FeatureSet features ) {
377
433
for (const ContainerInfo& cInfo : containerInfo) {
378
434
std::string ctype = cInfo.typeName ;
379
435
ctype = ctype.substr (0 , ctype.find (" <" , 0 ));
@@ -383,7 +439,7 @@ bool FuncGen::DeclareGetSizeFuncs(std::string& testCode,
383
439
testCode.append (fmt.str ());
384
440
}
385
441
386
- if (chaseRawPointers ) {
442
+ if (features[Feature::ChaseRawPointers] ) {
387
443
testCode.append (
388
444
" template<typename T, typename = "
389
445
" std::enable_if_t<!std::is_pointer_v<std::decay_t<T>>>>\n " );
@@ -397,7 +453,7 @@ bool FuncGen::DeclareGetSizeFuncs(std::string& testCode,
397
453
398
454
bool FuncGen::DefineGetSizeFuncs (std::string& testCode,
399
455
const ContainerInfoRefSet& containerInfo,
400
- bool chaseRawPointers ) {
456
+ FeatureSet features ) {
401
457
for (const ContainerInfo& cInfo : containerInfo) {
402
458
std::string ctype = cInfo.typeName ;
403
459
ctype = ctype.substr (0 , ctype.find (" <" , 0 ));
@@ -407,7 +463,7 @@ bool FuncGen::DefineGetSizeFuncs(std::string& testCode,
407
463
testCode.append (fmt.str ());
408
464
}
409
465
410
- if (chaseRawPointers ) {
466
+ if (features[Feature::ChaseRawPointers] ) {
411
467
testCode.append (" template<typename T, typename C>\n " );
412
468
} else {
413
469
testCode.append (" template<typename T>\n " );
0 commit comments