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 5, 2023
1 parent af34cc0 commit 69abfd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
41 changes: 30 additions & 11 deletions src/base/sys_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
namespace openmldb::base {

constexpr const char* MEM_TOTAL = "MemTotal";
constexpr const char* MEM_AVAILABLE = "MemAvailable";
constexpr const char* MEM_BUFFERS = "Buffers";
constexpr const char* MEM_CACHED = "Cached";
constexpr const char* MEM_FREE = "MemFree";
constexpr const char* SLAB = "Slab";

struct SysInfo {
uint64_t mem_total = 0; // unit is kB
uint64_t mem_used = 0; // unit is kB
uint64_t mem_available = 0; // unit is kB
uint64_t mem_total = 0; // unit is kB
uint64_t mem_used = 0; // unit is kB
uint64_t mem_free = 0; // unit is kB
uint64_t mem_buffers = 0; // unit is kB
uint64_t mem_cached = 0; // unit is kB
};

base::Status GetSysMem(SysInfo* info) {
Expand All @@ -51,6 +56,7 @@ base::Status GetSysMem(SysInfo* info) {
return {};
};
int parse_cnt = 0;
uint64_t slab = 0;
while (fgets(line, sizeof(line), fd)) {
absl::string_view str_view(line);
str_view = absl::StripAsciiWhitespace(str_view);
Expand All @@ -59,20 +65,33 @@ base::Status GetSysMem(SysInfo* info) {
return status;

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

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L65

Added line #L65 was not covered by tests
}
parse_cnt++;
} else if (absl::StartsWith(str_view, MEM_AVAILABLE)) {
if (auto status = parse(str_view, MEM_AVAILABLE, &info->mem_available); !status.OK()) {
} else if (absl::StartsWith(str_view, MEM_BUFFERS)) {
if (auto status = parse(str_view, MEM_BUFFERS, &info->mem_buffers); !status.OK()) {
return status;

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

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L70

Added line #L70 was not covered by tests
}
parse_cnt++;
} else if (absl::StartsWith(str_view, MEM_CACHED)) {
if (auto status = parse(str_view, MEM_CACHED, &info->mem_cached); !status.OK()) {
return status;

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

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L75

Added line #L75 was not covered by tests
}
parse_cnt++;
} else if (absl::StartsWith(str_view, MEM_FREE)) {
if (auto status = parse(str_view, MEM_FREE, &info->mem_free); !status.OK()) {
return status;

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

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L80

Added line #L80 was not covered by tests
}
parse_cnt++;
} else if (absl::StartsWith(str_view, SLAB)) {
if (auto status = parse(str_view, SLAB, &slab); !status.OK()) {
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++;
}
if (parse_cnt >= 2) {
break;
}
}
if (parse_cnt != 2) {
if (parse_cnt != 5) {
return {ReturnCode::kError, "fail to parse meminfo"};

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

View check run for this annotation

Codecov / codecov/patch

src/base/sys_info.h#L91

Added line #L91 was not covered by tests
}
info->mem_used = info->mem_total - info->mem_available;
info->mem_cached += slab;
info->mem_used = info->mem_total - info->mem_buffers - info->mem_cached - info->mem_free;
fclose(fd);
#endif
return {};
Expand Down
9 changes: 7 additions & 2 deletions src/base/sys_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ TEST_F(SystemInfoTest, GetMemory) {
ASSERT_TRUE(status.OK());
ASSERT_GT(info.mem_total, 0);
ASSERT_GT(info.mem_used, 0);
ASSERT_GT(info.mem_available, 0);
ASSERT_EQ(info.mem_total, info.mem_used + info.mem_available);
ASSERT_GT(info.mem_free, 0);
ASSERT_EQ(info.mem_total, info.mem_used + info.mem_buffers + info.mem_free + info.mem_cached);
/*printf("total:%lu\n", info.mem_total);
printf("used:%lu\n", info.mem_used);
printf("free:%lu\n", info.mem_free);
printf("buffers:%lu\n", info.mem_buffers);
printf("cached:%lu\n", info.mem_cached);*/
}

} // namespace base
Expand Down
3 changes: 2 additions & 1 deletion src/client/tablet_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ base::Status TabletClient::Put(uint32_t tid, uint32_t pid, uint64_t time, const
return {response.code(), response.msg()};
}

base::Status TabletClient::Put(uint32_t tid, uint32_t pid, const std::string& pk, uint64_t time, const std::string& value) {
base::Status TabletClient::Put(uint32_t tid, uint32_t pid, const std::string& pk, uint64_t time,
const std::string& value) {
::openmldb::api::PutRequest request;
auto dim = request.add_dimensions();
dim->set_key(pk);
Expand Down

0 comments on commit 69abfd6

Please sign in to comment.