]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, bgpd: Add ability to specify that some json output should not be pretty
authorDonald Sharp <sharpd@nvidia.com>
Thu, 2 Feb 2023 15:28:19 +0000 (10:28 -0500)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 6 Feb 2023 10:48:10 +0000 (12:48 +0200)
Initial commit: 23b2a7ef524c9fe083b217c7f6ebaec0effc8f52
changed the json output of `show bgp <afi> <safi> json` to
not have pretty print because when under a situation where
there are a bunch of routes with a large scale ecmp show
output was taking forever and this commit cut 2 minutes out
of vtysh run time.

Subusequent commit: f4ec52f7cc99f709756d9030623a20c98a086125
changed this back.

When upgrading to latest version the long run time was noticed
due to testing.  Let's add back this functionality such that
FRR can have reduced run times with vtysh when it's really
needed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_route.c
lib/vty.c
lib/vty.h

index 29e2768d173ead4d5caa71aa21e5ca2186d8dcdf..82d623a21c5561d3f14196597bb1c48f05dcc9cd 100644 (file)
@@ -11416,7 +11416,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
index 5fe8a7955bbe398fd7339f7537a5a853bc8c5105..9d8966064aab61b8ae2d88d13fdd8d1f046ae871 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -281,7 +281,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;
 
@@ -296,6 +297,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)
 {
index 430579c5a8776caf5b541138425d9029dd2e0750..0031ab6331f8e2d8e23e9b9ee34e1767b22149fc 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -348,8 +348,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