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;
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);
#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) {
/*******************************************************************
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");
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);