-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Reapply "Add trace_file metadata table"" into main
- Loading branch information
Showing
32 changed files
with
541 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/trace_processor/importers/common/scoped_active_trace_file.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "src/trace_processor/importers/common/scoped_active_trace_file.h" | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <string> | ||
|
||
#include "perfetto/ext/base/string_view.h" | ||
#include "src/trace_processor/importers/common/trace_file_tracker.h" | ||
#include "src/trace_processor/storage/trace_storage.h" | ||
#include "src/trace_processor/tables/metadata_tables_py.h" | ||
#include "src/trace_processor/types/trace_processor_context.h" | ||
|
||
namespace perfetto::trace_processor { | ||
ScopedActiveTraceFile::~ScopedActiveTraceFile() { | ||
if (is_valid_) { | ||
context_->trace_file_tracker->EndFile(row_); | ||
} | ||
} | ||
|
||
void ScopedActiveTraceFile::SetName(const std::string& name) { | ||
row_.set_name(context_->storage->InternString(base::StringView(name))); | ||
} | ||
|
||
void ScopedActiveTraceFile::SetTraceType(TraceType type) { | ||
row_.set_trace_type(context_->storage->InternString(TraceTypeToString(type))); | ||
} | ||
|
||
void ScopedActiveTraceFile::SetSize(size_t size) { | ||
row_.set_size(static_cast<int64_t>(size)); | ||
} | ||
|
||
void ScopedActiveTraceFile::AddSize(size_t size) { | ||
row_.set_size(static_cast<int64_t>(size) + row_.size()); | ||
} | ||
|
||
} // namespace perfetto::trace_processor |
77 changes: 77 additions & 0 deletions
77
src/trace_processor/importers/common/scoped_active_trace_file.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_SCOPED_ACTIVE_TRACE_FILE_H_ | ||
#define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_SCOPED_ACTIVE_TRACE_FILE_H_ | ||
|
||
#include <string> | ||
|
||
#include "src/trace_processor/tables/metadata_tables_py.h" | ||
#include "src/trace_processor/util/trace_type.h" | ||
|
||
namespace perfetto::trace_processor { | ||
|
||
class TraceProcessorContext; | ||
|
||
// RAII like object that represents a file currently being parsed. When | ||
// instances of this object go out of scope they will notify the | ||
// TraceFileTracker that we are done parsing the file. | ||
// This class also acts a handler for setting file related properties. | ||
class ScopedActiveTraceFile { | ||
public: | ||
~ScopedActiveTraceFile(); | ||
|
||
ScopedActiveTraceFile(const ScopedActiveTraceFile&) = delete; | ||
ScopedActiveTraceFile& operator=(const ScopedActiveTraceFile&) = delete; | ||
|
||
ScopedActiveTraceFile(ScopedActiveTraceFile&& o) | ||
: context_(o.context_), row_(o.row_), is_valid_(o.is_valid_) { | ||
o.is_valid_ = false; | ||
} | ||
|
||
ScopedActiveTraceFile& operator=(ScopedActiveTraceFile&& o) { | ||
context_ = o.context_; | ||
row_ = o.row_; | ||
is_valid_ = o.is_valid_; | ||
o.is_valid_ = false; | ||
return *this; | ||
} | ||
|
||
void SetTraceType(TraceType type); | ||
|
||
// For streamed files this method can be called for each chunk to update the | ||
// file size incrementally. | ||
void AddSize(size_t delta); | ||
|
||
private: | ||
friend class TraceFileTracker; | ||
ScopedActiveTraceFile(TraceProcessorContext* context, | ||
tables::TraceFileTable::RowReference row) | ||
: context_(context), row_(row), is_valid_(true) {} | ||
|
||
// Sets the file name. If this method is not called (sometimes we do not know | ||
// the file name, e.g. streaming data) the name is set to null. | ||
void SetName(const std::string& name); | ||
void SetSize(size_t size); | ||
|
||
TraceProcessorContext* context_; | ||
tables::TraceFileTable::RowReference row_; | ||
bool is_valid_; | ||
}; | ||
|
||
} // namespace perfetto::trace_processor | ||
|
||
#endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_SCOPED_ACTIVE_TRACE_FILE_H_ |
74 changes: 74 additions & 0 deletions
74
src/trace_processor/importers/common/trace_file_tracker.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "src/trace_processor/importers/common/trace_file_tracker.h" | ||
|
||
#include <cstddef> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "src/trace_processor/importers/common/metadata_tracker.h" | ||
#include "src/trace_processor/storage/metadata.h" | ||
#include "src/trace_processor/storage/trace_storage.h" | ||
#include "src/trace_processor/tables/metadata_tables_py.h" | ||
#include "src/trace_processor/types/trace_processor_context.h" | ||
#include "src/trace_processor/util/trace_type.h" | ||
|
||
namespace perfetto::trace_processor { | ||
|
||
ScopedActiveTraceFile TraceFileTracker::StartNewFile() { | ||
tables::TraceFileTable::Row row; | ||
if (!ancestors_.empty()) { | ||
row.parent_id = ancestors_.back(); | ||
} | ||
|
||
row.size = 0; | ||
row.trace_type = | ||
context_->storage->InternString(TraceTypeToString(kUnknownTraceType)); | ||
|
||
auto ref = | ||
context_->storage->mutable_trace_file_table()->Insert(row).row_reference; | ||
|
||
ancestors_.push_back(ref.id()); | ||
return ScopedActiveTraceFile(context_, std::move(ref)); | ||
} | ||
|
||
ScopedActiveTraceFile TraceFileTracker::StartNewFile(const std::string& name, | ||
TraceType type, | ||
size_t size) { | ||
auto file = StartNewFile(); | ||
file.SetName(name); | ||
file.SetTraceType(type); | ||
file.SetSize(size); | ||
return file; | ||
} | ||
|
||
void TraceFileTracker::EndFile( | ||
const tables::TraceFileTable::ConstRowReference& row) { | ||
PERFETTO_CHECK(!ancestors_.empty()); | ||
PERFETTO_CHECK(ancestors_.back() == row.id()); | ||
|
||
// First file (root) | ||
if (row.id().value == 0) { | ||
context_->metadata_tracker->SetMetadata(metadata::trace_size_bytes, | ||
Variadic::Integer(row.size())); | ||
context_->metadata_tracker->SetMetadata(metadata::trace_type, | ||
Variadic::String(row.trace_type())); | ||
} | ||
ancestors_.pop_back(); | ||
} | ||
|
||
} // namespace perfetto::trace_processor |
Oops, something went wrong.