diff options
Diffstat (limited to 'src/freebsd/btop_collect.cpp')
-rw-r--r-- | src/freebsd/btop_collect.cpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index a9cdf00..8d7aa0e 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -123,7 +123,7 @@ namespace Shared { mib[1] = HW_NCPU; int ncpu; size_t len = sizeof(ncpu); - if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1) { + if (sysctl(mib, 2, &ncpu, &len, nullptr, 0) == -1) { Logger::warning("Could not determine number of cores, defaulting to 1."); } else { coreCount = ncpu; @@ -143,21 +143,21 @@ namespace Shared { int64_t memsize = 0; size_t size = sizeof(memsize); - if (sysctlbyname("hw.physmem", &memsize, &size, NULL, 0) < 0) { + if (sysctlbyname("hw.physmem", &memsize, &size, nullptr, 0) < 0) { Logger::warning("Could not get memory size"); } totalMem = memsize; struct timeval result; size = sizeof(result); - if (sysctlbyname("kern.boottime", &result, &size, NULL, 0) < 0) { + if (sysctlbyname("kern.boottime", &result, &size, nullptr, 0) < 0) { Logger::warning("Could not get boot time"); } else { bootTime = result.tv_sec; } size = sizeof(kfscale); - if (sysctlbyname("kern.fscale", &kfscale, &size, NULL, 0) == -1) { + if (sysctlbyname("kern.fscale", &kfscale, &size, nullptr, 0) == -1) { kfscale = 2048; } @@ -185,7 +185,7 @@ namespace Shared { //* RAII wrapper for kvm_openfiles class kvm_openfiles_wrapper { - kvm_t* kd = NULL; + kvm_t* kd = nullptr; public: kvm_openfiles_wrapper(const char* execf, const char* coref, const char* swapf, int flags, char* err) { this->kd = kvm_openfiles(execf, coref, swapf, flags, err); @@ -217,7 +217,7 @@ namespace Cpu { string name; char buffer[1024]; size_t size = sizeof(buffer); - if (sysctlbyname("hw.model", &buffer, &size, NULL, 0) < 0) { + if (sysctlbyname("hw.model", &buffer, &size, nullptr, 0) < 0) { Logger::error("Failed to get CPU name"); return name; } @@ -264,13 +264,13 @@ namespace Cpu { if (Config::getB("show_coretemp") and Config::getB("check_temp")) { int32_t temp; size_t size = sizeof(temp); - if (sysctlbyname("dev.cpu.0.temperature", &temp, &size, NULL, 0) < 0) { + if (sysctlbyname("dev.cpu.0.temperature", &temp, &size, nullptr, 0) < 0) { Logger::warning("Could not get temp sensor - maybe you need to load the coretemp module"); } else { got_sensors = true; int temp; size_t size = sizeof(temp); - sysctlbyname("dev.cpu.0.coretemp.tjmax", &temp, &size, NULL, 0); //asuming the max temp is same for all cores + sysctlbyname("dev.cpu.0.coretemp.tjmax", &temp, &size, nullptr, 0); //asuming the max temp is same for all cores temp = (temp - 2732) / 10; // since it's an int, it's multiplied by 10, and offset to absolute zero... current_cpu.temp_max = temp; } @@ -284,7 +284,7 @@ namespace Cpu { int found = 0; bool got_package = false; size_t size = sizeof(p_temp); - if (sysctlbyname("hw.acpi.thermal.tz0.temperature", &p_temp, &size, NULL, 0) >= 0) { + if (sysctlbyname("hw.acpi.thermal.tz0.temperature", &p_temp, &size, nullptr, 0) >= 0) { got_package = true; p_temp = (p_temp - 2732) / 10; // since it's an int, it's multiplied by 10, and offset to absolute zero... } @@ -292,7 +292,7 @@ namespace Cpu { size = sizeof(temp); for (int i = 0; i < Shared::coreCount; i++) { string s = "dev.cpu." + std::to_string(i) + ".temperature"; - if (sysctlbyname(s.c_str(), &temp, &size, NULL, 0) >= 0) { + if (sysctlbyname(s.c_str(), &temp, &size, nullptr, 0) >= 0) { temp = (temp - 2732) / 10; if (not got_package) { p_temp += temp; @@ -317,7 +317,7 @@ namespace Cpu { unsigned int freq = 1; size_t size = sizeof(freq); - if (sysctlbyname("dev.cpu.0.freq", &freq, &size, NULL, 0) < 0) { + if (sysctlbyname("dev.cpu.0.freq", &freq, &size, nullptr, 0) < 0) { return ""; } return std::to_string(freq / 1000.0 ).substr(0, 3); // seems to be in MHz @@ -373,17 +373,17 @@ namespace Cpu { uint32_t percent = -1; size_t size = sizeof(percent); string status = "discharging"; - if (sysctlbyname("hw.acpi.battery.life", &percent, &size, NULL, 0) < 0) { + if (sysctlbyname("hw.acpi.battery.life", &percent, &size, nullptr, 0) < 0) { has_battery = false; } else { has_battery = true; size_t size = sizeof(seconds); - if (sysctlbyname("hw.acpi.battery.time", &seconds, &size, NULL, 0) < 0) { + if (sysctlbyname("hw.acpi.battery.time", &seconds, &size, nullptr, 0) < 0) { seconds = 0; } int state; size = sizeof(state); - if (sysctlbyname("hw.acpi.battery.state", &state, &size, NULL, 0) < 0) { + if (sysctlbyname("hw.acpi.battery.state", &state, &size, nullptr, 0) < 0) { status = "unknown"; } else { if (state == 2) { @@ -409,7 +409,7 @@ namespace Cpu { vector<array<long, CPUSTATES>> cpu_time(Shared::coreCount); size_t size = sizeof(long) * CPUSTATES * Shared::coreCount; - if (sysctlbyname("kern.cp_times", &cpu_time[0], &size, NULL, 0) == -1) { + if (sysctlbyname("kern.cp_times", &cpu_time[0], &size, nullptr, 0) == -1) { Logger::error("failed to get CPU times"); } long long global_totals = 0; @@ -565,13 +565,13 @@ namespace Mem { static std::unique_ptr<struct devinfo, decltype(std::free)*> curDevInfo (reinterpret_cast<struct devinfo*>(std::calloc(1, sizeof(struct devinfo))), std::free); cur.dinfo = curDevInfo.get(); - if (devstat_getdevs(NULL, &cur) != -1) { + if (devstat_getdevs(nullptr, &cur) != -1) { for (int i = 0; i < cur.dinfo->numdevs; i++) { auto d = cur.dinfo->devices[i]; string devStatName = "/dev/" + string(d.device_name) + std::to_string(d.unit_number); for (auto& [ignored, disk] : disks) { // find matching mountpoints - could be multiple as d.device_name is only ada (and d.unit_number is the device number), while the disk.dev is like /dev/ada0s1 if (disk.dev.string().rfind(devStatName, 0) == 0) { - devstat_compute_statistics(&d, NULL, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); + devstat_compute_statistics(&d, nullptr, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); assign_values(disk, total_bytes_read, total_bytes_write); string mountpoint = mapping.at(disk.dev); Logger::debug("dev " + devStatName + " -> " + mountpoint + " read=" + std::to_string(total_bytes_read) + " write=" + std::to_string(total_bytes_write)); @@ -594,7 +594,7 @@ namespace Mem { while (not std::feof(f())) { if (fgets(buf, len, f())) { char *name = std::strtok(buf, ": \n"); - char *value = std::strtok(NULL, ": \n"); + char *value = std::strtok(nullptr, ": \n"); if (string(name).find("dataset_name") != string::npos) { // create entry if datasetname matches with anything in mapping // relies on the fact that the dataset name is last value in the list @@ -627,7 +627,7 @@ namespace Mem { auto show_disks = Config::getB("show_disks"); auto swap_disk = Config::getB("swap_disk"); auto &mem = current_mem; - static bool snapped = (getenv("BTOP_SNAPPED") != NULL); + static bool snapped = (getenv("BTOP_SNAPPED") != nullptr); int mib[4]; u_int memActive, memWire, cachedMem, freeMem; @@ -635,12 +635,12 @@ namespace Mem { len = 4; sysctlnametomib("vm.stats.vm.v_active_count", mib, &len); len = sizeof(memActive); - sysctl(mib, 4, &(memActive), &len, NULL, 0); + sysctl(mib, 4, &(memActive), &len, nullptr, 0); memActive *= Shared::pageSize; len = 4; sysctlnametomib("vm.stats.vm.v_wire_count", mib, &len); len = sizeof(memWire); - sysctl(mib, 4, &(memWire), &len, NULL, 0); + sysctl(mib, 4, &(memWire), &len, nullptr, 0); memWire *= Shared::pageSize; mem.stats.at("used") = memWire + memActive; @@ -648,19 +648,19 @@ namespace Mem { len = sizeof(cachedMem); len = 4; sysctlnametomib("vm.stats.vm.v_cache_count", mib, &len); - sysctl(mib, 4, &(cachedMem), &len, NULL, 0); + sysctl(mib, 4, &(cachedMem), &len, nullptr, 0); cachedMem *= Shared::pageSize; mem.stats.at("cached") = cachedMem; len = sizeof(freeMem); len = 4; sysctlnametomib("vm.stats.vm.v_free_count", mib, &len); - sysctl(mib, 4, &(freeMem), &len, NULL, 0); + sysctl(mib, 4, &(freeMem), &len, nullptr, 0); freeMem *= Shared::pageSize; mem.stats.at("free") = freeMem; if (show_swap) { char buf[_POSIX2_LINE_MAX]; - Shared::kvm_openfiles_wrapper kd(NULL, _PATH_DEVNULL, NULL, O_RDONLY, buf); + Shared::kvm_openfiles_wrapper kd(nullptr, _PATH_DEVnullptr, nullptr, O_RDONLY, buf); struct kvm_swap swap[16]; int nswap = kvm_getswapinfo(kd(), swap, 16, 0); int totalSwap = 0, usedSwap = 0; @@ -850,8 +850,8 @@ namespace Net { string ipv4, ipv6; //? Iteration over all items in getifaddrs() list - for (auto *ifa = if_wrap(); ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) continue; + for (auto *ifa = if_wrap(); ifa != nullptr; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == nullptr) continue; family = ifa->ifa_addr->sa_family; const auto &iface = ifa->ifa_name; //? Update available interfaces vector and get status of interface @@ -868,7 +868,7 @@ namespace Net { //? Get IPv4 address if (family == AF_INET) { if (net[iface].ipv4.empty()) { - if (NULL != inet_ntop(family, &(reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr)->sin_addr), ip, IPBUFFER_MAXSIZE)) { + if (nullptr != inet_ntop(family, &(reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr)->sin_addr), ip, IPBUFFER_MAXSIZE)) { net[iface].ipv4 = ip; } else { @@ -880,7 +880,7 @@ namespace Net { //? Get IPv6 address else if (family == AF_INET6) { if (net[iface].ipv6.empty()) { - if (NULL != inet_ntop(family, &(reinterpret_cast<struct sockaddr_in6*>(ifa->ifa_addr)->sin6_addr), ip, IPBUFFER_MAXSIZE)) { + if (nullptr != inet_ntop(family, &(reinterpret_cast<struct sockaddr_in6*>(ifa->ifa_addr)->sin6_addr), ip, IPBUFFER_MAXSIZE)) { net[iface].ipv6 = ip; } else { int errsv = errno; @@ -893,15 +893,15 @@ namespace Net { unordered_flat_map<string, std::tuple<uint64_t, uint64_t>> ifstats; int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; size_t len; - if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { + if (sysctl(mib, 6, nullptr, &len, nullptr, 0) < 0) { Logger::error("failed getting network interfaces"); } else { std::unique_ptr<char[]> buf(new char[len]); - if (sysctl(mib, 6, buf.get(), &len, NULL, 0) < 0) { + if (sysctl(mib, 6, buf.get(), &len, nullptr, 0) < 0) { Logger::error("failed getting network interfaces"); } else { char *lim = buf.get() + len; - char *next = NULL; + char *next = nullptr; for (next = buf.get(); next < lim;) { struct if_msghdr *ifm = (struct if_msghdr *)next; next += ifm->ifm_msglen; @@ -1078,7 +1078,7 @@ namespace Proc { //? Process runtime : current time - start time (both in unix time - seconds since epoch) struct timeval currentTime; - gettimeofday(¤tTime, NULL); + gettimeofday(¤tTime, nullptr); detailed.elapsed = sec_to_dhms(currentTime.tv_sec - detailed.entry.cpu_s); // only interested in second granularity, so ignoring tc_usec if (detailed.elapsed.size() > 8) detailed.elapsed.resize(detailed.elapsed.size() - 3); @@ -1133,7 +1133,7 @@ namespace Proc { vector<array<long, CPUSTATES>> cpu_time(Shared::coreCount); size_t size = sizeof(long) * CPUSTATES * Shared::coreCount; - if (sysctlbyname("kern.cp_times", &cpu_time[0], &size, NULL, 0) == -1) { + if (sysctlbyname("kern.cp_times", &cpu_time[0], &size, nullptr, 0) == -1) { Logger::error("failed to get CPU times"); } cputimes = 0; @@ -1152,12 +1152,12 @@ namespace Proc { should_filter = true; found.clear(); struct timeval currentTime; - gettimeofday(¤tTime, NULL); + gettimeofday(¤tTime, nullptr); const double timeNow = currentTime.tv_sec + (currentTime.tv_usec / 1'000'000); int count = 0; char buf[_POSIX2_LINE_MAX]; - Shared::kvm_openfiles_wrapper kd(NULL, _PATH_DEVNULL, NULL, O_RDONLY, buf); + Shared::kvm_openfiles_wrapper kd(nullptr, _PATH_DEVnullptr, nullptr, O_RDONLY, buf); const struct kinfo_proc* kprocs = kvm_getprocs(kd(), KERN_PROC_PROC, 0, &count); for (int i = 0; i < count; i++) { @@ -1179,7 +1179,7 @@ namespace Proc { //? Get program name, command, username, parent pid, nice and status if (no_cache) { - if (kproc->ki_comm == NULL or kproc->ki_comm == "idle"s) { + if (kproc->ki_comm == nullptr or kproc->ki_comm == "idle"s) { current_procs.pop_back(); found.pop_back(); continue; @@ -1342,8 +1342,8 @@ namespace Tools { struct timeval ts, currTime; std::size_t len = sizeof(ts); int mib[2] = {CTL_KERN, KERN_BOOTTIME}; - if (sysctl(mib, 2, &ts, &len, NULL, 0) != -1) { - gettimeofday(&currTime, NULL); + if (sysctl(mib, 2, &ts, &len, nullptr, 0) != -1) { + gettimeofday(&currTime, nullptr); return currTime.tv_sec - ts.tv_sec; } return 0.0; |