• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_TOOLING_SAMPLER_SAMPLE_READER_H
17 #define PANDA_RUNTIME_TOOLING_SAMPLER_SAMPLE_READER_H
18 
19 #include "libpandabase/macros.h"
20 
21 #include "runtime/tooling/sampler/sample_info.h"
22 
23 namespace ark::tooling::sampler {
24 
25 // Reader of .aspt format
26 class SampleReader final {
27 public:
28     // clang-format off
29     static constexpr size_t SAMPLE_THREAD_ID_OFFSET     = 0 * sizeof(uint32_t);
30     static constexpr size_t SAMPLE_THREAD_STATUS_OFFSET = 1 * sizeof(uint32_t);
31     static constexpr size_t SAMPLE_STACK_SIZE_OFFSET    = 2 * sizeof(uint32_t);
32     static constexpr size_t SAMPLE_STACK_OFFSET         = 2 * sizeof(uint32_t) + 1 * sizeof(uintptr_t);
33 
34     static constexpr size_t PANDA_FILE_POINTER_OFFSET   = 1 * sizeof(uintptr_t);
35     static constexpr size_t PANDA_FILE_CHECKSUM_OFFSET  = 2 * sizeof(uintptr_t);
36     static constexpr size_t PANDA_FILE_NAME_SIZE_OFFSET = 2 * sizeof(uintptr_t) + 1 * sizeof(uint32_t);
37     static constexpr size_t PANDA_FILE_NAME_OFFSET      = 3 * sizeof(uintptr_t) + 1 * sizeof(uint32_t);
38     // clang-format on
39     inline explicit SampleReader(const char *filename);
40     ~SampleReader() = default;
41 
42     inline bool GetNextSample(SampleInfo *sampleOut);
43     inline bool GetNextModule(FileInfo *moduleOut);
44 
45     NO_COPY_SEMANTIC(SampleReader);
46     NO_MOVE_SEMANTIC(SampleReader);
47 
48 private:
49     // Using std::vector instead of PandaVector 'cause it should be used in tool without runtime
50     std::vector<char> buffer_;
51     std::vector<char *> sampleRowPtrs_;
52     std::vector<char *> moduleRowPtrs_;
53     size_t sampleRowCounter_ {0};
54     size_t moduleRowCounter_ {0};
55 };
56 
57 }  // namespace ark::tooling::sampler
58 
59 #endif  // PANDA_RUNTIME_TOOLING_SAMPLER_SAMPLE_READER_H
60