Add XPlaneBuilder::AddStatMetadata overload for temporary string
PiperOrigin-RevId: 314413233 Change-Id: I6fdca129f8951fd9988fcebd03df1d3e7043ce8f
This commit is contained in:
parent
609339dd19
commit
5c74699789
@ -50,13 +50,11 @@ XEventMetadata* XPlaneBuilder::GetOrCreateEventMetadata(int64 metadata_id) {
|
||||
return &metadata;
|
||||
}
|
||||
|
||||
// Returns XEventMetadata for the given event name.
|
||||
XEventMetadata* XPlaneBuilder::GetOrCreateEventMetadata(
|
||||
absl::string_view name) {
|
||||
XEventMetadata*& metadata = event_metadata_by_name_[name];
|
||||
if (metadata == nullptr) {
|
||||
metadata =
|
||||
XPlaneBuilder::GetOrCreateEventMetadata(++last_event_metadata_id_);
|
||||
metadata = GetOrCreateEventMetadata(++last_event_metadata_id_);
|
||||
metadata->set_name(std::string(name));
|
||||
}
|
||||
return metadata;
|
||||
@ -65,8 +63,7 @@ XEventMetadata* XPlaneBuilder::GetOrCreateEventMetadata(
|
||||
XEventMetadata* XPlaneBuilder::GetOrCreateEventMetadata(std::string&& name) {
|
||||
XEventMetadata*& metadata = event_metadata_by_name_[name];
|
||||
if (metadata == nullptr) {
|
||||
metadata =
|
||||
XPlaneBuilder::GetOrCreateEventMetadata(++last_event_metadata_id_);
|
||||
metadata = GetOrCreateEventMetadata(++last_event_metadata_id_);
|
||||
metadata->set_name(std::move(name));
|
||||
}
|
||||
return metadata;
|
||||
@ -78,29 +75,31 @@ XStatMetadata* XPlaneBuilder::GetOrCreateStatMetadata(int64 metadata_id) {
|
||||
return &metadata;
|
||||
}
|
||||
|
||||
// Returns XStatMetadata for the given stat name.
|
||||
XStatMetadata* XPlaneBuilder::GetOrCreateStatMetadata(absl::string_view name) {
|
||||
XStatMetadata*& metadata = stat_metadata_by_name_[name];
|
||||
if (metadata == nullptr) {
|
||||
metadata = XPlaneBuilder::GetOrCreateStatMetadata(++last_stat_metadata_id_);
|
||||
metadata = GetOrCreateStatMetadata(++last_stat_metadata_id_);
|
||||
metadata->set_name(std::string(name));
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
XLine* XPlaneBuilder::AddLine(int64 line_id) {
|
||||
XLine*& line = lines_by_id_[line_id];
|
||||
if (line == nullptr) {
|
||||
line = RawPlane()->add_lines();
|
||||
line->set_id(line_id);
|
||||
XStatMetadata* XPlaneBuilder::GetOrCreateStatMetadata(std::string&& name) {
|
||||
XStatMetadata*& metadata = stat_metadata_by_name_[name];
|
||||
if (metadata == nullptr) {
|
||||
metadata = GetOrCreateStatMetadata(++last_stat_metadata_id_);
|
||||
metadata->set_name(std::move(name));
|
||||
}
|
||||
return line;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
// Returns a builder for the line with the given id. Creates a new line if the
|
||||
// id was unused, otherwise the builder will add events to an existing line.
|
||||
XLineBuilder XPlaneBuilder::GetOrCreateLine(int64 line_id) {
|
||||
return XLineBuilder(AddLine(line_id), this);
|
||||
XLine*& line = lines_by_id_[line_id];
|
||||
if (line == nullptr) {
|
||||
line = plane_->add_lines();
|
||||
line->set_id(line_id);
|
||||
}
|
||||
return XLineBuilder(line, this);
|
||||
}
|
||||
|
||||
XEventBuilder XLineBuilder::AddEvent(const XEventMetadata& metadata) {
|
||||
|
@ -155,10 +155,13 @@ class XLineBuilder {
|
||||
explicit XLineBuilder(XLine* line, XPlaneBuilder* plane)
|
||||
: line_(line), plane_(plane) {}
|
||||
|
||||
int64 Id() { return line_->id(); }
|
||||
// Returns the owner plane.
|
||||
XPlaneBuilder* Plane() const { return plane_; }
|
||||
|
||||
int64 Id() const { return line_->id(); }
|
||||
void SetId(int64 id) { line_->set_id(id); }
|
||||
|
||||
int64 NumEvents() { return line_->events_size(); }
|
||||
int64 NumEvents() const { return line_->events_size(); }
|
||||
|
||||
void SetName(absl::string_view name) { line_->set_name(std::string(name)); }
|
||||
|
||||
@ -166,7 +169,7 @@ class XLineBuilder {
|
||||
if (line_->name().empty()) SetName(name);
|
||||
}
|
||||
|
||||
int64 TimestampNs() { return line_->timestamp_ns(); }
|
||||
int64 TimestampNs() const { return line_->timestamp_ns(); }
|
||||
// This will set the line start timestamp.
|
||||
// WARNING: The offset_ps of existing events will not be altered.
|
||||
void SetTimestampNs(int64 timestamp_ns) {
|
||||
@ -218,21 +221,43 @@ class XPlaneBuilder : public XStatsBuilder<XPlane> {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a builder for the line with the given id. Creates a new line if the
|
||||
// id was unused, otherwise the builder will add events to an existing line.
|
||||
XLineBuilder GetOrCreateLine(int64 line_id);
|
||||
|
||||
// Returns event metadata with the given id. Creates a new metadata if the id
|
||||
// was unused.
|
||||
// WARNING: If calling this function, don't call the string overloads below
|
||||
// on the same instance.
|
||||
XEventMetadata* GetOrCreateEventMetadata(int64 metadata_id);
|
||||
|
||||
// Returns event metadata with the given name. The id is internally assigned.
|
||||
// Creates a new metadata if the name was unused.
|
||||
// Using these overloads guarantees names are unique.
|
||||
// WARNING: If calling any of these overloads, do not call the integer one
|
||||
// above on the same instance.
|
||||
XEventMetadata* GetOrCreateEventMetadata(absl::string_view name);
|
||||
XEventMetadata* GetOrCreateEventMetadata(std::string&& name);
|
||||
inline XEventMetadata* GetOrCreateEventMetadata(const char* name) {
|
||||
XEventMetadata* GetOrCreateEventMetadata(const char* name) {
|
||||
return GetOrCreateEventMetadata(absl::string_view(name));
|
||||
}
|
||||
|
||||
// Returns stat metadata with the given id. Creates a new metadata if the id
|
||||
// was unused.
|
||||
// WARNING: If calling this function, don't call the string overloads below
|
||||
// on the same instance.
|
||||
XStatMetadata* GetOrCreateStatMetadata(int64 metadata_id);
|
||||
XStatMetadata* GetOrCreateStatMetadata(absl::string_view name);
|
||||
|
||||
protected:
|
||||
XPlane* RawPlane() const { return plane_; }
|
||||
XLine* AddLine(int64 line_id);
|
||||
// Returns stat metadata with the given name. The id is internally assigned.
|
||||
// Creates a new metadata if the name was unused.
|
||||
// Using these overloads guarantees names are unique.
|
||||
// WARNING: If calling any of these overloads, do not call the integer one
|
||||
// above on the same instance.
|
||||
XStatMetadata* GetOrCreateStatMetadata(absl::string_view name);
|
||||
XStatMetadata* GetOrCreateStatMetadata(std::string&& name);
|
||||
XStatMetadata* GetOrCreateStatMetadata(const char* name) {
|
||||
return GetOrCreateStatMetadata(absl::string_view(name));
|
||||
}
|
||||
|
||||
private:
|
||||
XPlane* plane_;
|
||||
|
Loading…
Reference in New Issue
Block a user