Keep a count of bytes moved due to the realloc() call. Signed-off-by: Andy Zhou <az...@nicira.com> --- lib/dynamic-string.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index a6c8f6c..89ead08 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -15,6 +15,7 @@ */ #include <config.h> +#include "coverage.h" #include "dynamic-string.h" #include <inttypes.h> #include <stdlib.h> @@ -23,6 +24,8 @@ #include "timeval.h" #include "util.h" +COVERAGE_DEFINE(ds_bytes_relocated); + /* Initializes 'ds' as an empty string buffer. */ void ds_init(struct ds *ds) @@ -58,9 +61,15 @@ void ds_reserve(struct ds *ds, size_t min_length) { if (min_length > ds->allocated || !ds->string) { + char *string_ = ds->string; + size_t size_ = ds->allocated; + ds->allocated += MAX(min_length, ds->allocated); ds->allocated = MAX(8, ds->allocated); ds->string = xrealloc(ds->string, ds->allocated + 1); + if (string_ && (string_ != ds->string)) { + COVERAGE_ADD(ds_bytes_relocated, size_); + } } } -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev