Skip to content

Commit 2e86d4f

Browse files
committed
Applied clang-format
1 parent dc69180 commit 2e86d4f

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

src/dyad/utils/memstat.c

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#endif
66

77
#include <dyad/utils/memstat.h>
8-
#include <sys/resource.h> // getrusage ()
9-
#include <linux/limits.h> // PATH_MAX
10-
#include <unistd.h> // sysconf(_SC_PAGESIZE)
8+
#include <linux/limits.h> // PATH_MAX
119
#include <stdio.h>
1210
#include <stdlib.h>
11+
#include <sys/resource.h> // getrusage ()
12+
#include <unistd.h> // sysconf(_SC_PAGESIZE)
1313

1414
typedef struct {
1515
unsigned long m_size, m_resident, m_share, m_text, m_lib, m_data, m_dt;
@@ -21,16 +21,22 @@ static int get_mem_status (statm_t* ms)
2121
unsigned long dummy;
2222
const char* statm_path = "/proc/self/statm";
2323

24-
FILE *f = fopen (statm_path, "r");
24+
FILE* f = fopen (statm_path, "r");
2525

2626
if (!ms || !f) {
2727
perror (statm_path);
2828
return EXIT_FAILURE;
2929
}
30-
if (7 != fscanf (f, "%lu %lu %lu %lu %lu %lu %lu",
31-
&(ms->m_size), &(ms->m_resident), &(ms->m_share),
32-
&(ms->m_text), &(ms->m_lib), &(ms->m_data), &(ms->m_dt)))
33-
{
30+
if (7
31+
!= fscanf (f,
32+
"%lu %lu %lu %lu %lu %lu %lu",
33+
&(ms->m_size),
34+
&(ms->m_resident),
35+
&(ms->m_share),
36+
&(ms->m_text),
37+
&(ms->m_lib),
38+
&(ms->m_data),
39+
&(ms->m_dt))) {
3440
perror (statm_path);
3541
return EXIT_FAILURE;
3642
}
@@ -42,18 +48,36 @@ int print_mem_status (const char* note, char* buf, unsigned bufsize)
4248
{
4349
statm_t ms;
4450
const char* nt = (!note ? "" : note);
45-
if (get_mem_status (&ms) != EXIT_SUCCESS) return 0;
51+
if (get_mem_status (&ms) != EXIT_SUCCESS)
52+
return 0;
4653

4754
if (!buf) {
48-
printf ("%s:\tsize %lu\tresident %lu\tshare %lu\ttext %lu"
49-
"\tlib %lu\tdata %lu\tdt %lu (in # pages of %ld)\n",
50-
nt, ms.m_size, ms.m_resident, ms.m_share, ms.m_text,
51-
ms.m_lib, ms.m_data, ms.m_dt, sysconf (_SC_PAGESIZE));
55+
printf (
56+
"%s:\tsize %lu\tresident %lu\tshare %lu\ttext %lu"
57+
"\tlib %lu\tdata %lu\tdt %lu (in # pages of %ld)\n",
58+
nt,
59+
ms.m_size,
60+
ms.m_resident,
61+
ms.m_share,
62+
ms.m_text,
63+
ms.m_lib,
64+
ms.m_data,
65+
ms.m_dt,
66+
sysconf (_SC_PAGESIZE));
5267
} else {
53-
return snprintf (buf, bufsize, "%s:\tsize %lu\tresident %lu\tshare %lu\t"
68+
return snprintf (buf,
69+
bufsize,
70+
"%s:\tsize %lu\tresident %lu\tshare %lu\t"
5471
"text %lu\tlib %lu\tdata %lu\tdt %lu (in # pages of %ld)\n",
55-
nt, ms.m_size, ms.m_resident, ms.m_share, ms.m_text,
56-
ms.m_lib, ms.m_data, ms.m_dt, sysconf (_SC_PAGESIZE));
72+
nt,
73+
ms.m_size,
74+
ms.m_resident,
75+
ms.m_share,
76+
ms.m_text,
77+
ms.m_lib,
78+
ms.m_data,
79+
ms.m_dt,
80+
sysconf (_SC_PAGESIZE));
5781
}
5882
return 0;
5983
}
@@ -62,28 +86,31 @@ int print_mem_status (const char* note, char* buf, unsigned bufsize)
6286
int print_rusage (const char* note, char* buf, unsigned bufsize)
6387
{
6488
struct rusage r_usage;
65-
getrusage (RUSAGE_SELF,&r_usage);
89+
getrusage (RUSAGE_SELF, &r_usage);
6690

6791
if (!buf) {
68-
printf ("%s:\n"
69-
"Memory usage: %ld kilobytes\n"
70-
"page reclaims: %ld\n"
71-
"page faults: %ld\n"
72-
"block input ops: %ld\n"
73-
"block input ops: %ld\n"
74-
"voluntary context switches: %ld\n"
75-
"involuntary context switches: %ld\n",
76-
(!note ? "" : note),
77-
r_usage.ru_maxrss,
78-
r_usage.ru_minflt,
79-
r_usage.ru_majflt,
80-
r_usage.ru_inblock,
81-
r_usage.ru_oublock,
82-
r_usage.ru_nvcsw,
83-
r_usage.ru_nivcsw);
92+
printf (
93+
"%s:\n"
94+
"Memory usage: %ld kilobytes\n"
95+
"page reclaims: %ld\n"
96+
"page faults: %ld\n"
97+
"block input ops: %ld\n"
98+
"block input ops: %ld\n"
99+
"voluntary context switches: %ld\n"
100+
"involuntary context switches: %ld\n",
101+
(!note ? "" : note),
102+
r_usage.ru_maxrss,
103+
r_usage.ru_minflt,
104+
r_usage.ru_majflt,
105+
r_usage.ru_inblock,
106+
r_usage.ru_oublock,
107+
r_usage.ru_nvcsw,
108+
r_usage.ru_nivcsw);
84109
} else {
85110
int n = 0;
86-
n = snprintf (buf, bufsize, "%s:\n"
111+
n = snprintf (buf,
112+
bufsize,
113+
"%s:\n"
87114
"Memory usage: %ld kilobytes\n"
88115
"page reclaims: %ld\n"
89116
"page faults: %ld\n"
@@ -121,7 +148,9 @@ int print_rusage_in_a_line (const char* note, char* buf, unsigned bufsize)
121148
r_usage.ru_nivcsw);
122149
} else {
123150
int n = 0;
124-
n = snprintf (buf, bufsize, "%s\tmemory usage: %ld %ld %ld %ld %ld %ld %ld\n",
151+
n = snprintf (buf,
152+
bufsize,
153+
"%s\tmemory usage: %ld %ld %ld %ld %ld %ld %ld\n",
125154
(!note ? "" : note),
126155
r_usage.ru_maxrss,
127156
r_usage.ru_minflt,

src/dyad/utils/memstat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ int print_rusage_in_a_line (const char* note, char* buf, unsigned bufsize);
1919
}
2020
#endif
2121

22-
#endif // DYAD_UTILS_MEMSTAT_H
22+
#endif // DYAD_UTILS_MEMSTAT_H

0 commit comments

Comments
 (0)