4

I am using the C++ standard library in some C++ code and this makefile:

CC=g++
CXXFLAGS=-Wall -Werror -ggdb3 -std=c++11 -pedantic $(OTHERFLAGS)
cpp_sort: cpp_sort.o
    g++ -o $@ $(CXXFLAGS) $^
clean:
rm -rf *.o cpp_sort *~

The source code:

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void get_input(vector<int>& items, int size) {
    for (int i = 0; i < size; ++i) {
        int element;
        cin >> element;
        items.push_back(element);
    }
}

void cpp_sort(vector<int>& items) {
    sort(items.begin(), items.end());
}

void print_array(vector<int>& items) {
    for (auto& item : items) {
        cout << item << ' ';
    }
    cout << endl;
}


int main() {
    int size;
    cin >> size;
    vector<int> items;
    items.reserve(size);
    get_input(items, size);
    cpp_sort(items);
    print_array(items);
}

I call make like this:

make OTHERFLAGS=-pg

run the program (where large.txt is a long list of integers):

./cpp_sort <large.txt

and view the profiling information:

grof ./cpp_sort

Which is fine and it does work, but the calling of my functions is obscured by all the C++ standard library function calls. Is there a way to exclude the standard library internal function calls?

Angus Comber
  • 9,316
  • 14
  • 59
  • 107
  • What does "obscured by all the C++ standard library function calls" mean? – The Quantum Physicist Jan 04 '19 at 12:14
  • @TheQuantumPhysicist in this example, the large number of std lib function calls in the gprof output crowds out the calls to the functions in the source file I wrote. Nothing wrong with that per se, but for analysis purposes it would be good to focus in on 'my' functions. – Angus Comber Jan 04 '19 at 12:24

0 Answers0