[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2 13/30] xen: introduce a new format specifier to print sizes in human-readable form
On Wed, Sep 28, 2016 at 10:24:07AM +0200, Juergen Gross wrote: > On 27/09/16 17:57, Roger Pau Monne wrote: > > Introduce a new %pB format specifier to print sizes (in bytes) in a > > Code suggests it is pZ. Right, first implementation used pB, but then I realized this was already used by Linux to print something else. > > human-readable form. > > > > Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> > > --- > > Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> > > Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx> > > Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> > > Cc: Jan Beulich <jbeulich@xxxxxxxx> > > Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> > > Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx> > > Cc: Tim Deegan <tim@xxxxxxx> > > Cc: Wei Liu <wei.liu2@xxxxxxxxxx> > > --- > > docs/misc/printk-formats.txt | 5 +++++ > > xen/common/vsprintf.c | 15 +++++++++++++++ > > 2 files changed, 20 insertions(+) > > > > diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt > > index 525108f..0ee3504 100644 > > --- a/docs/misc/printk-formats.txt > > +++ b/docs/misc/printk-formats.txt > > @@ -30,3 +30,8 @@ Domain and vCPU information: > > > > %pv Domain and vCPU ID from a 'struct vcpu *' (printed as > > "d<domid>v<vcpuid>") > > + > > +Size in human readable form: > > + > > + %pZ Size in human-readable form (input size must be in bytes). > > + e.g. 24MB > > diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c > > index f92fb67..2dadaec 100644 > > --- a/xen/common/vsprintf.c > > +++ b/xen/common/vsprintf.c > > @@ -386,6 +386,21 @@ static char *pointer(char *str, char *end, const char > > **fmt_ptr, > > *str = 'v'; > > return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0); > > } > > + case 'Z': > > + { > > + static const char units[][3] = {"B", "KB", "MB", "GB", "TB"}; > > + size_t size = (size_t)arg; > > + int i = 0; > > + > > + /* Advance parents fmt string, as we have consumed 'B' */ > > + ++*fmt_ptr; > > + > > + while ( ++i < sizeof(units) && size >= 1024 ) > > sizeof(units) is 15. That's not what you want to check here. Indeed, it's ARRAY_SIZE, thanks for noticing! Roger. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |