├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── include ├── bubble_sort.h ├── debug.h ├── definitions.h ├── matrix_multiplication.h └── pi_calculation.h ├── src ├── bubble_sort.c ├── debug.c ├── main.c ├── matrix_multiplication.c └── pi_calculation.c └── tools ├── gcov_generator.py ├── generate_afdo.sh ├── generate_perf_data.sh ├── install_autofdo.sh └── profile_generator.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = /bin/sh 2 | CC = gcc 3 | 4 | FLAGS = -std=gnu99 -Iinclude 5 | CFLAGS = -pedantic -Wall -Wextra -march=native -ggdb3 6 | LIBS = -lm 7 | DEBUGFLAGS = -O0 -D _DEBUG 8 | RELEASEFLAGS = -O3 -D NDEBUG 9 | 10 | SOURCES = $(shell echo src/*.c) 11 | COMMON = include/definitions.h include/debug.h 12 | HEADERS = $(shell echo include/*.h) 13 | OBJECTS = $(SOURCES:.c=.o) 14 | COBJECTS= src/debug.o 15 | CSOURCES= src/debug.c 16 | BINARIES= bubble_sort matrix_multiplication pi_calculation 17 | 18 | PREFIX = $(DESTDIR)/usr/local 19 | BINDIR = $(PREFIX)/bin 20 | 21 | INSTALLATION_PATH = /tmp 22 | PMU_TOOLS_PATH = $(INSTALLATION_PATH)/pmu-tools 23 | AUTOFDO_PATH = $(INSTALLATION_PATH)/autofdo 24 | 25 | all: $(BINARIES) 26 | 27 | # $(TARGET): src/main.o $(OBJECTS) $(COMMON) 28 | # $(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(DEBUGFLAGS) -o $@ $(OBJECTS) 29 | 30 | # release: $(SOURCES) $(HEADERS) $(COMMON) 31 | # $(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(RELEASEFLAGS) -o $(TARGET) $(SOURCES) 32 | 33 | release: $(SOURCES) $(HEADERS) $(COMMON) $(CSOURCES) 34 | $(foreach BINARY,$(BINARIES),$(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(RELEASEFLAGS) -o $(BINARY) src/$(BINARY).c $(CSOURCES);) 35 | 36 | # install: release 37 | # install -D $(TARGET) $(BINDIR)/$(TARGET) 38 | 39 | # install-strip: release 40 | # install -D -s $(TARGET) $(BINDIR)/$(TARGET) 41 | 42 | # uninstall: 43 | # -rm $(BINDIR)/$(TARGET) 44 | 45 | clean: 46 | -rm -f $(OBJECTS) 47 | 48 | cleanfdo: 49 | -rm -f *.data* 50 | -rm -f *.afdo* 51 | -rm -f *.gcda 52 | 53 | distclean: 54 | @find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print | xargs rm -f 55 | default: 56 | gcc main.c bubble_sort.c pi_calculation.c matrix_multiplication.c -lm -o demo 57 | 58 | remove: 59 | rm -rf demo* 60 | rm -rf *.data* 61 | rm -rf *.afdo* 62 | rm -rf *.gcda 63 | 64 | normalfdo: 65 | $(CC) -g3 $(FLAGS) $(LIBS) src/debug.c src/bubble_sort.c -o bubble_sort -fprofile-generate 66 | ./bubble_sort 67 | $(CC) $(FLAGS) $(LIBS) -O3 src/debug.c src/bubble_sort.c -o bubble_sort -fprofile-use="*.gcda" 68 | ./bubble_sort 69 | 70 | # autofdo: $(BINARIES) 71 | # ~/pmu-tools/ocperf.py record -b -e br_inst_retired.near_taken -- ./demo 72 | # /tmp/autofdo/create_gcov --binary=./demo --profile=perf.data --gcov=demo.afdo -gcov_version=1 73 | # $(CC) $(FLAGS) $(LIBS) -O3 -fauto-profile=demo.afdo $(SOURCES) -o demo_autofdo 74 | 75 | autofdo: $(BINARIES) $(PMU_TOOLS_PATH)/ocperf.py $(AUTOFDO_PATH)/create_gcov 76 | $(foreach BINARY,$(BINARIES),$(PMU_TOOLS_PATH)/ocperf.py record -b -e br_inst_retired.near_taken -- ./$(BINARY);$(AUTOFDO_PATH)/create_gcov --binary=./$(BINARY) --profile=perf.data --gcov=$(BINARY).afdo -gcov_version=1;) 77 | 78 | $(PMU_TOOLS_PATH)/ocperf.py: 79 | git clone https://github.com/andikleen/pmu-tools.git $(PMU_TOOLS_PATH) 80 | 81 | $(AUTOFDO_PATH)/create_gcov: 82 | ./install_autofdo.sh $(INSTALLATION_PATH) 83 | 84 | bubble_sort: src/bubble_sort.o $(COBJECTS) $(HEADERS) $(COMMON) 85 | $(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(DEBUGFLAGS) -o $@ $< $(COBJECTS) 86 | 87 | matrix_multiplication: src/matrix_multiplication.o $(COBJECTS) $(HEADERS) $(COMMON) 88 | $(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(DEBUGFLAGS) -o $@ $< $(COBJECTS) 89 | 90 | pi_calculation: src/pi_calculation.o $(COBJECTS) $(HEADERS) $(COMMON) 91 | $(CC) $(FLAGS) $(CFLAGS) $(LIBS) $(DEBUGFLAGS) -o $@ $< $(COBJECTS) 92 | 93 | %.o: %.c $(HEADERS) $(COMMON) 94 | $(CC) $(FLAGS) $(CFLAGS) $(DEBUGFLAGS) -c -o $@ $< 95 | 96 | 97 | 98 | .PHONY : all release clean distclean autofdo 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AutoFDO tutorial ================ 2 | 3 | This package will help you understand and automate the process of using 4 | feedback driven optimizations, the tutorial has been divided in three sections: 5 | 6 | ## 1. Basic understanding 7 | 8 | In this repository you will find a `sort.c` file that contains a sorting 9 | algorithm to start using optimizations, then you will need to read our document 10 | in https://gcc.gnu.org/wiki/AutoFDO/Tutorial and follow the steps to compare 11 | different types of optimizations: 12 | 13 | 1. GCC normal optimization (just add the -O flag to the gcc command) 14 | 2. FDO (By executing the instrumented binary, it will output data to a profile 15 | file) 16 | 3. AutoFDO (By using perf, it will sample the hardware events to create a 17 | profile file) 18 | 19 | You can read more information about using optimization flags in here 20 | https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html 21 | 22 | ## 2. Different use cases 23 | 24 | You might will be willing to optimize a package that can include different 25 | binaries, which may result in multiple binaries, so we included an example in 26 | this tutorial. Every binary contains different algorithms with a timing measure 27 | that prints at the end of the execution so you won't need to implement any time 28 | mesurement tool. 29 | 30 | #### GCC normal optimization 31 | 32 | If you want to know how much performance is imporved by FDO, compile them with 33 | `$ make release` This will enable the `-O3` flag. 34 | 35 | Execute every binary to know how much they delay. 36 | 37 | #### Normal FDO 38 | 39 | For this case you will need to compile all the binaries with the debug symbols 40 | and the `-fprofile-generate` flag to keep track of the execution feedback: 41 | 42 | $ gcc -g3 -Iinclude -lm -o bubble_sort src/bubble_sort.c src/debug.c 43 | -fprofile-generate $ gcc -g3 -Iinclude -lm -o matrix_multiplication 44 | src/matrix_multiplication.c src/debug.c -fprofile-generate $ gcc -g3 45 | -Iinclude -lm -o pi_calculation src/pi_calculation.c src/debug.c 46 | -fprofile-generate 47 | 48 | Then execute each binary to get the feedback: 49 | 50 | $ ./bubble_sort $ ./matrix_multiplication $ ./pi_calculation 51 | 52 | Then recompile again with the `-fprofile-use` flag and the optimization enabled 53 | (`-O3`) 54 | 55 | In case that you want to compile using `$ make release` you will need to change 56 | the `RELEASEFLAGS` variable to include `-fprofile-use=*.gcda` to use all the 57 | profile files 58 | 59 | $ make RELEASEFLAGS="-O3 -fprofile-use=*.gcda" release 60 | 61 | Execute the binaries again to measure the time and compare with other 62 | optimization methods. 63 | 64 | #### AutoFDO 65 | 66 | The first thing you do after downloading a source code is compiling, so go 67 | ahead and execute: 68 | 69 | $ make 70 | 71 | Then we have included a proccess that generates the profiles for you. We are 72 | taking advantage of a perf wrapper named `ocperf.py`, this tool can be found in 73 | the repository in here: https://github.com/andikleen/pmu-tools. We are also 74 | downloading and compiling AutoFDO from https://github.com/google/autofdo. The 75 | default location for this tools is /tmp/ you can change it by overwriting the 76 | `INSTALLATION_PATH` variable: 77 | 78 | $ make autofdo 79 | 80 | Then before recompiling, you will need to change the `RELEASEFLAGS` variable to 81 | use the .afdo profile files 82 | 83 | $ make RELEASEFLAGS="-O3 -fauto-profile=*.afdo" release 84 | 85 | 86 | Another option is to merge the profiles using the `profile_merger` binary in 87 | AutoFDO package. This will make you handle only just one .afdo file instead of 88 | multiple (Remember to include `-gcov_version=1` flag): 89 | 90 | $ /tmp/autofdo/profile_merger -gcov_version=1 *.afdo $ make 91 | RELEASEFLAGS="-O3 -fauto-profile=fbdata.afdo" release 92 | 93 | Execute the binaries again to measure the time and compare with other 94 | optimization methods. 95 | 96 | In case you want to clean everithing run `$ make distclean` this will delete 97 | all generated files to start compiling again. 98 | 99 | ## 3. Automation scripts 100 | 101 | If you want to get the perf.data of any execution you can use the 102 | `generate_perf_data.sh` file. This script will automatically download the 103 | pmu_tools repository in specified directory (/tmp/ by default): 104 | 105 | $ ./generate_perf_data.sh --command="./some_tool --params" 106 | 107 | If you want to generate an AutoFDO profile, you can use the 108 | `profile_generator.py`. This script will automatically download and compile 109 | AutoFDO package in specified directory (/tmp/ by default) 110 | 111 | $ ./profile_generator.py some_tool.data 112 | 113 | Then you will have a `some_tool.afdo` merged profile that can be used to 114 | recompile the "some_tool" binaries 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /include/bubble_sort.h: -------------------------------------------------------------------------------- 1 | #ifndef BUBBLE_SORT_H_ 2 | #define BUBBLE_SORT_H_ 3 | 4 | void bubble_sort (int *a, int n); 5 | void generate_array (int *buffer, int len); 6 | 7 | #endif // BUBBLE_SORT_H_ -------------------------------------------------------------------------------- /include/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_H_ 2 | #define DEBUG_H_ 3 | 4 | void start(); 5 | void stop(); 6 | 7 | #endif // DEBUG_H_ -------------------------------------------------------------------------------- /include/definitions.h: -------------------------------------------------------------------------------- 1 | #ifndef DEFINITIONS_H_ 2 | #define DEFINITIONS_H_ 3 | 4 | #define ARRAY_LEN 30000 5 | #define PI_LEN_MIN 10000 6 | #define PI_LEN_MAX 100000 7 | #define MATRIX_SIZE 800 8 | 9 | #endif // DEFINITIONS_H_ -------------------------------------------------------------------------------- /include/matrix_multiplication.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX_MULTIPLICATION_H_ 2 | #define MATRIX_MULTIPLICATION_H_ 3 | 4 | void multiply_matrix(int size); 5 | 6 | #endif // MATRIX_MULTIPLICATION_H_ -------------------------------------------------------------------------------- /include/pi_calculation.h: -------------------------------------------------------------------------------- 1 | #ifndef PI_CALCULATION_H_ 2 | #define PI_CALCULATION_H_ 3 | 4 | void calculate_pi_1(int len); 5 | void calculate_pi_2(int len); 6 | 7 | #endif // PI_CALCULATION_H_ -------------------------------------------------------------------------------- /src/bubble_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "bubble_sort.h" 5 | #include "definitions.h" 6 | #include "debug.h" 7 | 8 | void bubble_sort (int *a, int n) { 9 | int i, t, s = 1; 10 | while (s) { 11 | s = 0; 12 | for (i = 1; i < n; i++) { 13 | if (a[i] < a[i - 1]) { 14 | t = a[i]; 15 | a[i] = a[i - 1]; 16 | a[i - 1] = t; 17 | s = 1; 18 | } 19 | } 20 | } 21 | } 22 | 23 | void generate_array(int *buffer, int len){ 24 | printf("Bubble sorting array of %d elements\n", len); 25 | srand(time(NULL)); 26 | int i; 27 | for(i = 0; i < len; ++i) 28 | buffer[i] = rand(); 29 | bubble_sort(buffer, len); 30 | } 31 | 32 | int main(){ 33 | start(); 34 | int array[ARRAY_LEN]; 35 | generate_array(array, ARRAY_LEN); 36 | bubble_sort(array, ARRAY_LEN); 37 | stop(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "debug.h" 4 | 5 | struct timeval tm1; 6 | 7 | void start(){ 8 | gettimeofday(&tm1, NULL); 9 | } 10 | 11 | void stop(){ 12 | struct timeval tm2; 13 | gettimeofday(&tm2, NULL); 14 | unsigned long long t = 1000 * (tm2.tv_sec - tm1.tv_sec) + (tm2.tv_usec - tm1.tv_usec) / 1000; 15 | printf("%llu ms\n", t); 16 | 17 | } -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "bubble_sort.h" 2 | #include "pi_calculation.h" 3 | #include "matrix_multiplication.h" 4 | #include "definitions.h" 5 | #include "debug.h" 6 | 7 | int all(){ 8 | start(); 9 | int array[ARRAY_LEN]; 10 | generate_array(array, ARRAY_LEN); 11 | bubble_sort(array, ARRAY_LEN); 12 | calculate_pi_1(PI_LEN_MIN); 13 | calculate_pi_2(PI_LEN_MAX); 14 | multiply_matrix(MATRIX_SIZE); 15 | stop(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/matrix_multiplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "matrix_multiplication.h" 5 | #include "definitions.h" 6 | #include "debug.h" 7 | 8 | void multiply_matrix(int size){ 9 | printf("Multiplying matrix of %dx%d\n", size, size); 10 | int c, d, k, sum = 0; 11 | int first[size][size], second[size][size]; 12 | // int multiply[size][size]; 13 | srand(time(NULL)); 14 | 15 | //printf("Entering the elements of first matrix\n"); 16 | 17 | for (c = 0; c < size; c++) 18 | for (d = 0; d < size; d++) 19 | first[c][d] = rand(); 20 | 21 | //printf("Entering the elements of second matrix\n"); 22 | 23 | for (c = 0; c < size; c++) 24 | for (d = 0; d < size; d++) 25 | second[c][d] = rand(); 26 | 27 | for (c = 0; c < size; c++) { 28 | for (d = 0; d < size; d++) { 29 | for (k = 0; k < size; k++) { 30 | sum = sum + first[c][k]*second[k][d]; 31 | } 32 | 33 | // multiply[c][d] = sum; 34 | sum = 0; 35 | } 36 | } 37 | 38 | // printf("Product of entered matrices:-\n"); 39 | 40 | for (c = 0; c < size; c++) { 41 | for (d = 0; d < size; d++){ 42 | // printf("%d\t", multiply[c][d]); 43 | } 44 | 45 | // printf("\n"); 46 | } 47 | } 48 | 49 | int main(){ 50 | start(); 51 | multiply_matrix(MATRIX_SIZE); 52 | stop(); 53 | return 0; 54 | } -------------------------------------------------------------------------------- /src/pi_calculation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "pi_calculation.h" 4 | #include "definitions.h" 5 | #include "debug.h" 6 | 7 | void calculate_pi_1(int size){ 8 | printf("Calculating PI method 1 with %d digits \n", size); 9 | int i, j, k; 10 | int len = floor(10 * size/3) + 1; 11 | int A[len]; 12 | 13 | for(i = 0; i < len; ++i) { 14 | A[i] = 2; 15 | } 16 | 17 | int nines = 0; 18 | // int predigit = 0; 19 | 20 | for(j = 1; j < size + 1; ++j) { 21 | int q = 0; 22 | 23 | for(i = len; i > 0; --i) { 24 | int x = 10 * A[i-1] + q*i; 25 | A[i-1] = x % (2*i - 1); 26 | q = x / (2*i - 1); 27 | } 28 | 29 | A[0] = q%10; 30 | q = q/10; 31 | 32 | if (9 == q) { 33 | ++nines; 34 | } 35 | else if (10 == q) { 36 | //printf("%d", predigit + 1); 37 | 38 | for (k = 0; k < nines; ++k) { 39 | //printf("%d", 0); 40 | } 41 | // predigit = 0; 42 | nines = 0; 43 | } 44 | else { 45 | //printf("%d", predigit); 46 | // predigit = q; 47 | 48 | if (0 != nines) { 49 | for (k = 0; k < nines; ++k) { 50 | //printf("%d", 9); 51 | } 52 | 53 | nines = 0; 54 | } 55 | } 56 | } 57 | //printf("%d", predigit); 58 | } 59 | 60 | void calculate_pi_2(int size){ 61 | printf("Calculating PI method 2 with %d digits\n", size); 62 | int r[size + 1]; 63 | int i, k; 64 | int b, d; 65 | // int c = 0; 66 | 67 | for (i = 0; i < size; i++) { 68 | r[i] = 2000; 69 | } 70 | 71 | for (k = size; k > 0; k -= 14) { 72 | d = 0; 73 | 74 | i = k; 75 | for (;;) { 76 | d += r[i] * 10000; 77 | b = 2 * i - 1; 78 | 79 | r[i] = d % b; 80 | d /= b; 81 | i--; 82 | if (i == 0) break; 83 | d *= i; 84 | } 85 | // printf("%.4d", c + d / 10000); 86 | // c = d % 10000; 87 | } 88 | 89 | //printf("\n"); 90 | 91 | } 92 | 93 | 94 | int main(){ 95 | start(); 96 | calculate_pi_1(PI_LEN_MIN); 97 | calculate_pi_2(PI_LEN_MAX); 98 | stop(); 99 | return 0; 100 | } -------------------------------------------------------------------------------- /tools/gcov_generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) Intel Corporation 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at// 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | import argparse 15 | import os 16 | import sys 17 | import shutil 18 | import subprocess 19 | import time 20 | import logging 21 | import pdb 22 | 23 | logger = logging.getLogger(__name__) 24 | logger.setLevel(logging.DEBUG) 25 | 26 | VERSION="0.1" 27 | DEFAULT_LOGGING_LEVEL=logging.INFO 28 | 29 | def get_autofdo_path(): 30 | logger.info("Verifying AutoFDO path") 31 | p = subprocess.Popen(os.path.join(os.path.dirname(os.path.realpath(__file__)), "install_autofdo.sh"), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 32 | out, err = p.communicate() 33 | if p.returncode: 34 | logger.debug(out) 35 | logger.error(err) 36 | logger.error("AutoFDO compilation error") 37 | sys.exit(1) 38 | return out.split()[-1] 39 | 40 | def generate_perf_data(command): 41 | logger.info("Generating perf file") 42 | p = subprocess.Popen(os.path.join(os.path.dirname(os.path.realpath(__file__)), "generate_perf_data.sh -c=\""+command+"\""), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 43 | out, err = p.communicate() 44 | logger.info(out) 45 | if p.returncode: 46 | logger.error(err) 47 | logger.error("Perf file generation error") 48 | sys.exit(1) 49 | perf_file = command.split()[0] 50 | if "/" in perf_file: 51 | perf_file = perf_file.split("/")[-1] 52 | if "." in perf_file: 53 | perf_file = perf_file.split(".")[0] 54 | if not os.path.exists(perf_file) or not os.path.isfile(perf_file): 55 | logger.error("Perf data file wasn't created") 56 | sys.exit(1) 57 | return perf_file 58 | 59 | def parse_binaries(perf_file): 60 | logger.info("Parsing perf file") 61 | binaries = [] 62 | cmd = ["perf", "buildid-list", "-i", perf_file, "-H"] 63 | logger.debug("Executing command: "+" ".join(cmd)) 64 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 65 | out, err = p.communicate() 66 | if not p.returncode: 67 | logger.debug("Success") 68 | binaries = [line.strip().split()[1] for line in out.split("\n") if line] 69 | logger.debug(out) 70 | logger.debug(err) 71 | binaries = [line.strip().split()[1] for line in out.split("\n") if line] 72 | return binaries 73 | 74 | def generate_gcov(autofdo_path, perf_file, binaries, automerge=False): 75 | if not binaries: 76 | logger.error("No binaries found in "+perf_file) 77 | sys.exit(1) 78 | directory = perf_file[:-5] if perf_file.endswith(".data") else perf_file 79 | directory += "_gcovs" 80 | if os.path.exists(directory) and os.path.isdir(directory): 81 | shutil.rmtree(directory) 82 | os.mkdir(directory) 83 | logger.info("Generating gcovs") 84 | gcovs = [] 85 | for binary in binaries: 86 | if not binary.startswith("["): 87 | gcov_file = os.path.join(directory, binary.split("/")[-1]+".afdo") 88 | cmd = [os.path.join(autofdo_path, "create_gcov"), "--binary="+binary, "--profile="+perf_file, "--gcov="+gcov_file, "-gcov_version=1"] 89 | logger.debug("Executing command "+" ".join(cmd)) 90 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 91 | out, err = p.communicate() 92 | if not p.returncode: 93 | logger.debug("Successful") 94 | gcovs.append(gcov_file) 95 | logger.debug(out) 96 | logger.debug(err) 97 | if automerge: 98 | main_gcov = merge_gcovs(autofdo_path, gcovs) if len(gcovs) > 1 else gcovs[0] 99 | while not os.path.exists(main_gcov): 100 | time.sleep(1) 101 | new_gcov = perf_file.split(".data")[0]+".afdo" 102 | shutil.copy2(main_gcov, new_gcov) 103 | 104 | def merge_gcovs(autofdo_path, gcovs): 105 | logger.info("Waiting gcov creation") 106 | while not all([os.path.exists(f) for f in gcovs]): 107 | time.sleep(1) 108 | logger.info("Merging gcovs") 109 | p = subprocess.Popen([os.path.join(autofdo_path, "profile_merger")] + gcovs + ["-gcov_version=1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 110 | return "fbdata.afdo" if not p.returncode else "" 111 | 112 | 113 | if __name__ == "__main__": 114 | parser = argparse.ArgumentParser(prog='./gcov_generator.py', 115 | usage='%(prog)s [options]') 116 | parser.add_argument('-c', '--command', dest='command', action='store', help='Command to execute benchmark' 117 | help="Perf data files") 118 | parser.add_argument('-l', '--verbosity_level', dest='verbosity_level', 119 | action='store', default=logging.getLevelName(DEFAULT_LOGGING_LEVEL), 120 | choices=[logging.getLevelName(logging.DEBUG), 121 | logging.getLevelName(logging.INFO), 122 | logging.getLevelName(logging.ERROR)], 123 | help='Set the verbosity level (default = {default})'.format(default=logging.getLevelName(DEFAULT_LOGGING_LEVEL))) 124 | parser.add_argument('-v', '--version', action='version', 125 | version='%(prog)s Version: {version}'.format(version=VERSION), 126 | help='Show version and exit') 127 | args = parser.parse_args() 128 | ch = logging.StreamHandler() 129 | if args.verbosity_level == logging.getLevelName(logging.DEBUG): 130 | ch.setLevel(logging.DEBUG) 131 | elif args.verbosity_level == logging.getLevelName(logging.INFO): 132 | ch.setLevel(logging.INFO) 133 | elif args.verbosity_level == logging.getLevelName(logging.ERROR): 134 | ch.setLevel(logging.ERROR) 135 | else: 136 | logger.error("Unrecognized logging level") 137 | logger.addHandler(ch) 138 | autofdo_path = get_autofdo_path() 139 | perf_file = generate_perf_data(args.command) 140 | binaries = parse_binaries(perf_file) 141 | gcov = generate_gcov(autofdo_path, perf_file, binaries, automerge=True) 142 | -------------------------------------------------------------------------------- /tools/generate_afdo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) Intel Corporation 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at// 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | for i in "$@" 15 | do 16 | case $i in 17 | -i=*|--installation_path=*) 18 | INSTALLATION_PATH="${i#*=}" 19 | shift 20 | ;; 21 | -b=*|--binaries=*) 22 | BINARIES="${i#*=}" 23 | shift 24 | ;; 25 | --default) 26 | DEFAULT=YES 27 | shift 28 | ;; 29 | *) 30 | ;; 31 | esac 32 | done 33 | 34 | INSTALLATION_PATH=${INSTALLATION_PATH:-"/tmp"} 35 | 36 | # echo $INSTALLATION_PATH 37 | # echo $BINARIES 38 | 39 | if [ ! -z "$BINARIES" ]; then 40 | 41 | echo "Verifying files" 42 | CWD="$(pwd)" 43 | while IFS=',' read -ra ADDR; do 44 | for i in "${ADDR[@]}"; do 45 | # echo $i 46 | if [ ! -f $i ]; then 47 | echo "$i doesn't exist" 48 | exit 1 49 | fi 50 | done 51 | done <<< "$BINARIES" 52 | 53 | which create_gcov 54 | if [ $? -eq 0 ]; then 55 | CREATE_GCOV="$(which create_gcov)" 56 | PROFILE_MERGER="$(which profile_merger)" 57 | else 58 | if [ ! -f $INSTALLATION_PATH/autofdo/create_gcov ]; then 59 | echo "Installing autofdo" 60 | cd $INSTALLATION_PATH 61 | git clone https://github.com/google/autofdo 62 | cd autofdo 63 | ./configure 64 | make 65 | fi 66 | CREATE_GCOV=$INSTALLATION_PATH/autofdo/create_gcov 67 | fi 68 | 69 | which ocperf.py 70 | if [ $? -eq 0 ]; then 71 | OCPERF="$(which ocperf.py)" 72 | else 73 | if [ ! -f $INSTALLATION_PATH/pmu-tools/ocperf.py ]; then 74 | echo "Installing pmu-tools" 75 | cd $INSTALLATION_PATH 76 | git clone https://github.com/andikleen/pmu-tools 77 | fi 78 | OCPERF=$INSTALLATION_PATH/pmu-tools/ocperf.py 79 | fi 80 | 81 | echo "Generating profiles" 82 | cd $CWD 83 | while IFS=',' read -ra ADDR; do 84 | for i in "${ADDR[@]}"; do 85 | $OCPERF record -b -g -e br_inst_retired.near_taken -o $CWD/$i.data -- $CWD/$i 86 | #$CREATE_GCOV --binary=$CWD/$i --profile=perf.data --gcov=$CWD/$i.afdo -gcov_version=1 87 | done 88 | done <<< "$BINARIES" 89 | echo "Merging profiles" 90 | #$PROFILE_MERGER $(echo *.afdo) -gcov_version=1 91 | 92 | else 93 | echo "No binaries provided, use -b=binary option" 94 | fi 95 | -------------------------------------------------------------------------------- /tools/generate_perf_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) Intel Corporation 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at// 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | for i in "$@" 15 | do 16 | case $i in 17 | -i=*|--installation_path=*) 18 | INSTALLATION_PATH="${i#*=}" 19 | shift 20 | ;; 21 | -c=*|--command=*) 22 | COMMAND="${i#*=}" 23 | shift 24 | ;; 25 | *) 26 | ;; 27 | esac 28 | done 29 | 30 | INSTALLATION_PATH=${INSTALLATION_PATH:-"/tmp"} 31 | 32 | if [ ! -z "$COMMAND" ]; then 33 | 34 | CWD="$(pwd)" 35 | IFS=' ' read -a c_array <<< "$COMMAND" 36 | BINARY=${c_array[0]} 37 | IFS='/' read -a b_array <<< "$BINARY" 38 | NAME=${b_array[-1]} 39 | IFS='.' read -a n_array <<< "$NAME" 40 | SHORTNAME=${n_array[0]} 41 | 42 | which ocperf.py > /dev/null 2>&1 43 | if [ $? -eq 0 ]; then 44 | OCPERF="$(which ocperf.py)" 45 | else 46 | if [ ! -f $INSTALLATION_PATH/pmu-tools/ocperf.py ]; then 47 | echo "Installing pmu-tools" 48 | cd $INSTALLATION_PATH 49 | git clone https://github.com/andikleen/pmu-tools 50 | fi 51 | OCPERF=$INSTALLATION_PATH/pmu-tools/ocperf.py 52 | fi 53 | 54 | echo "Generating profiles" 55 | cd $CWD 56 | $OCPERF record -b -e br_inst_retired.near_taken -o $CWD/$SHORTNAME.data -- $COMMAND 57 | 58 | else 59 | echo "No command provided, use -c=\"tool --params\" option" 60 | fi 61 | 62 | -------------------------------------------------------------------------------- /tools/install_autofdo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INSTALLATION_PATH=${1:-"/tmp"} 4 | 5 | which create_gcov > /dev/null 2>&1 6 | if [ $? -eq 0 ]; then 7 | echo "AutoFDO is installed" 8 | echo $(dirname "$(which create_gcov)") 9 | else 10 | if [ ! -f $INSTALLATION_PATH/autofdo/create_gcov ]; then 11 | echo "Installing autofdo" 12 | cd $INSTALLATION_PATH 13 | git clone https://github.com/google/autofdo 14 | cd autofdo 15 | echo "$(pwd)" 16 | ./configure 17 | aclocal 18 | automake --add-missing 19 | make 20 | fi 21 | echo "AutoFDO is installed" 22 | echo "$INSTALLATION_PATH/autofdo" 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /tools/profile_generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) Intel Corporation 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at// 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | import argparse 15 | import os 16 | import sys 17 | import shutil 18 | import subprocess 19 | import time 20 | import logging 21 | import pdb 22 | 23 | logger = logging.getLogger(__name__) 24 | logger.setLevel(logging.DEBUG) 25 | 26 | VERSION="0.1" 27 | DEFAULT_LOGGING_LEVEL=logging.INFO 28 | 29 | def get_autofdo_path(): 30 | logger.info("Verifying AutoFDO path") 31 | p = subprocess.Popen(os.path.join(os.path.dirname(os.path.realpath(__file__)), "install_autofdo.sh"), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 32 | out, err = p.communicate() 33 | if p.returncode: 34 | logger.debug(out) 35 | logger.error(err) 36 | logger.error("AutoFDO compilation error") 37 | sys.exit(1) 38 | return out.split()[-1] 39 | 40 | def parse_binaries(perf_file): 41 | logger.info("Parsing perf file") 42 | binaries = [] 43 | exist = False 44 | if not os.path.exists(perf_file) or not os.path.isfile(perf_file): 45 | logger.error("Perf data file wasn't found") 46 | sys.exit(1) 47 | cmd = ["perf", "buildid-list", "-i", perf_file, "-H"] 48 | logger.debug("Executing command: "+" ".join(cmd)) 49 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 50 | out, err = p.communicate() 51 | if not p.returncode: 52 | logger.debug("Success") 53 | binaries = [line.strip().split()[1] for line in out.split("\n") if line] 54 | logger.debug(out) 55 | logger.debug(err) 56 | binaries = [line.strip().split()[1] for line in out.split("\n") if line] 57 | return binaries 58 | 59 | def generate_gcov(autofdo_path, perf_file, binaries, automerge=False): 60 | if not binaries: 61 | logger.error("No binaries found in "+perf_file) 62 | sys.exit(1) 63 | directory = perf_file[:-5] if perf_file.endswith(".data") else perf_file 64 | directory += "_gcovs" 65 | if os.path.exists(directory) and os.path.isdir(directory): 66 | shutil.rmtree(directory) 67 | os.mkdir(directory) 68 | logger.info("Generating gcovs") 69 | gcovs = [] 70 | for binary in binaries: 71 | if not binary.startswith("["): 72 | gcov_file = os.path.join(directory, binary.split("/")[-1]+".afdo") 73 | cmd = [os.path.join(autofdo_path, "create_gcov"), "--binary="+binary, "--profile="+perf_file, "--gcov="+gcov_file, "-gcov_version=1"] 74 | logger.debug("Executing command "+" ".join(cmd)) 75 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 76 | out, err = p.communicate() 77 | if not p.returncode: 78 | logger.debug("Successful") 79 | gcovs.append(gcov_file) 80 | logger.debug(out) 81 | logger.debug(err) 82 | if automerge: 83 | main_gcov = merge_gcovs(autofdo_path, gcovs) if len(gcovs) > 1 else gcovs[0] 84 | while not os.path.exists(main_gcov): 85 | time.sleep(1) 86 | new_gcov = perf_file.split(".data")[0]+".afdo" 87 | shutil.copy2(main_gcov, new_gcov) 88 | 89 | def merge_gcovs(autofdo_path, gcovs): 90 | logger.info("Waiting gcov creation") 91 | while not all([os.path.exists(f) for f in gcovs]): 92 | time.sleep(1) 93 | logger.info("Merging gcovs") 94 | p = subprocess.Popen([os.path.join(autofdo_path, "profile_merger")] + gcovs + ["-gcov_version=1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 95 | return "fbdata.afdo" if not p.returncode else "" 96 | 97 | 98 | if __name__ == "__main__": 99 | parser = argparse.ArgumentParser(prog='./profile_generator.py', 100 | usage='%(prog)s [options]') 101 | parser.add_argument("perf_files", nargs="+", 102 | help="Perf data files") 103 | parser.add_argument('-l', '--verbosity_level', dest='verbosity_level', 104 | action='store', default=logging.getLevelName(DEFAULT_LOGGING_LEVEL), 105 | choices=[logging.getLevelName(logging.DEBUG), 106 | logging.getLevelName(logging.INFO), 107 | logging.getLevelName(logging.ERROR)], 108 | help='Set the verbosity level (default = {default})'.format(default=logging.getLevelName(DEFAULT_LOGGING_LEVEL))) 109 | parser.add_argument('-v', '--version', action='version', 110 | version='%(prog)s Version: {version}'.format(version=VERSION), 111 | help='Show version and exit') 112 | args = parser.parse_args() 113 | ch = logging.StreamHandler() 114 | if args.verbosity_level == logging.getLevelName(logging.DEBUG): 115 | ch.setLevel(logging.DEBUG) 116 | elif args.verbosity_level == logging.getLevelName(logging.INFO): 117 | ch.setLevel(logging.INFO) 118 | elif args.verbosity_level == logging.getLevelName(logging.ERROR): 119 | ch.setLevel(logging.ERROR) 120 | else: 121 | logger.error("Unrecognized logging level") 122 | logger.addHandler(ch) 123 | autofdo_path = get_autofdo_path() 124 | for perf_file in args.perf_files: 125 | binaries = parse_binaries(perf_file) 126 | gcov = generate_gcov(autofdo_path, perf_file, binaries, automerge=True) 127 | --------------------------------------------------------------------------------