• 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 
19 #include <cstddef>
20 #include <optional>
21 
22 #include "perfetto/ext/base/string_utils.h"
23 #include "perfetto/ext/base/string_view.h"
24 #include "src/trace_processor/types/version_number.h"
25 
26 namespace perfetto::trace_processor {
27 
28 SystemInfoTracker::SystemInfoTracker() = default;
29 SystemInfoTracker::~SystemInfoTracker() = default;
30 
SetKernelVersion(base::StringView name,base::StringView release)31 void SystemInfoTracker::SetKernelVersion(base::StringView name,
32                                          base::StringView release) {
33   if (name.empty() || release.empty() || name != "Linux") {
34     version_ = std::nullopt;
35     return;
36   }
37 
38   size_t first_dot_pos = release.find(".");
39   size_t second_dot_pos = release.find(".", first_dot_pos + 1);
40   auto major_version =
41       base::StringToUInt32(release.substr(0, first_dot_pos).ToStdString());
42   auto minor_version = base::StringToUInt32(
43       release.substr(first_dot_pos + 1, second_dot_pos - (first_dot_pos + 1))
44           .ToStdString());
45   if (!major_version || !minor_version) {
46     version_ = std::nullopt;
47     return;
48   }
49   version_ = VersionNumber{major_version.value(), minor_version.value()};
50 }
51 
52 }  // namespace perfetto::trace_processor
53