mirror of
https://github.com/zebrajr/tensorflow.git
synced 2025-12-06 12:20:11 +01:00
Allow ProfilerFactory to return a nullptr ProfilerInterface
PiperOrigin-RevId: 368888650 Change-Id: I6d76435f8dfb376c5c8108d778efbf11d2e2b939
This commit is contained in:
parent
63019e2b06
commit
fb4e94e3fd
|
|
@ -47,6 +47,8 @@ void CreateProfilers(
|
|||
mutex_lock lock(mu);
|
||||
for (auto factory : *GetFactories()) {
|
||||
if (auto profiler = factory(options)) {
|
||||
// A factory might return nullptr based on options.
|
||||
if (profiler == nullptr) continue;
|
||||
result->push_back(std::move(profiler));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,16 @@ limitations under the License.
|
|||
namespace tensorflow {
|
||||
namespace profiler {
|
||||
|
||||
// A ProfilerFactory returns an instance of ProfilerInterface if ProfileOptions
|
||||
// require it. Otherwise, it might return nullptr.
|
||||
using ProfilerFactory =
|
||||
std::unique_ptr<ProfilerInterface> (*)(const ProfileOptions&);
|
||||
|
||||
// Registers a profiler factory. Should be invoked at most once per factory.
|
||||
void RegisterProfilerFactory(ProfilerFactory factory);
|
||||
|
||||
// Invokes all registered profiler factories with the given options, and
|
||||
// returns the instantiated (non-null) profiler interfaces in result.
|
||||
void CreateProfilers(const ProfileOptions& options,
|
||||
std::vector<std::unique_ptr<ProfilerInterface>>* result);
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ ProfilerSession::ProfilerSession(ProfileOptions options)
|
|||
status_ = Status::OK();
|
||||
|
||||
for (auto& profiler : profilers_) {
|
||||
DCHECK(profiler != nullptr);
|
||||
auto start_status = profiler->Start();
|
||||
if (!start_status.ok()) {
|
||||
LOG(WARNING) << "Encountered error while starting profiler: "
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user