Bug 1884378 - Expose Profiler's NativeStack structure r=canaltinova,profiler-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D207732
This commit is contained in:
Alexandre Lissy 2024-06-14 10:17:34 +00:00
Родитель d40d99c2bb
Коммит a8b0609956
3 изменённых файлов: 27 добавлений и 14 удалений

Просмотреть файл

@ -41,6 +41,7 @@
#include "ProfilerCPUFreq.h"
#include "ProfilerIOInterposeObserver.h"
#include "ProfilerParent.h"
#include "ProfilerNativeStack.h"
#include "ProfilerRustBindings.h"
#include "mozilla/Assertions.h"
#include "mozilla/Maybe.h"
@ -2027,18 +2028,6 @@ class Registers {
#endif
};
// Setting MAX_NATIVE_FRAMES too high risks the unwinder wasting a lot of time
// looping on corrupted stacks.
static const size_t MAX_NATIVE_FRAMES = 1024;
struct NativeStack {
void* mPCs[MAX_NATIVE_FRAMES];
void* mSPs[MAX_NATIVE_FRAMES];
size_t mCount; // Number of frames filled.
NativeStack() : mPCs(), mSPs(), mCount(0) {}
};
Atomic<bool> WALKING_JS_STACK(false);
struct AutoWalkJSStack {
@ -2881,7 +2870,7 @@ static inline void DoSharedSample(
aJsFrames ? ExtractJsFrames(aIsSynchronous, aThreadData, aRegs, collector,
aJsFrames, stackWalkControlIfSupported)
: 0;
NativeStack nativeStack;
NativeStack nativeStack{.mCount = 0};
#if defined(HAVE_NATIVE_UNWIND)
if (captureNative) {
DoNativeBacktrace(aThreadData, aRegs, nativeStack,
@ -7657,7 +7646,7 @@ static void profiler_suspend_and_sample_thread(
}
// Allocate the space for the native stack
NativeStack nativeStack;
NativeStack nativeStack{.mCount = 0};
auto collectStack = [&](const Registers& aRegs, const TimeStamp& aNow) {
// The target thread is now suspended. Collect a native backtrace,

Просмотреть файл

@ -176,6 +176,7 @@ EXPORTS += [
"public/ProfileAdditionalInformation.h",
"public/ProfilerBindings.h",
"public/ProfilerControl.h",
"public/ProfilerNativeStack.h",
"public/ProfilerParent.h",
"public/ProfilerRustBindings.h",
"public/shared-libraries.h",

Просмотреть файл

@ -0,0 +1,23 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ProfilerNativeStack_h
#define ProfilerNativeStack_h
#include <stddef.h>
// Setting MAX_NATIVE_FRAMES too high risks the unwinder wasting a lot of time
// looping on corrupted stacks.
static const size_t MAX_NATIVE_FRAMES = 1024;
struct NativeStack {
void* mPCs[MAX_NATIVE_FRAMES];
void* mSPs[MAX_NATIVE_FRAMES];
size_t mCount; // Number of frames filled.
};
#endif // ProfilerNativeStack_h