profile: Fix rusage reporting
authorVolker Lendecke <vl@samba.org>
Fri, 24 Nov 2023 15:27:42 +0000 (16:27 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 19 Dec 2023 16:05:36 +0000 (16:05 +0000)
getrusage already gives accumulated values, so add them to the tdb
record after smbprofile_stats_accumulate. Maybe we should not zero out
our internal copy after writing the tdb, this would save a call to
smbprofile_stats_accumulate() once a second.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/profile/profile.c

index cf35db7877394bd4a5bf33880bd0cb9eeed8a273..0b02e36fcd01e72ad8b6629e1e76e0b6d6c8acb7 100644 (file)
@@ -233,6 +233,16 @@ void smbprofile_dump(void)
 
        pid = tevent_cached_getpid();
 
+       ret = tdb_chainlock(smbprofile_state.internal.db->tdb, key);
+       if (ret != 0) {
+               return;
+       }
+
+       tdb_parse_record(smbprofile_state.internal.db->tdb,
+                        key, profile_stats_parser, &s);
+
+       smbprofile_stats_accumulate(profile_p, &s);
+
 #ifdef HAVE_GETRUSAGE
        ret = getrusage(RUSAGE_SELF, &rself);
        if (ret != 0) {
@@ -247,16 +257,6 @@ void smbprofile_dump(void)
                rself.ru_stime.tv_usec;
 #endif /* HAVE_GETRUSAGE */
 
-       ret = tdb_chainlock(smbprofile_state.internal.db->tdb, key);
-       if (ret != 0) {
-               return;
-       }
-
-       tdb_parse_record(smbprofile_state.internal.db->tdb,
-                        key, profile_stats_parser, &s);
-
-       smbprofile_stats_accumulate(profile_p, &s);
-
        tdb_store(smbprofile_state.internal.db->tdb, key,
                  (TDB_DATA) {
                        .dptr = (uint8_t *)profile_p,