• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/trace_processor/importers/etm/mapping_version.h"
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <cstring>
22 #include <optional>
23 
24 #include "perfetto/base/logging.h"
25 #include "perfetto/trace_processor/trace_blob_view.h"
26 #include "src/trace_processor/importers/common/address_range.h"
27 
28 namespace perfetto::trace_processor::etm {
29 
MappingVersion(MappingId id,int64_t create_ts,AddressRange range,std::optional<TraceBlobView> content)30 MappingVersion::MappingVersion(MappingId id,
31                                int64_t create_ts,
32                                AddressRange range,
33                                std::optional<TraceBlobView> content)
34     : id_(id), create_ts_(create_ts), range_(range) {
35   if (content) {
36     content_ = std::move(*content);
37   }
38   PERFETTO_CHECK(content_.size() == range.length() ||
39                  content_.data() == nullptr);
40 }
41 
SplitFront(uint64_t mid)42 MappingVersion MappingVersion::SplitFront(uint64_t mid) {
43   PERFETTO_CHECK(range_.start() < mid && mid < range_.end());
44   AddressRange head(range_.start(), mid);
45   AddressRange tail(mid, range_.end());
46   uint64_t offset = mid - range_.start();
47 
48   TraceBlobView head_content;
49   TraceBlobView tail_content;
50   if (content_.size() != 0) {
51     head_content = content_.slice_off(0, offset);
52     tail_content = content_.slice_off(offset, content_.size() - offset);
53   }
54 
55   range_ = tail;
56   content_ = std::move(tail_content);
57 
58   return MappingVersion(id_, create_ts_, head, std::move(head_content));
59 }
60 
61 }  // namespace perfetto::trace_processor::etm
62