Skip to content

Commit

Permalink
fix: fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Dec 8, 2023
1 parent 69abfd6 commit e880a28
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/base/sys_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ constexpr const char* MEM_TOTAL = "MemTotal";
constexpr const char* MEM_BUFFERS = "Buffers";
constexpr const char* MEM_CACHED = "Cached";
constexpr const char* MEM_FREE = "MemFree";
constexpr const char* SLAB = "Slab";
constexpr const char* SRECLAIMABLE = "SReclaimable";

/* We calculate MemAvailable as follows
* MemAvailable = MemFree + Buffers + Cached + SReclaimable
* refer https://www.kernel.org/doc/Documentation/filesystems/proc.txt
* */

struct SysInfo {
uint64_t mem_total = 0; // unit is kB
Expand All @@ -56,7 +61,7 @@ base::Status GetSysMem(SysInfo* info) {
return {};
};
int parse_cnt = 0;
uint64_t slab = 0;
uint64_t s_reclaimable = 0;
while (fgets(line, sizeof(line), fd)) {
absl::string_view str_view(line);
str_view = absl::StripAsciiWhitespace(str_view);
Expand All @@ -80,8 +85,8 @@ base::Status GetSysMem(SysInfo* info) {
return status;

Check warning on line 85 in src/base/sys_info.h

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L85

Added line #L85 was not covered by tests
}
parse_cnt++;
} else if (absl::StartsWith(str_view, SLAB)) {
if (auto status = parse(str_view, SLAB, &slab); !status.OK()) {
} else if (absl::StartsWith(str_view, SRECLAIMABLE)) {
if (auto status = parse(str_view, SRECLAIMABLE, &s_reclaimable); !status.OK()) {
return status;

Check warning on line 90 in src/base/sys_info.h

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L90

Added line #L90 was not covered by tests
}
parse_cnt++;
Expand All @@ -90,7 +95,7 @@ base::Status GetSysMem(SysInfo* info) {
if (parse_cnt != 5) {
return {ReturnCode::kError, "fail to parse meminfo"};

Check warning on line 96 in src/base/sys_info.h

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L96

Added line #L96 was not covered by tests
}
info->mem_cached += slab;
info->mem_cached += s_reclaimable;
info->mem_used = info->mem_total - info->mem_buffers - info->mem_cached - info->mem_free;
fclose(fd);
#endif
Expand Down

0 comments on commit e880a28

Please sign in to comment.