]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
profile: Return number of workers from smbprofile_collect_tdb()
authorVolker Lendecke <vl@samba.org>
Wed, 22 Nov 2023 14:11:09 +0000 (15:11 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 11 Apr 2025 18:46:40 +0000 (18:46 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/include/smbprofile.h
source3/profile/profile.c
source3/profile/profile_read.c

index 4779a33c22a161fe4a5ee0c85c7f8c723cd69964..c11b136535a4a4183ded2fd04769ba14bdc5e272 100644 (file)
@@ -305,6 +305,7 @@ struct smbprofile_stats_iobytes_async {
 
 struct profile_stats {
        uint64_t magic;
+       bool summary_record;
        struct {
 #define SMBPROFILE_STATS_START
 #define SMBPROFILE_STATS_SECTION_START(name, display)
@@ -563,9 +564,9 @@ void smbprofile_cleanup(pid_t pid, pid_t dst);
 void smbprofile_stats_accumulate(struct profile_stats *acc,
                                 const struct profile_stats *add);
 int smbprofile_magic(const struct profile_stats *stats, uint64_t *_magic);
-void smbprofile_collect_tdb(struct tdb_context *tdb,
-                           uint64_t magic,
-                           struct profile_stats *stats);
+size_t smbprofile_collect_tdb(struct tdb_context *tdb,
+                             uint64_t magic,
+                             struct profile_stats *stats);
 void smbprofile_collect(struct profile_stats *stats);
 
 static inline uint64_t profile_timestamp(void)
index 0b02e36fcd01e72ad8b6629e1e76e0b6d6c8acb7..7e139cd06487b59929092879e250e350ab1673c0 100644 (file)
@@ -311,6 +311,8 @@ void smbprofile_cleanup(pid_t pid, pid_t dst)
        smbprofile_stats_accumulate(&acc, &s);
 
        acc.magic = profile_p->magic;
+       acc.summary_record = true;
+
        tdb_store(smbprofile_state.internal.db->tdb, key,
                  (TDB_DATA) {
                        .dptr = (uint8_t *)&acc,
index 7281ff2e52da8204df49ef86e8a6b52256361327..3c4e6ebcfa3541cda22e1167ab6d1667534ad271 100644 (file)
@@ -190,12 +190,18 @@ out:
        return rc;
 }
 
+struct smbprofile_collect_state {
+       size_t num_workers;
+       struct profile_stats *acc;
+};
+
 static int smbprofile_collect_fn(struct tdb_context *tdb,
                                 TDB_DATA key,
                                 TDB_DATA value,
                                 void *private_data)
 {
-       struct profile_stats *acc = (struct profile_stats *)private_data;
+       struct smbprofile_collect_state *state = private_data;
+       struct profile_stats *acc = state->acc;
        const struct profile_stats *v;
 
        if (value.dsize != sizeof(struct profile_stats)) {
@@ -208,15 +214,29 @@ static int smbprofile_collect_fn(struct tdb_context *tdb,
                return 0;
        }
 
+       if (!v->summary_record) {
+               state->num_workers += 1;
+       }
+
        smbprofile_stats_accumulate(acc, v);
        return 0;
 }
 
-void smbprofile_collect_tdb(struct tdb_context *tdb,
-                           uint64_t magic,
-                           struct profile_stats *stats)
+/*
+ * return the number of tdb records, i.e. active smbds. Includes the
+ * parent, so if you want the number of worker smbd, subtract one.
+ */
+size_t smbprofile_collect_tdb(struct tdb_context *tdb,
+                             uint64_t magic,
+                             struct profile_stats *stats)
 {
+       struct smbprofile_collect_state state = {
+               .acc = stats,
+       };
+
        *stats = (struct profile_stats){.magic = magic};
 
-       tdb_traverse_read(tdb, smbprofile_collect_fn, stats);
+       tdb_traverse_read(tdb, smbprofile_collect_fn, &state);
+
+       return state.num_workers;
 }