]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add JSON support for smbstatus --profile
authorJule Anger <janger@samba.org>
Fri, 25 Mar 2022 13:16:27 +0000 (14:16 +0100)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status.c
source3/utils/status_profile.c
source3/utils/status_profile.h
source3/utils/status_profile_dummy.c

index 72cc2c08a11f1f233a3000e483cb6926e1c742c6..e311f067c9c57514eb564b494b7ce45618f23e75 100644 (file)
@@ -1101,13 +1101,18 @@ int main(int argc, const char *argv[])
        switch (profile_only) {
                case 'P':
                        /* Dump profile data */
-                       ok = status_profile_dump(verbose);
+                       ok = status_profile_dump(verbose, &state);
                        ret = ok ? 0 : 1;
                        goto done;
                case 'R':
                        /* Continuously display rate-converted data */
-                       ok = status_profile_rates(verbose);
-                       ret = ok ? 0 : 1;
+                       if (!state.json_output) {
+                               ok = status_profile_rates(verbose);
+                               ret = ok ? 0 : 1;
+                       } else {
+                               fprintf(stderr, "Call rates not available in a json output.\n");
+                               ret = 1;
+                       }
                        goto done;
                default:
                        break;
@@ -1200,7 +1205,7 @@ done:
        cmdline_messaging_context_free();
        poptFreeContext(pc);
 #ifdef HAVE_JANSSON
-       if (state.json_output && !profile_only) {
+       if (state.json_output) {
                d_printf("%s\n", json_to_string(frame, &state.root_json));
        }
        json_free(&state.root_json);
index b3428a8c61892923e918bdfe9493677b6e078de3..6e0916ed7e8cc6db53b4a61fa3a29d5132aa132d 100644 (file)
 #include "includes.h"
 #include "smbprofile.h"
 #include "status_profile.h"
+#include "conn_tdb.h"
+#include "librpc/gen_ndr/open_files.h"
+#include "status_json.h"
 
-static void profile_separator(const char * title)
+static void profile_separator(const char * title,
+                             struct traverse_state *state)
 {
        char line[79 + 1];
        char * end;
 
+       if (state->json_output) {
+               return;
+       }
+
        snprintf(line, sizeof(line), "**** %s ", title);
 
        for (end = line + strlen(line); end < &line[sizeof(line) -1]; ++end) {
@@ -40,9 +48,11 @@ static void profile_separator(const char * title)
 /*******************************************************************
  dump the elements of the profile structure
   ******************************************************************/
-bool status_profile_dump(bool verbose)
+bool status_profile_dump(bool verbose,
+                        struct traverse_state *state)
 {
        struct profile_stats stats = {};
+       const char* latest_section = NULL;
 
        if (!profile_setup(NULL, True)) {
                fprintf(stderr,"Failed to initialise profile memory\n");
@@ -52,12 +62,20 @@ bool status_profile_dump(bool verbose)
        smbprofile_collect(&stats);
 
 #define __PRINT_FIELD_LINE(name, _stats, field) do { \
-       d_printf("%-59s%20ju\n", \
-                name "_" #field ":", \
-                (uintmax_t)stats.values._stats.field); \
+       uintmax_t val = (uintmax_t)stats.values._stats.field; \
+       if (!state->json_output) { \
+               d_printf("%-59s%20ju\n", \
+                        name "_" #field ":", \
+                        val); \
+       } else { \
+              add_profile_item_to_json(state, latest_section, name, #field, val); \
+       } \
 } while(0);
 #define SMBPROFILE_STATS_START
-#define SMBPROFILE_STATS_SECTION_START(name, display) profile_separator(#display);
+#define SMBPROFILE_STATS_SECTION_START(name, display) do { \
+       latest_section = display; \
+       profile_separator(display, state);\
+} while(0);
 #define SMBPROFILE_STATS_COUNT(name) do { \
        __PRINT_FIELD_LINE(#name, name##_stats,  count); \
 } while(0);
index a8a73e12178a2a796a28bd647af7df1eafbb336a..eed54e033609e72e309f453c64c5bd831524e14b 100644 (file)
 #define __STATUS_PROFILE_H__
 
 #include "replace.h"
+#include "status.h"
 
-bool status_profile_dump(bool be_verbose);
+bool status_profile_dump(bool be_verbose,
+                        struct traverse_state *state);
 bool status_profile_rates(bool be_verbose);
 
 #endif
index dfc5da7756a8ae353930396641d5ec4faed3acf5..9083abf2111c859c327234ada5b57166c629382f 100644 (file)
@@ -21,7 +21,8 @@
 #include "smbprofile.h"
 #include "status_profile.h"
 
-bool status_profile_dump(bool be_verbose)
+bool status_profile_dump(bool be_verbose,
+                        struct traverse_state *state)
 {
        fprintf(stderr, "Profile data unavailable\n");
        return true;