• R/O
  • HTTP
  • SSH
  • HTTPS

system-metrics: Commit


Commit MetaInfo

Revision7afcff9aec45014e88edc3d9d91aa072c65fa815 (tree)
Time2020-01-22 11:31:16
AuthorTomasz Konojacki <me@xenu...>
CommiterTomasz Konojacki

Log Message

Dssadsad

Change Summary

Incremental Difference

--- a/cxx/bsd.hxx
+++ b/cxx/bsd.hxx
@@ -32,12 +32,31 @@
3232
3333
3434 #ifndef __OpenBSD__
35-class sm_mib {
35+// A simple sysctl() wrapper.
36+//
37+// For example, the following code:
38+//
39+// int buf[100];
40+// sm_sysctl foo = sm_sysctl("some.sysctl");
41+// foo.call(buf);
42+//
43+// is roughly equivalent to:
44+//
45+// int buf[100];
46+// int mib[CTL_MAXNAME];
47+// size_t mib_len = CTL_MAXNAME, buf_len = sizeof(buf);
48+// sysctlnametomib("some.sysctl", mib, &mib_len);
49+// sysctl(mib, mib_len, buf, &buflen, NULL, 0);
50+//
51+// On failure, it throws an errno_exception.
52+//
53+// XXX: sometime in future tcb::span should be replaced with std::span
54+class sm_sysctl {
3655 public:
3756 int mib[CTL_MAXNAME];
3857 size_t mib_len = CTL_MAXNAME;
3958
40- sm_mib(const char *sysctl_name)
59+ sm_sysctl(const char *sysctl_name)
4160 {
4261 int ret = sysctlnametomib(sysctl_name, this->mib, &this->mib_len);
4362
--- a/cxx/dragonfly/dragonfly.cxx
+++ b/cxx/dragonfly/dragonfly.cxx
@@ -36,8 +36,6 @@ struct sm_private {
3636 std::vector<struct kinfo_cputime> kern_cputime_buf;
3737 };
3838
39-static struct sm_mib init_mib(const char *sysctl_name);
40-
4139 system_metrics::system_metrics()
4240 :_priv(new sm_private())
4341 {
@@ -51,9 +49,9 @@ uint64_t
5149 system_metrics::number_of_cpus()
5250 {
5351 int n_cpus[1];
54- static const sm_mib mib = sm_mib("hw.ncpu");
52+ static const sm_sysctl sc = sm_sysctl("hw.ncpu");
5553
56- mib.call(n_cpus);
54+ sc.call(n_cpus);
5755
5856 return n_cpus[0];
5957 }
@@ -62,9 +60,9 @@ struct cpu_times
6260 system_metrics::cpu_times()
6361 {
6462 long cp_time[CPUSTATES];
65- static const sm_mib mib = sm_mib("kern.cp_time");
63+ static const sm_sysctl sc = sm_sysctl("kern.cp_time");
6664
67- size_t ret_len = mib.call(cp_time);
65+ size_t ret_len = sc.call(cp_time);
6866
6967 struct cpu_times ret;
7068 ret.user = cp_time[CP_USER] + cp_time[CP_NICE];
@@ -78,12 +76,11 @@ std::vector<struct cpu_times>
7876 system_metrics::per_cpu_times()
7977 {
8078 auto &buf = this->_priv->kern_cputime_buf;
81- size_t buf_len = buf.size() * sizeof(buf[0]);
82- static const sm_mib mib = sm_mib("kern.cputime");
79+ static const sm_sysctl sc = sm_sysctl("kern.cputime");
8380
8481 size_t ret_len;
8582 try {
86- ret_len = mib.call(buf);
83+ ret_len = sc.call(buf);
8784 }
8885 catch (errno_exception &e) {
8986 if (e.code() == ENOMEM) {
Show on old repository browser