Skip to content

Commit

Permalink
add oboe namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 committed Jan 23, 2025
1 parent 6639e15 commit 858dde4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 80 deletions.
2 changes: 1 addition & 1 deletion apps/OboeTester/app/src/main/cpp/jni-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Java_com_mobileer_oboetester_OboeAudioStream_close(JNIEnv *env, jobject, jint st

JNIEXPORT void JNICALL
Java_com_mobileer_oboetester_TestAudioActivity_setUseAlternativeAdpf(JNIEnv *env, jobject, jboolean enabled) {
AdpfWrapper::setUseAlternative(enabled);
oboe::AdpfWrapper::setUseAlternative(enabled);
}

JNIEXPORT jint JNICALL
Expand Down
2 changes: 2 additions & 0 deletions src/common/AdpfWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "OboeDebug.h"
#include "Trace.h"

using namespace oboe;

typedef APerformanceHintManager* (*APH_getManager)();
typedef APerformanceHintSession* (*APH_createSession)(APerformanceHintManager*, const int32_t*,
size_t, int64_t);
Expand Down
105 changes: 54 additions & 51 deletions src/common/AdpfWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,69 @@
#include <unistd.h>
#include <mutex>

struct APerformanceHintManager;
struct APerformanceHintSession;
namespace oboe {

typedef struct APerformanceHintManager APerformanceHintManager;
typedef struct APerformanceHintSession APerformanceHintSession;
struct APerformanceHintManager;
struct APerformanceHintSession;

class AdpfWrapper {
public:
/**
* Create an ADPF session that can be used to boost performance.
* @param threadId
* @param targetDurationNanos - nominal period of isochronous task
* @return zero or negative error
*/
int open(pid_t threadId,
int64_t targetDurationNanos);
typedef struct APerformanceHintManager APerformanceHintManager;
typedef struct APerformanceHintSession APerformanceHintSession;

bool isOpen() const {
return (mHintSession != nullptr);
}
class AdpfWrapper {
public:
/**
* Create an ADPF session that can be used to boost performance.
* @param threadId
* @param targetDurationNanos - nominal period of isochronous task
* @return zero or negative error
*/
int open(pid_t threadId,
int64_t targetDurationNanos);

void close();
bool isOpen() const {
return (mHintSession != nullptr);
}

/**
* Call this at the beginning of the callback that you are measuring.
*/
void onBeginCallback();
void close();

/**
* Call this at the end of the callback that you are measuring.
* It is OK to skip this if you have a short callback.
*/
void onEndCallback(double durationScaler);
/**
* Call this at the beginning of the callback that you are measuring.
*/
void onBeginCallback();

/**
* For internal use only!
* This is a hack for communicating with experimental versions of ADPF.
* @param enabled
*/
static void setUseAlternative(bool enabled) {
sUseAlternativeHack = enabled;
}
/**
* Call this at the end of the callback that you are measuring.
* It is OK to skip this if you have a short callback.
*/
void onEndCallback(double durationScaler);

/**
* Report the measured duration of a callback.
* This is normally called by onEndCallback().
* You may want to call this directly in order to give an advance hint of a jump in workload.
* @param actualDurationNanos
*/
void reportActualDuration(int64_t actualDurationNanos);
/**
* For internal use only!
* This is a hack for communicating with experimental versions of ADPF.
* @param enabled
*/
static void setUseAlternative(bool enabled) {
sUseAlternativeHack = enabled;
}

void reportWorkload(int32_t appWorkload);
/**
* Report the measured duration of a callback.
* This is normally called by onEndCallback().
* You may want to call this directly in order to give an advance hint of a jump in workload.
* @param actualDurationNanos
*/
void reportActualDuration(int64_t actualDurationNanos);

private:
std::mutex mLock;
APerformanceHintSession* mHintSession = nullptr;
int64_t mBeginCallbackNanos = 0;
static bool sUseAlternativeHack;
int32_t mPreviousWorkload = 0;
double mNanosPerWorkloadUnit = 0.0;
};
void reportWorkload(int32_t appWorkload);

private:
std::mutex mLock;
APerformanceHintSession *mHintSession = nullptr;
int64_t mBeginCallbackNanos = 0;
static bool sUseAlternativeHack;
int32_t mPreviousWorkload = 0;
double mNanosPerWorkloadUnit = 0.0;
};

}
#endif //SYNTHMARK_ADPF_WRAPPER_H
35 changes: 18 additions & 17 deletions src/common/Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "Trace.h"
#include "OboeDebug.h"

using namespace oboe;

static char buffer[256];

// Tracing functions
Expand All @@ -38,33 +40,32 @@ typedef void *(*fp_ATrace_setCounter)(const char *counterName, int64_t counterVa

typedef bool *(*fp_ATrace_isEnabled)(void);

bool Trace::mIsTracingSupported = false;
bool Trace::mIsSetCounterSupported = false;
bool Trace::mIsTracingEnabled = false;
bool Trace::mIsSetCounterSupported = false;
bool Trace::mHasErrorBeenShown = false;

void Trace::beginSection(const char *format, ...){
if (mIsTracingSupported) {
if (mIsTracingEnabled) {
va_list va;
va_start(va, format);
vsprintf(buffer, format, va);
ATrace_beginSection(buffer);
va_end(va);
}
} else {
if (mIsTracingEnabled) {
va_list va;
va_start(va, format);
vsprintf(buffer, format, va);
ATrace_beginSection(buffer);
va_end(va);
} else if (!mHasErrorBeenShown) {
LOGE("Tracing is either not initialized (call Trace::initialize()) "
"or not supported on this device");
mHasErrorBeenShown = true;
}
}

void Trace::endSection() {
if (mIsTracingSupported && mIsTracingEnabled) {
if (mIsTracingEnabled) {
ATrace_endSection();
}
}

void Trace::setCounter(const char *counterName, int64_t counterValue) {
if (mIsSetCounterSupported && mIsTracingEnabled) {
if (mIsSetCounterSupported) {
ATrace_setCounter(counterName, counterValue);
}
}
Expand All @@ -90,12 +91,12 @@ void Trace::initialize() {
reinterpret_cast<fp_ATrace_isEnabled >(
dlsym(lib, "ATrace_isEnabled"));

if (ATrace_beginSection != nullptr && ATrace_endSection != nullptr && ATrace_isEnabled != nullptr){
mIsTracingEnabled = ATrace_isEnabled();
LOGD("Trace::initialize isEnabled: %d", mIsTracingEnabled);
mIsTracingSupported = true;
if (ATrace_beginSection != nullptr && ATrace_endSection != nullptr && ATrace_isEnabled != nullptr && ATrace_isEnabled()){
mIsTracingEnabled = true;
if (ATrace_setCounter != nullptr) {
mIsSetCounterSupported = true;
} else {
LOGE("setCounter not supported");
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions src/common/Trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@

#include <cstdint>

class Trace {
namespace oboe {

public:
static void beginSection(const char *format, ...);
static void endSection();
static void setCounter(const char *counterName, int64_t counterValue);
static void initialize();
class Trace {

private:
static bool mIsTracingSupported;
static bool mIsSetCounterSupported;
static bool mIsTracingEnabled;
};
public:
static void beginSection(const char *format, ...);

static void endSection();

static void setCounter(const char *counterName, int64_t counterValue);

static void initialize();

private:
static bool mIsTracingEnabled;
static bool mIsSetCounterSupported;
static bool mHasErrorBeenShown;
};

}
#endif //OBOE_TRACE_H

0 comments on commit 858dde4

Please sign in to comment.