diff --git a/src/bloaty.cc b/src/bloaty.cc index ec94647d..600dc327 100644 --- a/src/bloaty.cc +++ b/src/bloaty.cc @@ -280,7 +280,10 @@ class Rollup { CreateRows(row, base, options, true); } - void SetFilterRegex(const ReImpl* regex) { filter_regex_ = regex; } + void SetFilterRegex(const ReImpl* regex_include, const ReImpl* regex_exclude) { + filter_regex_include_ = regex_include; + filter_regex_exclude_ = regex_exclude; + } // Add the values in "other" from this. void Add(const Rollup& other) { @@ -316,7 +319,8 @@ class Rollup { int64_t filtered_vm_total_ = 0; int64_t filtered_file_total_ = 0; - const ReImpl* filter_regex_ = nullptr; + const ReImpl* filter_regex_include_ = nullptr; + const ReImpl* filter_regex_exclude_ = nullptr; // Putting Rollup by value seems to work on some compilers/libs but not // others. @@ -335,20 +339,33 @@ class Rollup { // If there are more entries names[i+1, i+2, etc] add them to sub-rollups. void AddInternal(const std::vector& names, size_t i, uint64_t size, bool is_vmsize) { - if (filter_regex_ != nullptr) { + if (filter_regex_include_ != nullptr || filter_regex_exclude_ != nullptr) { // filter_regex_ is only set in the root rollup, which checks the full // label hierarchy for a match to determine whether a region should be // considered. - bool any_matched = false; + bool exclude = false; + if (filter_regex_include_ != nullptr) { + bool any_matched = false; + + for (const auto& name : names) { + if (ReImpl::PartialMatch(name, *filter_regex_include_)) { + any_matched = true; + break; + } + } + exclude = !any_matched; + } - for (const auto& name : names) { - if (ReImpl::PartialMatch(name, *filter_regex_)) { - any_matched = true; - break; + if (!exclude && filter_regex_exclude_ != nullptr) { + for (const auto& name : names) { + if (ReImpl::PartialMatch(name, *filter_regex_exclude_)) { + exclude = true; + break; + } } } - if (!any_matched) { + if (exclude) { // Ignore this region in the rollup and don't visit sub-rollups. if (is_vmsize) { CheckedAdd(&filtered_vm_total_, size); @@ -1810,13 +1827,17 @@ void Bloaty::ScanAndRollupFiles(const std::vector& filenames, std::vector threads(num_threads); ThreadSafeIterIndex index(filenames.size()); - std::unique_ptr regex = nullptr; + std::unique_ptr regex_include = nullptr; + std::unique_ptr regex_exclude = nullptr; if (options_.has_source_filter()) { - regex = absl::make_unique(options_.source_filter()); + regex_include = absl::make_unique(options_.source_filter()); + } + if (options_.has_exclude_source_filter()) { + regex_exclude = absl::make_unique(options_.exclude_source_filter()); } for (int i = 0; i < num_threads; i++) { - thread_data[i].rollup.SetFilterRegex(regex.get()); + thread_data[i].rollup.SetFilterRegex(regex_include.get(), regex_exclude.get()); threads[i] = std::thread( [this, &index, &filenames](PerThreadData* data) { @@ -1960,6 +1981,10 @@ USAGE: bloaty [OPTION]... FILE... [-- BASE_FILE...] --list-sources Show a list of available sources and exit. --source-filter=PATTERN Only show keys with names matching this pattern. + --exclude-source-filter=PATTERN + Exclude keys with names matching this pattern. + When both --source-filter and --exclude-source-filter + match the same data, the data will be excluded. Options for debugging Bloaty: @@ -2159,6 +2184,8 @@ bool DoParseOptions(bool skip_unknown, int* argc, char** argv[], } } else if (args.TryParseOption("--source-filter", &option)) { options->set_source_filter(std::string(option)); + } else if (args.TryParseOption("--exclude-source-filter", &option)) { + options->set_exclude_source_filter(std::string(option)); } else if (args.TryParseFlag("-v")) { options->set_verbose_level(1); } else if (args.TryParseFlag("-vv")) { @@ -2264,7 +2291,14 @@ void BloatyDoMain(const Options& options, const InputFileFactory& file_factory, if (options.has_source_filter()) { ReImpl re(options.source_filter()); if (!re.ok()) { - THROW("invalid regex for source_filter"); + THROW("invalid regex for --source-filter"); + } + } + + if (options.has_exclude_source_filter()) { + ReImpl re(options.exclude_source_filter()); + if (!re.ok()) { + THROW("invalid regex for --exclude-source-filter"); } } diff --git a/src/bloaty.proto b/src/bloaty.proto index 16793288..f4883794 100644 --- a/src/bloaty.proto +++ b/src/bloaty.proto @@ -75,6 +75,9 @@ message Options { // Dump raw memory map instead of printing normal output. optional bool dump_raw_map = 14; + + // Regex with which to exclude names in the data sources. + optional string exclude_source_filter = 15; } // A custom data source allows users to create their own label space by diff --git a/tests/PE/filter/exclude-source-filter-text-pe32.test b/tests/PE/filter/exclude-source-filter-text-pe32.test new file mode 100644 index 00000000..303ab90f --- /dev/null +++ b/tests/PE/filter/exclude-source-filter-text-pe32.test @@ -0,0 +1,97 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --exclude-source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4160 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8304 + Size: 366 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 0 + Size: 0 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 12288 + Size: 16 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 8 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 160 + SectionData: 5589E581EC0000000090B80020001050E88300000083C404C9C35589E581EC0000000090B80920001050E86900000083C404B800000000E900000000C9C210005589E581EC04000000908B4510508B450C508B450850E8250000008945FC8B45FCE900000000C9C20C00000000000000000000000000000000000000000000005589E581EC0000000090B801000000E900000000C9C20C00FF25482000100000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E00000000000000000000000050200000000000000000000058200000482000000000000000000000000000000000000000000000632000000000000063200000000000006D73766372742E646C6C00000070757473000000000000000000000000000000000000001A210000010000000D0000000D00000098200000CC20000000210000801000001A1000004010000000300000003000000030000000300000003000000030000020200000E0210000981000000010000027210000332100003F2100004D2100005E210000712100008221000095210000A9210000BF210000C6210000CB210000D221000000000100020003000400050006000700080009000A000B000C00706533325F7374642E646C6C005F446C6C4D61696E403132005F446C6C4D61696E403136005F5F646C6C7374617274403132005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F7468657265000000 + - Name: .reloc + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 16 + SectionData: 00100000100000000B3025309A300000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 33.3% 512 48.4% 480 .data +# CHECK: 33.3% 512 1.6% 16 .reloc +# CHECK: 24.5% 376 37.9% 376 [PE Headers] +# CHECK: 7.8% 120 12.1% 120 [PE Section Headers] +# CHECK: 1.0% 16 0.0% 0 [Unmapped] +# CHECK: 100.0% 1.50Ki 100.0% 992 TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 512, vm = 160 of entries diff --git a/tests/PE/filter/exclude-source-filter-text-pe64.test b/tests/PE/filter/exclude-source-filter-text-pe64.test new file mode 100644 index 00000000..e540e02b --- /dev/null +++ b/tests/PE/filter/exclude-source-filter-text-pe64.test @@ -0,0 +1,97 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --exclude-source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4192 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8320 + Size: 336 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 12288 + Size: 36 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 0 + Size: 0 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 16 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 168 + SectionData: 554889E54881EC20000000488D0DEE0F0000E889000000C9C30000000104020504030150554889E54881EC2000000048894D10488955184C8945204C894D28488D0DC30F0000E855000000B800000000E900000000C9C3000000000000000000554889E54881EC3000000048894D10488955184C894520488B45204989C08B5518488B4D10E89AFFFFFF8945FC8B45FCE900000000C9C3000104020504030150FF25A20F00000000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E0000000000000000000000005820000000000000000000006820000048200000000000000000000000000000000000000000000073200000000000000000000000000000732000000000000000000000000000006D73766372742E646C6C000000707574730000000000000000000000000000000000000020210000010000000C0000000C000000A8200000D820000008210000241000000040000000400000004000000040000000400000004000006010000020200000E0210000A0100000001000002D2100003521000046210000592100006A2100007D21000091210000A7210000B1210000B8210000BD210000C421000000000100020003000400050006000700080009000A000B00706536345F7374642E646C6C00446C6C4D61696E005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F646C6C7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F74686572650000000000000000000000000000000000 + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 36 + SectionData: 0B100000191000001C1000002F100000571000001C1000006B1000009710000098100000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 33.3% 512 46.7% 480 .data +# CHECK: 33.3% 512 3.5% 36 .pdata +# CHECK: 25.5% 392 38.1% 392 [PE Headers] +# CHECK: 7.8% 120 11.7% 120 [PE Section Headers] +# CHECK: 100.0% 1.50Ki 100.0% 1.00Ki TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 512, vm = 168 of entries + diff --git a/tests/PE/filter/inex-source-filter-text-pe32.test b/tests/PE/filter/inex-source-filter-text-pe32.test new file mode 100644 index 00000000..00b4fec2 --- /dev/null +++ b/tests/PE/filter/inex-source-filter-text-pe32.test @@ -0,0 +1,94 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --source-filter text --exclude-source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4160 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8304 + Size: 366 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 0 + Size: 0 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 12288 + Size: 16 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 8 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 160 + SectionData: 5589E581EC0000000090B80020001050E88300000083C404C9C35589E581EC0000000090B80920001050E86900000083C404B800000000E900000000C9C210005589E581EC04000000908B4510508B450C508B450850E8250000008945FC8B45FCE900000000C9C20C00000000000000000000000000000000000000000000005589E581EC0000000090B801000000E900000000C9C20C00FF25482000100000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E00000000000000000000000050200000000000000000000058200000482000000000000000000000000000000000000000000000632000000000000063200000000000006D73766372742E646C6C00000070757473000000000000000000000000000000000000001A210000010000000D0000000D00000098200000CC20000000210000801000001A1000004010000000300000003000000030000000300000003000000030000020200000E0210000981000000010000027210000332100003F2100004D2100005E210000712100008221000095210000A9210000BF210000C6210000CB210000D221000000000100020003000400050006000700080009000A000B000C00706533325F7374642E646C6C005F446C6C4D61696E403132005F446C6C4D61696E403136005F5F646C6C7374617274403132005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F7468657265000000 + - Name: .reloc + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 16 + SectionData: 00100000100000000B3025309A300000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 100.0% 0 100.0% 0 TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 2.00Ki, vm = 1.12Ki of entries + + diff --git a/tests/PE/filter/inex-source-filter-text-pe64.test b/tests/PE/filter/inex-source-filter-text-pe64.test new file mode 100644 index 00000000..936e4da1 --- /dev/null +++ b/tests/PE/filter/inex-source-filter-text-pe64.test @@ -0,0 +1,94 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --source-filter text --exclude-source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4192 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8320 + Size: 336 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 12288 + Size: 36 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 0 + Size: 0 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 16 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 168 + SectionData: 554889E54881EC20000000488D0DEE0F0000E889000000C9C30000000104020504030150554889E54881EC2000000048894D10488955184C8945204C894D28488D0DC30F0000E855000000B800000000E900000000C9C3000000000000000000554889E54881EC3000000048894D10488955184C894520488B45204989C08B5518488B4D10E89AFFFFFF8945FC8B45FCE900000000C9C3000104020504030150FF25A20F00000000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E0000000000000000000000005820000000000000000000006820000048200000000000000000000000000000000000000000000073200000000000000000000000000000732000000000000000000000000000006D73766372742E646C6C000000707574730000000000000000000000000000000000000020210000010000000C0000000C000000A8200000D820000008210000241000000040000000400000004000000040000000400000004000006010000020200000E0210000A0100000001000002D2100003521000046210000592100006A2100007D21000091210000A7210000B1210000B8210000BD210000C421000000000100020003000400050006000700080009000A000B00706536345F7374642E646C6C00446C6C4D61696E005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F646C6C7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F74686572650000000000000000000000000000000000 + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 36 + SectionData: 0B100000191000001C1000002F100000571000001C1000006B1000009710000098100000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 100.0% 0 100.0% 0 TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 2.00Ki, vm = 1.17Ki of entries + + diff --git a/tests/PE/filter/source-filter-text-pe32.test b/tests/PE/filter/source-filter-text-pe32.test new file mode 100644 index 00000000..f786964d --- /dev/null +++ b/tests/PE/filter/source-filter-text-pe32.test @@ -0,0 +1,95 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4160 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8304 + Size: 366 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 0 + Size: 0 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 12288 + Size: 16 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 8 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 160 + SectionData: 5589E581EC0000000090B80020001050E88300000083C404C9C35589E581EC0000000090B80920001050E86900000083C404B800000000E900000000C9C210005589E581EC04000000908B4510508B450C508B450850E8250000008945FC8B45FCE900000000C9C20C00000000000000000000000000000000000000000000005589E581EC0000000090B801000000E900000000C9C20C00FF25482000100000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E00000000000000000000000050200000000000000000000058200000482000000000000000000000000000000000000000000000632000000000000063200000000000006D73766372742E646C6C00000070757473000000000000000000000000000000000000001A210000010000000D0000000D00000098200000CC20000000210000801000001A1000004010000000300000003000000030000000300000003000000030000020200000E0210000981000000010000027210000332100003F2100004D2100005E210000712100008221000095210000A9210000BF210000C6210000CB210000D221000000000100020003000400050006000700080009000A000B000C00706533325F7374642E646C6C005F446C6C4D61696E403132005F446C6C4D61696E403136005F5F646C6C7374617274403132005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F7468657265000000 + - Name: .reloc + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 16 + SectionData: 00100000100000000B3025309A300000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 100.0% 512 100.0% 160 .text +# CHECK: 100.0% 512 100.0% 160 TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 1.50Ki, vm = 992 of entries + + diff --git a/tests/PE/filter/source-filter-text-pe64.test b/tests/PE/filter/source-filter-text-pe64.test new file mode 100644 index 00000000..99d4de34 --- /dev/null +++ b/tests/PE/filter/source-filter-text-pe64.test @@ -0,0 +1,95 @@ +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty --source-filter text %t.obj | %FileCheck %s --dump-input fail + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4192 + ImageBase: 268435456 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 4 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 4 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI + DLLCharacteristics: [ ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 + ExportTable: + RelativeVirtualAddress: 8320 + Size: 336 + ImportTable: + RelativeVirtualAddress: 8224 + Size: 40 + ResourceTable: + RelativeVirtualAddress: 0 + Size: 0 + ExceptionTable: + RelativeVirtualAddress: 12288 + Size: 36 + CertificateTable: + RelativeVirtualAddress: 0 + Size: 0 + BaseRelocationTable: + RelativeVirtualAddress: 0 + Size: 0 + Debug: + RelativeVirtualAddress: 0 + Size: 0 + Architecture: + RelativeVirtualAddress: 0 + Size: 0 + GlobalPtr: + RelativeVirtualAddress: 0 + Size: 0 + TlsTable: + RelativeVirtualAddress: 0 + Size: 0 + LoadConfigTable: + RelativeVirtualAddress: 0 + Size: 0 + BoundImport: + RelativeVirtualAddress: 0 + Size: 0 + IAT: + RelativeVirtualAddress: 8264 + Size: 16 + DelayImportDescriptor: + RelativeVirtualAddress: 0 + Size: 0 + ClrRuntimeHeader: + RelativeVirtualAddress: 0 + Size: 0 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DEBUG_STRIPPED, IMAGE_FILE_DLL ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 168 + SectionData: 554889E54881EC20000000488D0DEE0F0000E889000000C9C30000000104020504030150554889E54881EC2000000048894D10488955184C8945204C894D28488D0DC30F0000E855000000B800000000E900000000C9C3000000000000000000554889E54881EC3000000048894D10488955184C894520488B45204989C08B5518488B4D10E89AFFFFFF8945FC8B45FCE900000000C9C3000104020504030150FF25A20F00000000 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + VirtualAddress: 8192 + VirtualSize: 480 + SectionData: 637572696F757321004D61726B204A616E73656E0000000000000000000000005820000000000000000000006820000048200000000000000000000000000000000000000000000073200000000000000000000000000000732000000000000000000000000000006D73766372742E646C6C000000707574730000000000000000000000000000000000000020210000010000000C0000000C000000A8200000D820000008210000241000000040000000400000004000000040000000400000004000006010000020200000E0210000A0100000001000002D2100003521000046210000592100006A2100007D21000091210000A7210000B1210000B8210000BD210000C421000000000100020003000400050006000700080009000A000B00706536345F7374642E646C6C00446C6C4D61696E005F5F66696E695F61727261795F656E64005F5F66696E695F61727261795F7374617274005F5F696E69745F61727261795F656E64005F5F696E69745F61727261795F7374617274005F5F707265696E69745F61727261795F656E64005F5F707265696E69745F61727261795F7374617274005F646C6C7374617274005F6564617461005F656E64005F65746578740068656C6C6F5F74686572650000000000000000000000000000000000 + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 12288 + VirtualSize: 36 + SectionData: 0B100000191000001C1000002F100000571000001C1000006B1000009710000098100000 +symbols: [] +... + +# CHECK: FILE SIZE VM SIZE +# CHECK: -------------- -------------- +# CHECK: 100.0% 512 100.0% 168 .text +# CHECK: 100.0% 512 100.0% 168 TOTAL +# CHECK:Filtering enabled (source_filter); omitted file = 1.50Ki, vm = 1.00Ki of entries + + diff --git a/tests/test.h b/tests/test.h index 99517d73..7f7a2e3f 100644 --- a/tests/test.h +++ b/tests/test.h @@ -140,7 +140,7 @@ class BloatyTest : public ::testing::Test { void CheckConsistency(const bloaty::Options& options) { ASSERT_EQ(options.base_filename_size() > 0, output_->diff_mode()); - if (!output_->diff_mode()) { + if (!output_->diff_mode() && !options.has_source_filter() && !options.has_exclude_source_filter()) { size_t total_input_size = 0; for (const auto& filename : options.filename()) { uint64_t size;