• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 #ifndef PBREADER_FILE_HEADER_H
16 #define PBREADER_FILE_HEADER_H
17 namespace SysTuning {
18 namespace TraceStreamer {
19 struct ProfilerTraceFileHeader {
20     // Some space is reserved to facilitate the subsequent addition of fields in the header
21     static constexpr uint32_t HEADER_SIZE = 1024;
22     static constexpr uint32_t SHA256_SIZE = 256 / 8;
23     static constexpr uint64_t HEADER_MAGIC = 0x464F5250534F484FuLL;
24     static constexpr uint32_t V_MAJOR = 0x0001;
25     static constexpr uint32_t V_MAJOR_BITS = 16;
26     static constexpr uint32_t TRACE_VERSION = V_MAJOR << V_MAJOR_BITS;
27     static constexpr uint8_t PLUGIN_MODULE_NAME_MAX = 127;
28     static constexpr uint8_t PLUGIN_MODULE_VERSION_MAX = 7;
29     enum DataType {
30         HIPROFILER_PROTOBUF_BIN = 0,
31         HIPERF_DATA,
32         STANDALONE_DATA = 1000,
33         UNKNOW_TYPE = 1024,
34     };
35     struct HeaderData {
36         // Magic number, used to distinguish offline files
37         uint64_t magic = HEADER_MAGIC;
38         // Total length, which can be used to check whether the document is truncated;
39         uint64_t length = HEADER_SIZE;
40         uint32_t version = TRACE_VERSION;
41         // The number of segments in the load data. The number of segments is even. One describes the length L and the
42         // other describes the next data v
43         uint32_t segments = 0;
44         // Sha256 of load data is used to verify whether the load data is complete;
45         uint8_t sha256[SHA256_SIZE] = {};
46         uint32_t dataType = UNKNOW_TYPE;
47         // clock
48         uint64_t boottime = 0;
49         uint64_t realtime = 0;
50         uint64_t realtimeCoarse = 0;
51         uint64_t monotonic = 0;
52         uint64_t monotonicCoarse = 0;
53         uint64_t monotonicRaw = 0;
54         char standalonePluginName[PLUGIN_MODULE_NAME_MAX + 1] = "";
55         char pluginVersion[PLUGIN_MODULE_VERSION_MAX + 1] = "";
56         uint64_t durationNs = 0;
57     } __attribute__((packed));
58     HeaderData data = {};
59     uint8_t padding_[HEADER_SIZE - sizeof(data)] = {};
60 };
61 struct ProfilerPluginDataHeader {
62     std::string name = "";
63     uint32_t status;
64     int32_t clockId;
65     uint64_t tvSec;
66     uint64_t tvNsec;
67     std::string version = ""; // "1.01"
68     uint32_t sampleInterval;  // Polling plugin collection interval(ms)
69 };
70 const std::string EBPF_PLUGIN_NAME = "hiebpf-plugin";
71 } // namespace TraceStreamer
72 } // namespace SysTuning
73 #endif // PBREADER_FILE_HEADER_H
74