diff options
| author | Russ White <russ@riw.us> | 2023-02-02 15:44:45 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-02 15:44:45 -0500 | 
| commit | 73fb874e0aaff37b417e7a1d167e251d98a6daa1 (patch) | |
| tree | d7d666e92cbd256615ac25ce12e19656b07f1450 | |
| parent | 7d1cbd75e147e3958dc197e7e40b7b50ce597276 (diff) | |
| parent | 2d4460de6f363533c77eae55bb590a19376b26fd (diff) | |
Merge pull request #12731 from donaldsharp/remove_pretty_print
lib, bgpd: Add ability to specify that some json output should not be…
| -rw-r--r-- | bgpd/bgp_evpn_vty.c | 15 | ||||
| -rw-r--r-- | bgpd/bgp_route.c | 11 | ||||
| -rw-r--r-- | lib/vty.c | 15 | ||||
| -rw-r--r-- | lib/vty.h | 4 | 
4 files changed, 35 insertions, 10 deletions
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 3c7fb4cb17..0b5f81ccb0 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -4807,14 +4807,13 @@ DEFUN(show_bgp_l2vpn_evpn_route,  	evpn_show_all_routes(vty, bgp, type, json, detail); -	if (uj) { -		if (detail) { -			vty_out(vty, "%s\n", json_object_to_json_string(json)); -			json_object_free(json); -		} else { -			vty_json(vty, json); -		} -	} +	/* +	 * This is an extremely expensive operation at scale +	 * and as such we need to save as much time as is +	 * possible. +	 */ +	if (uj) +		vty_json_no_pretty(vty, json);  	return CMD_SUCCESS;  } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index aba8260e2b..4c98ffcf09 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11588,7 +11588,16 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,  				else  					vty_out(vty, ",\"%pFX\": ", dest_p);  			} -			vty_json(vty, json_paths); +			/* +			 * We are using no_pretty here because under +			 * extremely high settings( say lots and lots of +			 * routes with lots and lots of ways to reach +			 * that route via different paths ) this can +			 * save several minutes of output when FRR +			 * is run on older cpu's or more underperforming +			 * routers out there +			 */ +			vty_json_no_pretty(vty, json_paths);  			json_paths = NULL;  			first = 0;  		} else @@ -284,7 +284,8 @@ done:  	return len;  } -int vty_json(struct vty *vty, struct json_object *json) +static int vty_json_helper(struct vty *vty, struct json_object *json, +			   uint32_t options)  {  	const char *text; @@ -299,6 +300,18 @@ int vty_json(struct vty *vty, struct json_object *json)  	return CMD_SUCCESS;  } +int vty_json(struct vty *vty, struct json_object *json) +{ +	return vty_json_helper(vty, json, +			       JSON_C_TO_STRING_PRETTY | +				       JSON_C_TO_STRING_NOSLASHESCAPE); +} + +int vty_json_no_pretty(struct vty *vty, struct json_object *json) +{ +	return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE); +} +  /* Output current time to the vty. */  void vty_time_print(struct vty *vty, int cr)  { @@ -353,8 +353,12 @@ extern void vty_endframe(struct vty *, const char *);  extern bool vty_set_include(struct vty *vty, const char *regexp);  /* returns CMD_SUCCESS so you can do a one-line "return vty_json(...)"   * NULL check and json_object_free() is included. + * + * _no_pretty means do not add a bunch of newlines and dump the output + * as densely as possible.   */  extern int vty_json(struct vty *vty, struct json_object *json); +extern int vty_json_no_pretty(struct vty *vty, struct json_object *json);  /* post fd to be passed to the vtysh client   * fd is owned by the VTY code after this and will be closed when done  | 
