• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef TRACE_FILE_HEADER_H
16 #define TRACE_FILE_HEADER_H
17 
18 #include "plugin_module_api.h"
19 
20 enum DataType {
21     HIPROFILER_PROTOBUF_BIN = 0,
22     HIPERF_DATA,
23     STANDALONE_DATA = 1000,
24 };
25 
26 struct TraceFileHeader {
27     static constexpr uint32_t HEADER_SIZE = 1024; // 预留了一些空间,方便后续在头部添加字段
28     static constexpr uint32_t SHA256_SIZE = 256 / 8;
29     static constexpr uint64_t HEADER_MAGIC = 0x464F5250534F484FuLL;
30     static constexpr uint32_t V_MAJOR = 0x0001;
31     static constexpr uint32_t V_MAJOR_BITS = 16;
32     static constexpr uint32_t V_MINOR = 0x0000;
33     static constexpr uint32_t TRACE_VERSION = (V_MAJOR << V_MAJOR_BITS) | V_MINOR;
34 
35     struct HeaderData {
36         uint64_t magic = HEADER_MAGIC;  // 魔数,用于区分离线文件
37         uint64_t length = HEADER_SIZE;  // 总长度,可用于检验文件是否被截断;
38         uint32_t version = TRACE_VERSION;
39         uint32_t segments = 0; // 载荷数据中的段个数, 段个数为偶数,一个描述长度 L,一个描述接下来的数据 V
40         uint8_t sha256[SHA256_SIZE] = {}; // 载荷数据 的 SHA256 ,用于校验 载荷数据是否完整;
41         uint32_t dataType = DataType::HIPROFILER_PROTOBUF_BIN; // 存储数据类型
42         uint64_t boottime = 0;
43         uint64_t realtime = 0;
44         uint64_t realtimeCoarse = 0;
45         uint64_t monotonic = 0;
46         uint64_t monotonicCoarse = 0;
47         uint64_t monotonicRaw = 0;
48         char standalonePluginName[PLUGIN_MODULE_NAME_MAX + 1] = "";
49         char pluginVersion[PLUGIN_MODULE_VERSION_MAX + 1] = "";
50     } __attribute__((packed));
51     HeaderData data_ = {};
52     static_assert(sizeof(data_) < HEADER_SIZE, "The max length of the reserved header is 1024 bytes");
53     uint8_t padding_[HEADER_SIZE - sizeof(data_)] = {};
54 };
55 
56 #endif  // TRACE_FILE_HEADER_H