Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Parameter-controlled unwinder thread priority
Browse files Browse the repository at this point in the history
Reviewed By: yukonfb

Differential Revision: D33118237

fbshipit-source-id: f2da35baef7d5ec0aff91b472211027883573eb2
  • Loading branch information
aandreyeu authored and facebook-github-bot committed Dec 15, 2021
1 parent 1f8ff3c commit bd33a28
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
17 changes: 12 additions & 5 deletions cpp/profiler/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ int32_t getCpuClockResolutionMicros(facebook::jni::alias_ref<jobject>) {
std::unordered_map<int32_t, std::shared_ptr<BaseTracer>> makeAvailableTracers(
MultiBufferLogger& logger,
uint32_t available_tracers,
bool native_tracer_unwind_dex_frames) {
bool native_tracer_unwind_dex_frames,
int32_t native_tracer_unwind_thread_pri) {
std::unordered_map<int32_t, std::shared_ptr<BaseTracer>> tracers;
if (available_tracers & tracers::DALVIK) {
tracers[tracers::DALVIK] = std::make_shared<DalvikTracer>();
}

#if HAS_NATIVE_TRACER
if (available_tracers & tracers::NATIVE) {
tracers[tracers::NATIVE] =
std::make_shared<NativeTracer>(logger, native_tracer_unwind_dex_frames);
tracers[tracers::NATIVE] = std::make_shared<NativeTracer>(
logger,
native_tracer_unwind_dex_frames,
native_tracer_unwind_thread_pri);
}
#endif

Expand Down Expand Up @@ -135,14 +138,18 @@ static jboolean nativeInitialize(
fbjni::alias_ref<jobject>,
JMultiBufferLogger* jlogger,
jint tracers,
jboolean native_tracer_unwind_dex_frames) {
jboolean native_tracer_unwind_dex_frames,
jint native_tracer_unwind_thread_pri) {
auto available_tracers = static_cast<uint32_t>(tracers);
auto& logger = jlogger->nativeInstance();
return SamplingProfiler::getInstance().initialize(
logger,
available_tracers,
makeAvailableTracers(
logger, available_tracers, native_tracer_unwind_dex_frames));
logger,
available_tracers,
native_tracer_unwind_dex_frames,
native_tracer_unwind_thread_pri));
}

static void nativeLoggerLoop(fbjni::alias_ref<jobject>) {
Expand Down
2 changes: 2 additions & 0 deletions java/main/com/facebook/profilo/core/ProfiloConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public static String abortReasonName(int abortReason) {
"provider.stack_trace.thread_detect_interval_ms";
public static final String PROVIDER_PARAM_NATIVE_STACK_TRACE_UNWIND_DEX_FRAMES =
"provider.native_stack_trace.unwind_dex_frames";
public static final String PROVIDER_PARAM_NATIVE_STACK_TRACE_UNWINDER_THREAD_PRIORITY =
"provider.native_stack_trace.unwinder_thread_pri";

// Keys to query conditions in a config
public static final String TRACE_CONFIG_DURATION_CONDITION = "trace_config.duration_condition";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,22 @@ static synchronized int getAvailableTracers() {
}

public static synchronized boolean init(
Context context, MultiBufferLogger logger, boolean nativeTracerUnwindDexFrames)
Context context,
MultiBufferLogger logger,
boolean nativeTracerUnwindDexFrames,
int nativeTracerUnwinderThreadPriority)
throws Exception {
if (sInitialized) {
return true;
}

sAvailableTracers = calculateTracers(context);
sInitialized = nativeInitialize(logger, sAvailableTracers, nativeTracerUnwindDexFrames);
sInitialized =
nativeInitialize(
logger,
sAvailableTracers,
nativeTracerUnwindDexFrames,
nativeTracerUnwinderThreadPriority);
return sInitialized;
}

Expand Down Expand Up @@ -164,7 +172,10 @@ public static void resetFrameworkNamesSet() {
/** Note: Init correctness is guaranteed for Main Thread only at this point. */
@DoNotStrip
private static native boolean nativeInitialize(
MultiBufferLogger logger, int availableTracers, boolean nativeTracerUnwindDexFrames);
MultiBufferLogger logger,
int availableTracers,
boolean nativeTracerUnwindDexFrames,
int nativeTracerUnwinderThreadPriority);

@DoNotStrip
private static native boolean nativeStartProfiling(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ private static int providersToTracers(int providers) {
*
* @return <code>true</code> if initProfiler was successful and <code>false</code> otherwise.
*/
private synchronized boolean initProfiler(boolean nativeTracerUnwindDexFrames) {
private synchronized boolean initProfiler(
boolean nativeTracerUnwindDexFrames, int nativeTracerUnwinderThreadPriority) {
try {
return CPUProfiler.init(mContext, getLogger(), nativeTracerUnwindDexFrames);
return CPUProfiler.init(
mContext, getLogger(), nativeTracerUnwindDexFrames, nativeTracerUnwinderThreadPriority);
} catch (Exception ex) {
Log.e(LOG_TAG, ex.getMessage(), ex);
return false;
Expand All @@ -112,8 +114,9 @@ private synchronized boolean enableInternal(
int threadDetectIntervalMs,
int enabledProviders,
boolean nativeTracerUnwindDexFrames,
int nativeTracerUnwinderThreadPriority,
TimeSource timeSource) {
if (!initProfiler(nativeTracerUnwindDexFrames)) {
if (!initProfiler(nativeTracerUnwindDexFrames, nativeTracerUnwinderThreadPriority)) {
return false;
}

Expand Down Expand Up @@ -216,6 +219,9 @@ protected void enable() {
context.enabledProviders,
context.mTraceConfigExtras.getBoolParam(
ProfiloConstants.PROVIDER_PARAM_NATIVE_STACK_TRACE_UNWIND_DEX_FRAMES, false),
context.mTraceConfigExtras.getIntParam(
ProfiloConstants.PROVIDER_PARAM_NATIVE_STACK_TRACE_UNWINDER_THREAD_PRIORITY,
ProfiloConstants.TRACE_CONFIG_PARAM_LOGGER_PRIORITY_DEFAULT),
timeSource);
if (!enabled) {
return;
Expand Down

0 comments on commit bd33a28

Please sign in to comment.