• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 
17 #include "src/trace_processor/importers/common/system_info_tracker.h"
18 #include "perfetto/ext/base/string_utils.h"
19 
20 namespace perfetto {
21 namespace trace_processor {
22 
SystemInfoTracker()23 SystemInfoTracker::SystemInfoTracker() {}
24 SystemInfoTracker::~SystemInfoTracker() = default;
25 
SetKernelVersion(base::StringView name,base::StringView release)26 void SystemInfoTracker::SetKernelVersion(base::StringView name,
27                                          base::StringView release) {
28   if (name.empty() || release.empty() || name != "Linux") {
29     version_ = std::nullopt;
30     return;
31   }
32 
33   size_t first_dot_pos = release.find(".");
34   size_t second_dot_pos = release.find(".", first_dot_pos + 1);
35   auto major_version =
36       base::StringToUInt32(release.substr(0, first_dot_pos).ToStdString());
37   auto minor_version = base::StringToUInt32(
38       release.substr(first_dot_pos + 1, second_dot_pos - (first_dot_pos + 1))
39           .ToStdString());
40   version_ = VersionNumber{major_version.value(), minor_version.value()};
41 }
42 
43 }  // namespace trace_processor
44 }  // namespace perfetto
45