Re: [PATCH] scripts/ksize: Add kernel build size report

2014-11-08 Thread Darren Hart


On 11/8/14 19:26, Josh Triplett wrote:
> On Sat, Nov 08, 2014 at 03:18:18PM -0800, Darren Hart wrote:
>> ksize generates hierarchical build size reports from vmlinux, *.o, and
>> built-in.o files.
>>
>> ksize is useful in preparing minimal configurations and comparing
>> similar configurations across kernel versions.
>>
>> Signed-off-by: Darren Hart 
>> Cc: Josh Triplett 
> 
> One comment below; with that addressed:
> Reviewed-by: Josh Triplett 
> 
>> +def main(argv):
>> +try:
>> +opts, args = getopt.getopt(argv[1:], "dh", ["help"])
>> +except getopt.GetoptError, err:
>> +print '%s' % str(err)
>> +usage()
>> +return 2
>> +
>> +driver_detail = False
>> +for o, a in opts:
>> +if o == '-d':
>> +driver_detail = True
>> +elif o in ('-h', '--help'):
>> +usage()
>> +return 0
>> +else:
>> +assert False, "unhandled option"
>> +
>> +cols = term_width()
>> +
>> +# Determine kernel version
>> +p = Popen("strings vmlinux | grep 'Linux version' | cut -d ' ' -f 3",
>> +  shell=True, stdout=PIPE, stderr=PIPE)
>> +version = p.communicate()[0].strip()
> 
> This seems like a very fragile, Perl-y way to obtain the kernel version.
> 
> I'd suggest either not including the version (just as bloat-o-meter
> doesn't), or parsing it out using objdump -h -t and file offsetting
> (looking for the offset and size of linux_banner).  Personally I'd go
> with the former.

I agree it's a hack, but it isn't a performance sensitive area and I
couldn't see spending the time to calculate offsets and such to save a
couple seconds for something like this. There are more advanced
approaches to extracting bits of information from vmlinux, such as
scripts/extract-ikconfig. I suppose something along those lines could be
created.

As to fragile, I have not tested every version, but this technique has
been used at least as far back as 2.6.24 [1], which seem fairly stable
to me.

Personally, I think it's nice to have. But, if nobody chimes in asking
to keep it, or with a better way to retrieve it, I can resend with it
removed.

Thanks Josh :-)

1.
http://plastilinux.blogspot.com/2009/11/how-to-know-version-of-kernel-without.html
(A slightly faster hack)

-- 
Darren Hart
Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] scripts/ksize: Add kernel build size report

2014-11-08 Thread Josh Triplett
On Sat, Nov 08, 2014 at 03:18:18PM -0800, Darren Hart wrote:
> ksize generates hierarchical build size reports from vmlinux, *.o, and
> built-in.o files.
> 
> ksize is useful in preparing minimal configurations and comparing
> similar configurations across kernel versions.
> 
> Signed-off-by: Darren Hart 
> Cc: Josh Triplett 

One comment below; with that addressed:
Reviewed-by: Josh Triplett 

> +def main(argv):
> +try:
> +opts, args = getopt.getopt(argv[1:], "dh", ["help"])
> +except getopt.GetoptError, err:
> +print '%s' % str(err)
> +usage()
> +return 2
> +
> +driver_detail = False
> +for o, a in opts:
> +if o == '-d':
> +driver_detail = True
> +elif o in ('-h', '--help'):
> +usage()
> +return 0
> +else:
> +assert False, "unhandled option"
> +
> +cols = term_width()
> +
> +# Determine kernel version
> +p = Popen("strings vmlinux | grep 'Linux version' | cut -d ' ' -f 3",
> +  shell=True, stdout=PIPE, stderr=PIPE)
> +version = p.communicate()[0].strip()

This seems like a very fragile, Perl-y way to obtain the kernel version.

I'd suggest either not including the version (just as bloat-o-meter
doesn't), or parsing it out using objdump -h -t and file offsetting
(looking for the offset and size of linux_banner).  Personally I'd go
with the former.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] scripts/ksize: Add kernel build size report

2014-11-08 Thread Darren Hart
ksize generates hierarchical build size reports from vmlinux, *.o, and
built-in.o files.

ksize is useful in preparing minimal configurations and comparing
similar configurations across kernel versions.

Signed-off-by: Darren Hart 
Cc: Josh Triplett 
---
 scripts/ksize | 345 ++
 1 file changed, 345 insertions(+)
 create mode 100755 scripts/ksize

diff --git a/scripts/ksize b/scripts/ksize
new file mode 100755
index 000..103da2a
--- /dev/null
+++ b/scripts/ksize
@@ -0,0 +1,345 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2011-2014 Intel Corporation.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# Author: Darren Hart 
+#
+
+"""
+Display details of the kernel build size.
+
+The generated report is comprised of many sub-reports, starting with vmlinux,
+and descending into each component built-in.o.
+
+The first line of each report block is the table header, including the report
+title and the column labels. Next is the report totals for the top level file
+(vmlinux or built-in.o). This is followed by itemized sizes for any component
+*.o object files and all built-in.o files from one directory down (the
+built-in.o components are labeled with their parent directory to avoid
+displaying "built-in.o" on nearly every line). The final lines display the sum
+of all the itemized components and delta between the total and the sum.
+
+An example report from an x86_64 allnoconfig build follows in part:
+
+Linux (3.18.0-rc3+) total |   text   data
bss
+
+vmlinux   2201904 | 864548 121612
1215744
+
+arch/x86   282709 | 171021  65448  
46240
+kernel 249960 | 234355   7201   
8404
+mm 190369 | 154171  14154  
22044
+fs 163867 | 160820   1351   
1696
+drivers 44429 |  41353   2052   
1024
+lib 37143 |  37053 85  
5
+init21535 |   5189  16285 
61
+security 3674 |   3658  8  
8
+net   122 |122  0  0
+
+sum993808 | 807742 106584  
79482
+delta 1208096 |  56806  15028
1136262
+
+...
+
+drivers total |   text   data
bss
+
+drivers/built-in.o  44429 |  41353   2052   
1024
+
+drivers/base32427 |  31267   1060
100
+drivers/char 9980 |   8412656
912
+drivers/rtc  1155 |   1155  0  0
+drivers/clocksource   674 |406256 
12
+drivers/video  62 | 46 16  0
+
+sum 44298 |  41286   1988   
1024
+delta 131 | 67 64  0
+
+The report may optionally display an additional level of drivers/* reports:
+
+drivers/basetotal |   text   data
bss
+

+drivers/base/built-in.o 32427 |  31267   1060
100
+

+drivers/base/*.o32253 |  31121   1032
100
+

+sum 32253 |  31121   1032
100
+delta 174 |146 28  0
+
+...
+"""
+
+import sys
+impo