Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tsl/profiler/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ cc_library(
"//tsl/profiler/protobuf:profiler_options_proto_cc",
"//tsl/profiler/protobuf:xplane_proto_cc",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/synchronization",
"@xla//xla/tsl/platform:errors",
"@xla//xla/tsl/platform:status",
Expand All @@ -237,15 +238,18 @@ cc_library(
"@xla//xla/tsl/profiler:internal",
]),
deps = [
"//tsl/platform",
"//tsl/platform:thread_annotations",
"//tsl/profiler/protobuf:profiler_options_proto_cc",
"//tsl/profiler/protobuf:xplane_proto_cc",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/synchronization",
"@xla//xla/tsl/platform:env",
"@xla//xla/tsl/platform:errors",
"@xla//xla/tsl/platform:logging",
"@xla//xla/tsl/platform:status",
"@xla//xla/tsl/platform:types",
"@xla//xla/tsl/profiler/utils:xplane_builder",
"@xla//xla/tsl/profiler/utils:xplane_schema",
Expand All @@ -256,9 +260,7 @@ cc_library(
":profiler_factory",
":profiler_interface",
":profiler_lock",
"//tsl/platform",
"//tsl/platform:platform_port",
"@xla//xla/tsl/platform:status",
"@xla//xla/tsl/profiler/convert:post_process_single_host_xplane",
"@xla//xla/tsl/profiler/utils:time_utils",
]),
Expand Down
22 changes: 21 additions & 1 deletion tsl/profiler/lib/profiler_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,31 @@ absl::Status ProfilerSession::CollectData(XSpace* space) {
TF_RETURN_IF_ERROR(CollectDataInternal(space));
profiler::SetXSpacePidIfNotSet(*space, tsl::Env::Default()->GetProcessId());
profiler::PostProcessSingleHostXSpace(space, start_time_ns_, stop_time_ns_);
#endif
SetProfileOptionsIntoSpace(options_, space);
#endif
return absl::OkStatus();
}

#if !defined(IS_MOBILE_PLATFORM)
absl::StatusOr<profiler::ConsumeResult> ProfilerSession::Consume() {
absl::MutexLock l(mutex_);
TF_RETURN_IF_ERROR(status_);
if (profilers_ != nullptr) {
return profilers_->Consume();
}
return absl::UnimplementedError("Consume not implemented");
}

absl::Status ProfilerSession::Serialize(std::any data, XSpace* space) {
absl::MutexLock l(mutex_);
TF_RETURN_IF_ERROR(status_);
if (profilers_ != nullptr) {
return profilers_->Serialize(std::move(data), space);
}
return absl::UnimplementedError("Serialize not implemented");
}
#endif

ProfilerSession::ProfilerSession(const ProfileOptions& options)
#if defined(IS_MOBILE_PLATFORM)
: status_(errors::Unimplemented(
Expand Down
11 changes: 11 additions & 0 deletions tsl/profiler/lib/profiler_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ limitations under the License.
#ifndef TENSORFLOW_TSL_PROFILER_LIB_PROFILER_SESSION_H_
#define TENSORFLOW_TSL_PROFILER_LIB_PROFILER_SESSION_H_

#include <any>
#include <functional>
#include <memory>
#include <vector>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "xla/tsl/platform/status.h"
#include "xla/tsl/platform/types.h"
Expand Down Expand Up @@ -67,6 +69,15 @@ class ProfilerSession {
absl::Status CollectData(tensorflow::profiler::XSpace* space)
TF_LOCKS_EXCLUDED(mutex_);

#if !defined(IS_MOBILE_PLATFORM)
// Consumes collected profile data without stopping the profiler.
absl::StatusOr<profiler::ConsumeResult> Consume() TF_LOCKS_EXCLUDED(mutex_);

// Serializes consumed profile data into XSpace.
absl::Status Serialize(std::any data, tensorflow::profiler::XSpace* space)
TF_LOCKS_EXCLUDED(mutex_);
#endif

private:
// Constructs an instance of the class and starts profiling
explicit ProfilerSession(const tensorflow::ProfileOptions& options);
Expand Down
Loading