Force enabling TFLite tracing with TFLITE_ENABLE_DEFAULT_PROFILER define.
Manual setting such as debug.tflite.trace Android system property is not needed when compiled with this option. PiperOrigin-RevId: 329398936 Change-Id: I7bcf62bb32676a5c206d025ffa5d668d93f38548
This commit is contained in:
parent
78766489df
commit
3a3f914539
@ -29,10 +29,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/util.h"
|
#include "tensorflow/lite/util.h"
|
||||||
#include "tensorflow/lite/version.h"
|
#include "tensorflow/lite/version.h"
|
||||||
|
|
||||||
#if defined(TFLITE_ENABLE_DEFAULT_PROFILER)
|
|
||||||
#include "tensorflow/lite/profiling/platform_profiler.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -93,6 +93,9 @@ class ATraceProfiler : public tflite::Profiler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<tflite::Profiler> MaybeCreateATraceProfiler() {
|
std::unique_ptr<tflite::Profiler> MaybeCreateATraceProfiler() {
|
||||||
|
#if defined(TFLITE_ENABLE_DEFAULT_PROFILER)
|
||||||
|
return std::unique_ptr<tflite::Profiler>(new ATraceProfiler());
|
||||||
|
#else // TFLITE_ENABLE_DEFAULT_PROFILER
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
constexpr char kTraceProp[] = "debug.tflite.trace";
|
constexpr char kTraceProp[] = "debug.tflite.trace";
|
||||||
char trace_enabled[PROP_VALUE_MAX] = "";
|
char trace_enabled[PROP_VALUE_MAX] = "";
|
||||||
@ -102,6 +105,7 @@ std::unique_ptr<tflite::Profiler> MaybeCreateATraceProfiler() {
|
|||||||
}
|
}
|
||||||
#endif // __ANDROID__
|
#endif // __ANDROID__
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
#endif // TFLITE_ENABLE_DEFAULT_PROFILER
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace profiling
|
} // namespace profiling
|
||||||
|
@ -22,6 +22,9 @@ limitations under the License.
|
|||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace profiling {
|
namespace profiling {
|
||||||
|
|
||||||
|
// Creates a profiler which reports the traced events to the Android ATrace.
|
||||||
|
// Nullptr will be returned if the Android system property 'debug.tflite.trace'
|
||||||
|
// is not set or the property value is not 1.
|
||||||
std::unique_ptr<tflite::Profiler> MaybeCreateATraceProfiler();
|
std::unique_ptr<tflite::Profiler> MaybeCreateATraceProfiler();
|
||||||
|
|
||||||
} // namespace profiling
|
} // namespace profiling
|
||||||
|
@ -27,18 +27,26 @@ namespace profiling {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(ATraceProfilerTest, MaybeCreateATraceProfiler) {
|
TEST(ATraceProfilerTest, MaybeCreateATraceProfiler) {
|
||||||
auto default_profiler = MaybeCreateATraceProfiler();
|
auto initial_state_profiler = MaybeCreateATraceProfiler();
|
||||||
EXPECT_EQ(nullptr, default_profiler.get());
|
#if !defined(TFLITE_ENABLE_DEFAULT_PROFILER)
|
||||||
|
EXPECT_EQ(nullptr, initial_state_profiler.get());
|
||||||
|
#else
|
||||||
|
EXPECT_NE(nullptr, initial_state_profiler.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
if (__system_property_set("debug.tflite.trace", "1") == 0) {
|
if (__system_property_set("debug.tflite.trace", "1") == 0) {
|
||||||
auto profiler = MaybeCreateATraceProfiler();
|
auto on_state_profiler = MaybeCreateATraceProfiler();
|
||||||
EXPECT_NE(nullptr, profiler.get());
|
EXPECT_NE(nullptr, on_state_profiler.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__system_property_set("debug.tflite.trace", "0") == 0) {
|
if (__system_property_set("debug.tflite.trace", "0") == 0) {
|
||||||
auto no_profiler = MaybeCreateATraceProfiler();
|
auto off_state_profiler = MaybeCreateATraceProfiler();
|
||||||
EXPECT_EQ(nullptr, no_profiler.get());
|
#if !defined(TFLITE_ENABLE_DEFAULT_PROFILER)
|
||||||
|
EXPECT_EQ(nullptr, off_state_profiler.get());
|
||||||
|
#else
|
||||||
|
EXPECT_NE(nullptr, off_state_profiler.get());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif // __ANDROID__
|
#endif // __ANDROID__
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user