11285115cSWilliam A. Kennington III // Copyright 2021 Google LLC
21285115cSWilliam A. Kennington III //
31285115cSWilliam A. Kennington III // Licensed under the Apache License, Version 2.0 (the "License");
41285115cSWilliam A. Kennington III // you may not use this file except in compliance with the License.
51285115cSWilliam A. Kennington III // You may obtain a copy of the License at
61285115cSWilliam A. Kennington III //
71285115cSWilliam A. Kennington III //      http://www.apache.org/licenses/LICENSE-2.0
81285115cSWilliam A. Kennington III //
91285115cSWilliam A. Kennington III // Unless required by applicable law or agreed to in writing, software
101285115cSWilliam A. Kennington III // distributed under the License is distributed on an "AS IS" BASIS,
111285115cSWilliam A. Kennington III // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121285115cSWilliam A. Kennington III // See the License for the specific language governing permissions and
131285115cSWilliam A. Kennington III // limitations under the License.
141285115cSWilliam A. Kennington III 
151285115cSWilliam A. Kennington III #pragma once
161285115cSWilliam A. Kennington III 
17580abaffSWilly Tu #include <cstdint>
181285115cSWilliam A. Kennington III #include <string>
191285115cSWilliam A. Kennington III #include <string_view>
201285115cSWilliam A. Kennington III 
211285115cSWilliam A. Kennington III namespace metric_blob
221285115cSWilliam A. Kennington III {
231285115cSWilliam A. Kennington III 
241285115cSWilliam A. Kennington III struct TcommUtimeStime
251285115cSWilliam A. Kennington III {
261285115cSWilliam A. Kennington III     std::string tcomm;
271285115cSWilliam A. Kennington III     float utime;
281285115cSWilliam A. Kennington III     float stime;
291285115cSWilliam A. Kennington III };
301285115cSWilliam A. Kennington III 
31b63d6314SMichael Shen struct BootTimesMonotonic
32b63d6314SMichael Shen {
33b63d6314SMichael Shen     uint64_t firmwareTime = 0;
34b63d6314SMichael Shen     uint64_t loaderTime = 0;
35b63d6314SMichael Shen     uint64_t initrdTime = 0;
36b63d6314SMichael Shen     uint64_t userspaceTime = 0;
37b63d6314SMichael Shen     uint64_t finishTime = 0;
38b63d6314SMichael Shen     uint64_t powerOnSecCounterTime = 0;
39b63d6314SMichael Shen };
40b63d6314SMichael Shen 
411285115cSWilliam A. Kennington III TcommUtimeStime parseTcommUtimeStimeString(std::string_view content,
421285115cSWilliam A. Kennington III                                            long ticksPerSec);
43b63d6314SMichael Shen std::string readFileThenGrepIntoString(std::string_view fileName,
44b63d6314SMichael Shen                                        std::string_view grepStr = "");
451285115cSWilliam A. Kennington III bool isNumericPath(std::string_view path, int& value);
461285115cSWilliam A. Kennington III TcommUtimeStime getTcommUtimeStime(int pid, long ticksPerSec);
471285115cSWilliam A. Kennington III std::string getCmdLine(int pid);
481285115cSWilliam A. Kennington III bool parseMeminfoValue(std::string_view content, std::string_view keyword,
491285115cSWilliam A. Kennington III                        int& value);
501285115cSWilliam A. Kennington III bool parseProcUptime(const std::string_view content, double& uptime,
511285115cSWilliam A. Kennington III                      double& idleProcessTime);
52b63d6314SMichael Shen bool readMem(const uint32_t target, uint32_t& memResult);
53b63d6314SMichael Shen bool getBootTimesMonotonic(BootTimesMonotonic& btm);
541285115cSWilliam A. Kennington III long getTicksPerSec();
551285115cSWilliam A. Kennington III char controlCharsToSpace(char c);
561285115cSWilliam A. Kennington III std::string trimStringRight(std::string_view s);
571285115cSWilliam A. Kennington III 
58*4dba220dSWilly Tu struct EccCounts
59*4dba220dSWilly Tu {
60*4dba220dSWilly Tu     int32_t correctableErrCount;
61*4dba220dSWilly Tu     int32_t uncorrectableErrCount;
62*4dba220dSWilly Tu };
63*4dba220dSWilly Tu 
64*4dba220dSWilly Tu bool getECCErrorCounts(EccCounts& eccCounts);
65*4dba220dSWilly Tu 
661285115cSWilliam A. Kennington III } // namespace metric_blob
67