• 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 HTRACE_FILE_HEADER_H
16 #define HTRACE_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     uint8_t* data;
65     enum ClockId {
66         CLOCKID_REALTIME = 0,
67         CLOCKID_REALTIME_ALARM,  // since Linux 3.0; Linux-specific
68         CLOCKID_REALTIME_COARSE, // since Linux 2.6.32; Linux-specific
69         CLOCKID_TAI,             // since Linux 3.10; Linux-specific
70         CLOCKID_MONOTONIC,
71         CLOCKID_MONOTONIC_COARSE,   // since Linux 2.6.32; Linux-specific
72         CLOCKID_MONOTONIC_RAW,      // since Linux 2.6.28; Linux-specific
73         CLOCKID_BOOTTIME,           // since Linux 2.6.39; Linux-specific
74         CLOCKID_BOOTTIME_ALARM,     // since Linux 3.0; Linux-specific
75         CLOCKID_PROCESS_CPUTIME_ID, // since Linux 2.6.12
76         CLOCKID_THREAD_CPUTIME_ID   // since Linux 2.6.12
77     };
78     ClockId clockId;
79     uint64_t tvSec;
80     uint64_t tvNsec;
81     uint8_t* version;        // "1.01"
82     uint32_t sampleInterval; // Polling plugin collection interval(ms)
83 };
84 const std::string EBPF_PLUGIN_NAME = "hiebpf-plugin";
85 } // namespace TraceStreamer
86 } // namespace SysTuning
87 #endif // HTRACE_FILE_HEADER_H
88