diff options
author | Andrew Clayton <andrew@zeta.digital-domain.net> | 2019-09-17 12:42:55 +0100 |
---|---|---|
committer | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2019-09-17 13:42:55 +0200 |
commit | d6ba820be6149e6e37dea6843d08d5364b46e874 (patch) | |
tree | c4ed605cdb3af53a8fa5a34d42ea7581ad84d5b3 /tests/profile | |
parent | 569a11f08f600f2d11653162515a3b0725e451cb (diff) |
Cppcheck fixes (#6386)
* collector: cgroups: Fix a cppcheck warning
Cppcheck was throwing the following warning in
collectors/cgroups.plugin/cgroup-network.c
[collectors/cgroups.plugin/cgroup-network.c:233]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
One of the arguments to switch_namespace() is 'const char *prefix', in
this function we were checking if prefix was NULL and if so setting it
(local scope wise) to "".
While this wasn't technically incorrect in this context. It is also
unnecessary as the prefix variable is only passed to the proc_pid_fd()
function where the same check happens, so we can simply remove the
offending line.
Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net>
* tests/profile: Remove somewhat redundant code
cppcheck was throwing a warning in benchmark-line-parsing.c
[tests/profile/benchmark-line-parsing.c:648]: (warning) Unnecessary
comparison of static strings, this comes from
(void)strcmp("1", "2");
in main()
That is amongst a group of three function calls preceded by the comment
// cache functions
But then test1() which uses strcmp() is called twice anyway with the
timing result of just the second one used, so the dummy strcmp() call
would seem superfluous.
I would say the same is true for the call to strtoull()
(void)strtoull("123", NULL, 0);
as that is also used in test1().
I actually ran this benchmark with and without the calls to all three
functions, i.e
// cache functions
(void)simple_hash2("hello world");
(void)strcmp("1", "2");
(void)strtoull("123", NULL, 0);
With the above functions being called
test1() average time = 7801604
test2() average time = 1333162
Without those three function calls
test1() average time = 7779905
test2() average time = 1321438
Those are the averages of three runs. test1() uses strcmp() & strtoull()
and test2() uses simple_hash2(), so in that run, not calling the three
functions initially was actually quicker.
Subsequent runs of each show similar numbers with each edging the other
out, however the difference is in the noise.
Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net>
Diffstat (limited to 'tests/profile')
-rw-r--r-- | tests/profile/benchmark-line-parsing.c | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/tests/profile/benchmark-line-parsing.c b/tests/profile/benchmark-line-parsing.c index c07d1d857b..1d47cc83a5 100644 --- a/tests/profile/benchmark-line-parsing.c +++ b/tests/profile/benchmark-line-parsing.c @@ -643,11 +643,6 @@ void main(void) total_active_file_hash = simple_hash("total_active_file"); total_unevictable_hash = simple_hash("total_unevictable"); - // cache functions - (void)simple_hash2("hello world"); - (void)strcmp("1", "2"); - (void)strtoull("123", NULL, 0); - unsigned long i, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7; unsigned long max = 1000000; |