MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / recordSample

Method recordSample

src/profiler.cpp:392–485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Event* event) {
393 atomicInc(_total_samples);
394
395 int tid = OS::threadId();
396 u32 lock_index = getLockIndex(tid);
397 if (!_locks[lock_index].tryLock() &&
398 !_locks[lock_index = (lock_index + 1) % CONCURRENCY_LEVEL].tryLock() &&
399 !_locks[lock_index = (lock_index + 2) % CONCURRENCY_LEVEL].tryLock())
400 {
401 // Too many concurrent signals already
402 atomicInc(_failures[-ticks_skipped]);
403
404 if (event_type == PERF_SAMPLE) {
405 // Need to reset PerfEvents ring buffer, even though we discard the collected trace
406 PerfEvents::resetBuffer(tid);
407 }
408 return 0;
409 }
410
411 u64 stack_walk_begin = _features.stats ? OS::nanotime() : 0;
412
413 ASGCT_CallFrame* frames = _calltrace_buffer[lock_index]->_asgct_frames;
414 jvmtiFrameInfo* jvmti_frames = _calltrace_buffer[lock_index]->_jvmti_frames;
415
416 int num_frames = 0;
417 if (_add_event_frame && event_type >= ALLOC_SAMPLE && event_type <= PARK_SAMPLE) {
418 u32 class_id = ((EventWithClassId*)event)->_class_id;
419 if (class_id != 0) {
420 // Convert event_type to frame_type, e.g. ALLOC_SAMPLE -> BCI_ALLOC
421 jint frame_type = BCI_ALLOC - (event_type - ALLOC_SAMPLE);
422 num_frames = makeFrame(frames, frame_type, class_id);
423 }
424 }
425
426 u64 cpu = 0;
427 if (hasNativeStack(event_type)) {
428 if (_features.pc_addr && event_type <= WALL_CLOCK_SAMPLE) {
429 num_frames += makeFrame(frames + num_frames, BCI_ADDRESS, StackFrame(ucontext).pc());
430 }
431 if (_cstack != CSTACK_NO) {
432 num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &cpu);
433 }
434 }
435
436 if (_features.mixed) {
437 num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type);
438 } else if (event_type <= MALLOC_SAMPLE) {
439 if (_cstack == CSTACK_VM) {
440 num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, _features, event_type);
441 } else {
442 num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);
443 }
444 } else if (event_type >= ALLOC_SAMPLE && event_type <= ALLOC_OUTSIDE_TLAB && _alloc_engine == &alloc_tracer) {
445 if (VMStructs::hasStackStructs()) {
446 StackWalkFeatures no_features{};
447 num_frames += StackWalker::walkVM(ucontext, frames + num_frames, _max_stack_depth, lock_index, no_features, event_type);
448 } else {
449 num_frames += getJavaTraceAsync(ucontext, frames + num_frames, _max_stack_depth);

Callers 10

recordMallocMethod · 0.80
recordEntryMethod · 0.80
recordExit0Method · 0.80
signalHandlerMethod · 0.80
recordAllocationMethod · 0.80
signalHandlerMethod · 0.80
recordContendedLockMethod · 0.80
recordNativeLockMethod · 0.80
recordAllocationMethod · 0.80
signalHandlerMethod · 0.80

Calls 8

atomicIncFunction · 0.85
makeFrameFunction · 0.85
hasNativeStackFunction · 0.85
StackFrameClass · 0.70
tryLockMethod · 0.45
putMethod · 0.45
recordEventMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected