Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MojitOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sepia-pub
MojitOS
Merge requests
!7
Add memory counters and fix makefile
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add memory counters and fix makefile
pr_final
into
devel
Overview
0
Commits
18
Pipelines
2
Changes
2
Merged
floreal.risso
requested to merge
pr_final
into
devel
2 years ago
Overview
0
Commits
18
Pipelines
2
Changes
2
Expand
Add the sensor "memory_counters"
Fix ld error
Fix make
0
0
Merge request reports
Viewing commit
aa98e7f8
Prev
Next
Show latest version
2 files
+
98
−
88
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
aa98e7f8
format
· aa98e7f8
floreal.risso
authored
2 years ago
src/memory_counters.c
+
95
−
85
Options
@@ -10,111 +10,121 @@
@@ -10,111 +10,121 @@
static
const
char
*
path
=
"/proc/meminfo"
;
static
const
char
*
path
=
"/proc/meminfo"
;
typedef
struct
{
typedef
struct
{
KeyFinder
*
keys
;
KeyFinder
*
keys
;
unsigned
int
count
;
unsigned
int
count
;
FILE
*
file
;
FILE
*
file
;
}
MemoryCounters
;
}
MemoryCounters
;
GenericPointer
long_allocator
(
char
*
s
)
{
GenericPointer
long_allocator
(
char
*
s
)
long
value
=
atol
(
s
);
{
return
(
GenericPointer
)
value
;
long
value
=
atol
(
s
);
return
(
GenericPointer
)
value
;
}
}
KeyFinder
*
build_keyfinder
(
unsigned
int
count
,
unsigned
int
*
indexes
)
{
KeyFinder
*
build_keyfinder
(
unsigned
int
count
,
unsigned
int
*
indexes
)
KeyFinder
*
keys
=
(
KeyFinder
*
)
calloc
(
count
,
sizeof
(
KeyFinder
));
{
for
(
unsigned
int
i
=
0
;
i
<
count
;
i
++
)
{
KeyFinder
*
keys
=
(
KeyFinder
*
)
calloc
(
count
,
sizeof
(
KeyFinder
));
unsigned
int
idx
=
indexes
[
i
];
for
(
unsigned
int
i
=
0
;
i
<
count
;
i
++
)
{
KeyFinder
key
=
{.
key
=
memory_counters
[
idx
],
unsigned
int
idx
=
indexes
[
i
];
.
delimiter
=
":"
,
KeyFinder
key
=
{.
key
=
memory_counters
[
idx
],
.
copy
=
long_allocator
,
.
delimiter
=
":"
,
.
set
=
setter_functions
[
i
]};
.
copy
=
long_allocator
,
memcpy
(
&
keys
[
i
],
&
key
,
sizeof
(
KeyFinder
));
.
set
=
setter_functions
[
i
]
}
};
return
keys
;
memcpy
(
&
keys
[
i
],
&
key
,
sizeof
(
KeyFinder
));
}
return
keys
;
}
}
void
memory_list
(
char
*
memory_string
,
unsigned
int
*
count
,
void
memory_list
(
char
*
memory_string
,
unsigned
int
*
count
,
unsigned
int
*
indexes
)
{
unsigned
int
*
indexes
)
char
*
token
;
{
*
count
=
0
;
char
*
token
;
*
count
=
0
;
while
((
token
=
strtok
(
memory_string
,
","
))
!=
NULL
)
{
memory_string
=
NULL
;
while
((
token
=
strtok
(
memory_string
,
","
))
!=
NULL
)
{
memory_string
=
NULL
;
unsigned
int
i
;
for
(
i
=
0
;
i
<
NB_COUNTERS
;
i
++
)
{
unsigned
int
i
;
if
(
strcmp
(
memory_counters
[
i
],
token
)
==
0
)
{
for
(
i
=
0
;
i
<
NB_COUNTERS
;
i
++
)
{
(
*
count
)
++
;
if
(
strcmp
(
memory_counters
[
i
],
token
)
==
0
)
{
indexes
[
*
count
-
1
]
=
i
;
(
*
count
)
++
;
break
;
indexes
[
*
count
-
1
]
=
i
;
}
break
;
}
}
}
if
(
i
==
NB_COUNTERS
)
{
fprintf
(
stderr
,
"Unknown memory counter: %s
\n
"
,
token
);
if
(
i
==
NB_COUNTERS
)
{
exit
(
EXIT_FAILURE
);
fprintf
(
stderr
,
"Unknown memory counter: %s
\n
"
,
token
);
exit
(
EXIT_FAILURE
);
}
if
((
*
count
)
>
NB_COUNTERS
)
{
fprintf
(
stderr
,
"Too much counters, there are probably duplicates
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
}
if
((
*
count
)
>
NB_COUNTERS
)
{
fprintf
(
stderr
,
"Too much counters, there are probably duplicates
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
}
}
unsigned
int
init_memory_counters
(
char
*
args
,
void
**
ptr
)
{
unsigned
int
init_memory_counters
(
char
*
args
,
void
**
ptr
)
unsigned
int
indexes
[
NB_COUNTERS
];
{
unsigned
int
count
=
0
;
unsigned
int
indexes
[
NB_COUNTERS
];
memory_list
(
args
,
&
count
,
indexes
);
unsigned
int
count
=
0
;
memory_list
(
args
,
&
count
,
indexes
);
KeyFinder
*
keys
=
build_keyfinder
(
count
,
indexes
);
KeyFinder
*
keys
=
build_keyfinder
(
count
,
indexes
);
FILE
*
file
=
fopen
(
path
,
"r"
);
FILE
*
file
=
fopen
(
path
,
"r"
);
MemoryCounters
*
counters
=
calloc
(
1
,
sizeof
(
MemoryCounters
));
MemoryCounters
*
counters
=
calloc
(
1
,
sizeof
(
MemoryCounters
));
counters
->
keys
=
keys
;
counters
->
keys
=
keys
;
counters
->
count
=
count
;
counters
->
count
=
count
;
counters
->
file
=
file
;
counters
->
file
=
file
;
*
ptr
=
(
void
*
)
counters
;
*
ptr
=
(
void
*
)
counters
;
return
count
;
return
count
;
}
}
unsigned
int
get_memory_counters
(
uint64_t
*
results
,
void
*
ptr
)
{
unsigned
int
get_memory_counters
(
uint64_t
*
results
,
void
*
ptr
)
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
{
fseek
(
counters
->
file
,
0
,
SEEK_SET
);
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
Parser
parser
=
{.
storage
=
(
GenericPointer
)
results
,
fseek
(
counters
->
file
,
0
,
SEEK_SET
);
.
capacity
=
1
,
Parser
parser
=
{.
storage
=
(
GenericPointer
)
results
,
.
nb_stored
=
0
,
.
capacity
=
1
,
.
storage_struct_size
=
sizeof
(
uint64_t
)
*
counters
->
count
,
.
nb_stored
=
0
,
.
keys
=
counters
->
keys
,
.
storage_struct_size
=
sizeof
(
uint64_t
)
*
counters
->
count
,
.
nb_keys
=
counters
->
count
,
.
keys
=
counters
->
keys
,
.
file
=
counters
->
file
};
.
nb_keys
=
counters
->
count
,
.
file
=
counters
->
file
parse
(
&
parser
);
};
return
counters
->
count
;
parse
(
&
parser
);
return
counters
->
count
;
}
}
void
label_memory_counters
(
char
**
labels
,
void
*
ptr
)
{
void
label_memory_counters
(
char
**
labels
,
void
*
ptr
)
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
{
for
(
unsigned
int
i
=
0
;
i
<
counters
->
count
;
i
++
)
{
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
labels
[
i
]
=
counters
->
keys
[
i
].
key
;
for
(
unsigned
int
i
=
0
;
i
<
counters
->
count
;
i
++
)
{
}
labels
[
i
]
=
counters
->
keys
[
i
].
key
;
}
}
}
void
clean_memory_counters
(
void
*
ptr
)
{
void
clean_memory_counters
(
void
*
ptr
)
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
{
fclose
(
counters
->
file
);
MemoryCounters
*
counters
=
(
MemoryCounters
*
)
ptr
;
free
(
counters
->
keys
);
fclose
(
counters
->
file
);
free
(
ptr
);
free
(
counters
->
keys
);
free
(
ptr
);
}
}
void
*
show_all_memory_counters
(
void
*
none1
,
size_t
none2
)
{
void
*
show_all_memory_counters
(
void
*
none1
,
size_t
none2
)
for
(
unsigned
int
i
=
0
;
i
<
NB_COUNTERS
;
i
++
)
{
{
printf
(
"%s
\n
"
,
memory_counters
[
i
]);
for
(
unsigned
int
i
=
0
;
i
<
NB_COUNTERS
;
i
++
)
{
}
printf
(
"%s
\n
"
,
memory_counters
[
i
]);
}
UNUSED
(
none1
);
UNUSED
(
none1
);
UNUSED
(
none2
);
UNUSED
(
none2
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
return
NULL
;
/* not reached */
return
NULL
;
/* not reached */
}
}
Loading