Apollo 10.0
自动驾驶开放平台
info.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
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
18
20
21namespace apollo {
22namespace cyber {
23namespace record {
24
26using apollo::cyber::record::kGB;
27using apollo::cyber::record::kKB;
28using apollo::cyber::record::kMB;
29
31
33
34bool Info::Display(const std::string& file) {
35 RecordFileReader file_reader;
36 if (!file_reader.Open(file)) {
37 AERROR << "open record file error. file: " << file;
38 return false;
39 }
40 proto::Header hdr = file_reader.GetHeader();
41
42 std::cout << setiosflags(std::ios::left);
43 std::cout << setiosflags(std::ios::fixed);
44
45 int w = 16;
46 // file name
47 std::cout << std::setw(w) << "record_file: " << file << std::endl;
48
49 // version
50 std::cout << std::setw(w) << "version: " << hdr.major_version() << "."
51 << hdr.minor_version() << std::endl;
52
53 // time and duration
54 auto begin_time_s = static_cast<double>(hdr.begin_time()) / 1e9;
55 auto end_time_s = static_cast<double>(hdr.end_time()) / 1e9;
56 auto duration_s = end_time_s - begin_time_s;
57 auto begin_time_str = UnixSecondsToString(static_cast<int>(begin_time_s));
58 auto end_time_str = UnixSecondsToString(static_cast<int>(end_time_s));
59 std::cout << std::setw(w) << "duration: " << duration_s << " Seconds"
60 << std::endl;
61 std::cout << std::setw(w) << "begin_time: " << begin_time_str << std::endl;
62 std::cout << std::setw(w) << "end_time: " << end_time_str << std::endl;
63
64 // size
65 std::cout << std::setw(w) << "size: " << hdr.size() << " Bytes";
66 if (hdr.size() >= kGB) {
67 std::cout << " (" << static_cast<float>(hdr.size()) / kGB << " GB)";
68 } else if (hdr.size() >= kMB) {
69 std::cout << " (" << static_cast<float>(hdr.size()) / kMB << " MB)";
70 } else if (hdr.size() >= kKB) {
71 std::cout << " (" << static_cast<float>(hdr.size()) / kKB << " KB)";
72 }
73 std::cout << std::endl;
74
75 // is_complete
76 std::cout << std::setw(w) << "is_complete:";
77 if (hdr.is_complete()) {
78 std::cout << "true";
79 } else {
80 std::cout << "false";
81 }
82 std::cout << std::endl;
83
84 // message_number
85 std::cout << std::setw(w) << "message_number: " << hdr.message_number()
86 << std::endl;
87
88 // channel_number
89 std::cout << std::setw(w) << "channel_number: " << hdr.channel_number()
90 << std::endl;
91
92 // read index section
93 if (!file_reader.ReadIndex()) {
94 AERROR << "read index section of the file fail. file: " << file;
95 return false;
96 }
97
98 // channel info
99 std::cout << std::setw(w) << "channel_info: " << std::endl;
100 proto::Index idx = file_reader.GetIndex();
101 for (int i = 0; i < idx.indexes_size(); ++i) {
102 ChannelCache* cache = idx.mutable_indexes(i)->mutable_channel_cache();
103 if (idx.mutable_indexes(i)->type() == proto::SectionType::SECTION_CHANNEL) {
104 std::cout << std::setw(w) << "";
105 std::cout << resetiosflags(std::ios::right);
106 std::cout << std::setw(50) << cache->name();
107 std::cout << setiosflags(std::ios::right);
108 std::cout << std::setw(8) << cache->message_number();
109 std::cout << std::setw(0) << " messages: ";
110 std::cout << cache->message_type();
111 std::cout << std::endl;
112 }
113 }
114 file_reader.Close();
115 return true;
116}
117
118} // namespace record
119} // namespace cyber
120} // namespace apollo
bool Display(const std::string &file)
Definition info.cc:34
const proto::Index & GetIndex() const
const proto::Header & GetHeader() const
bool Open(const std::string &path) override
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
optional uint64 channel_number
Definition record.proto:70
optional uint32 minor_version
Definition record.proto:64
optional uint32 major_version
Definition record.proto:63
optional uint64 begin_time
Definition record.proto:71
optional uint64 message_number
Definition record.proto:73