How to make gprof report in nanosecond? - c++

I'm trying to profile my C++ application, using gprof I would like to calculate function execution time. However in case some functions run faster than 0.01s it's reported on gprof with value 0.00. How can I change the report time of gprof to nanosecond?
Thanks for your advices.
Flat profile:
Each sample counts as 0.01 seconds.
no time accumulated
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 3 0.00 0.00 access_counter
0.00 0.00 0.00 2 0.00 0.00 get_counter
0.00 0.00 0.00 1 0.00 0.00 start_counter
Copyright (C) 2012-2015 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
.....
Call graph (explanation follows)
granularity: each sample hit covers 2 byte(s) no time propagated
index % time self children called name
0.00 0.00 1/3 start_counter [3]
0.00 0.00 2/3 get_counter [2]
[1] 0.0 0.00 0.00 3 access_counter [1]
-----------------------------------------------
0.00 0.00 2/2 main [9]
[2] 0.0 0.00 0.00 2 get_counter [2]
0.00 0.00 2/3 access_counter [1]
-----------------------------------------------
0.00 0.00 1/1 main [9]
[3] 0.0 0.00 0.00 1 start_counter [3]
0.00 0.00 1/3 access_counter [1]
-----------------------------------------------

Related

Django filters two fields in different records with the same value

In Django, I have a large amount of data(real data is about tens of thousands). I want to find all records with the same amount of income and expenditure. What should I do?
Mysql:
id
income
expenses
1
0.00
50.00
2
0.00
43.00
3
50.00
0.00
4
50.00
0.00
5
29.00
0.00
6
23.00
0.00
7
0.00
23.00
8
0.00
5.00
9
0.00
12.00
I want to filter out data 13467. All expenses and income amounts have the same data (excluding the amount is 0.00)
id
income
expenses
1
0.00
50.00
3
50.00
0.00
4
50.00
0.00
6
23.00
0.00
7
0.00
23.00
you can do this:
from django.db.models import F
data = Model.objects.filter(income_field=F("expenses_field_name")).exclude(income_field=0)
same question with Datetime Field. Answer

Why doesn't the reg exp that works in regex101 dot com, does NOT work with grep nor with vim in Linux

I have an ascii file in the format below:
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/reg/dff_in_gated 17.13 0.0 6.00 11.13 0.00 gc_ht_t_dff_en_in_WIDTH84_0
gc_ab_cd/reg/dff_in_send_gated 0.20 0.0 0.00 0.20 0.00 gc_ht_t_dff_in_WIDTH1_33
gc_ab_cd/reg/rd_rtn 11.42 0.0 4.20 7.22 0.00 gc_ht_t_gfx_2toN_WIDTH32_1
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
gc_ab_cd/tap_ch/throttle 136.63 0.0 77.33 59.30 0.00 gc_ht_t_gc_vm2__throttle
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
gc_ab_cd/vm2_dbg/bg_mux 22.79 0.0 9.90 4.80 0.00 gc_ht_t_gc_dbg_mux_4_1_01
gc_ab_cd/vm2_dbg/bg_mux/clk 0.20 0.0 0.00 0.20 0.00 gc_ht_t_clock
gc_ab_cd/vm2_dbg/bg__mux/flop_mux_flop 5.33 0.0 2.63 2.70 0.00 gc_ht_t_dbg_COUNT4_WIDTH8_0
I need to grep 0 or 1 level of the hierarchy of the first field in the above text, so that the output of the "grep" should print the below in the stdout
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
I used the regexp https://regex101.com/r/D92KSP/1
But it gives only 3 matches below (1 level of hierarchy in the first field), as can be seen in https://regex101.com/r/D92KSP/1
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
Questions:
[1] I'm NOT sure why the below line (0 hierarchy in the first field) is NOT being matched by the regexp in https://regex101.com/r/D92KSP/1
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
[2] What should I do to modify the regexp https://regex101.com/r/D92KSP/1 to match the line below
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
[3] I used the above regexp with "grep" and in the vim editor in Linux and it doesn't work there, though it works partially in regexp101.com. Don't know why?
regex101 and other such web sites will help you create/validate a regexp that works on that web site, don't assume it'll work anywhere else, especially the mandatory POSIX command-line tools like sed, grep, and awk as each tool uses specific regexp variants (BRE, ERE, and/or PCRE) with different arguments (e.g. -E to enable EREs in grep and sed, -P to enable PCREs in grep with some caveats), extensions (e.g. word boundaries, shortcuts, or back references), and limitations (e.g. delimiter chars). You have to learn which regexp variant with which extensions and limitations the version (e.g. GNU or BSD) of the tool you want to use supports.
In any case, any time you're talking about fields you should be using awk, not grep (or sed) since awk is the tool that separates input into fields. The following will work using any awk in any shell on every Unix box:
$ awk '$1 ~ "^[^/]*/?[^/]*$"' file
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
or to search for a specific path depth by just setting a numeric variable on the command line:
$ awk -v n=2 '{key=$1} gsub("/","&",key)<n' file
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
$ awk -v n=3 '{key=$1} gsub("/","&",key)<n' file
gc_ab_cd 92641.48 25.2 5.12 9.20 0.00 gc_ht_t_gc_ab_cd
gc_ab_cd/reg 29.24 0.0 0.49 0.01 0.00 gc_ht_t_CHECK1_0
gc_ab_cd/reg/dff_in_gated 17.13 0.0 6.00 11.13 0.00 gc_ht_t_dff_en_in_WIDTH84_0
gc_ab_cd/reg/dff_in_send_gated 0.20 0.0 0.00 0.20 0.00 gc_ht_t_dff_in_WIDTH1_33
gc_ab_cd/reg/rd_rtn 11.42 0.0 4.20 7.22 0.00 gc_ht_t_gfx_2toN_WIDTH32_1
gc_ab_cd/regs 18583.88 5.1 2958.87 25.01 0.00 gc_ht_t_gc_ab_cd_regs
gc_ab_cd/tap_ch 431.51 0.1 144.83 150.05 0.00 gc_ht_t_gc_vm2_qe128
gc_ab_cd/tap_ch/throttle 136.63 0.0 77.33 59.30 0.00 gc_ht_t_gc_vm2__throttle
gc_ab_cd/vm2_dbg 22.79 0.0 0.00 0.00 0.00 gc_ht_t_gfx_dbg_mux_01
gc_ab_cd/vm2_dbg/bg_mux 22.79 0.0 9.90 4.80 0.00 gc_ht_t_gc_dbg_mux_4_1_01

using the gprof -f option in Linux for c++

Hi so i have started using gprof for my profiling work and it works fine except for the -f option which allows me to specifiy a particular function to be viewed in the call graph.
for example
Call graph (explanation follows)
granularity: each sample hit covers 4 byte(s) no time propagated
index % time self children called name
0.00 0.00 1/1 __do_global_ctors_aux [13]
[5] 0.0 0.00 0.00 1 global constructors keyed to main [5]
0.00 0.00 1/1 __static_initialization_and_destruction_0(int, int) [6]
-----------------------------------------------
0.00 0.00 1/1 global constructors keyed to main [5]
[6] 0.0 0.00 0.00 1 __static_initialization_and_destruction_0(int, int) [6]
-----------------------------------------------
0.00 0.00 1/1 main [4]
[7] 0.0 0.00 0.00 1 car::DisplayPrice() [7]
-----------------------------------------------
0.00 0.00 1/1 main [4]
[8] 0.0 0.00 0.00 1 car::showc() [8]
-----------------------------------------------
0.00 0.00 1/1 main [4]
[9] 0.0 0.00 0.00 1 car::car(std::string, int) [9]
0.00 0.00 1/1 vehical::vehical(int, int) [12]
-----------------------------------------------
0.00 0.00 1/1 main [4]
[10] 0.0 0.00 0.00 1 car::~car() [10]
-----------------------------------------------
0.00 0.00 1/1 main [4]
[11] 0.0 0.00 0.00 1 vehical::show() [11]
-----------------------------------------------
0.00 0.00 1/1 car::car(std::string, int) [9]
[12] 0.0 0.00 0.00 1 vehical::vehical(int, int) [12]
-----------------------------------------------
Now if i specify
gprof -f car::car(std::string, int) a.out gmon.out
i get error
syntax error near unexpected token '('
now if i do
gprof -f car::car(std::string, int) a.out gmon.out
i get an error
No such file or directory
if i try putting the function in double quotes i get an output as above with no change..
CAN Someone please help me with this ??
Thanks in advance
() is taken by your shell. Try like this:
gprof -f 'car::car(std::string, int)' a.out gmon.out

gprof on MacOS 10.6 with c++ program has call data but no timing data --- why?

I have a C++ single-threaded program running on MacOS 10.6. It's getting call counts but not time information.
Here's an example of the output:
0.00 0.00 9/31377020 __ZNSaISsEC1Ev [454]
0.00 0.00 9/31377020 __ZNSaISsED1Ev [314]
0.00 0.00 9/31377020 __Z12banner_stampRSt14basic_ofstreamIcSt11char_traitsIcEE [3960]
0.00 0.00 9/31377020 __ZStorSt13_Ios_OpenmodeS_ [14555]
0.00 0.00 9/31377020 __ZNSaIP13ifstream_lineEC1Ev [497]
0.00 0.00 9/31377020 __ZNSaIP13ifstream_lineED1Ev [321]
0.00 0.00 9/31377020 __ZNSt6vectorISsSaISsEE5beginEv [511]
0.00 0.00 9/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EEC1ERKS2_ [510]
0.00 0.00 9/31377020 __ZNSt6vectorISsSaISsEEC1ERKS0_ [512]
0.00 0.00 9/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EED1Ev [404]
0.00 0.00 9/31377020 __ZNSt6vectorISsSaISsEED1Ev [405]
0.00 0.00 144/31377020 __ZNK9__gnu_cxx17__normal_iteratorIPSsSt6vectorISsSaISsEEEdeEv [9475]
0.00 0.00 144/31377020 __ZN9__gnu_cxx17__normal_iteratorIPSsSt6vectorISsSaISsEEEppEi [327]
0.00 0.00 144/31377020 __ZSt4findIN9__gnu_cxx17__normal_iteratorIPP13ifstream_lineSt6vectorIS3_SaIS3_EEEES3_ET_S9_S9_RKT0_ [296]
0.00 0.00 144/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EE5eraseEN9__gnu_cxx17__normal_iteratorIPS1_S3_EE [251]
0.00 0.00 144/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EE9push_backERKS1_ [316]
0.00 0.00 144/31377020 __ZNSt6vectorISsSaISsEE9push_backERKSs [317]
0.00 0.00 153/31377020 __ZNSt6vectorISsSaISsEE3endEv [312]
0.00 0.00 153/31377020 __ZN9__gnu_cxxneIPSsSt6vectorISsSaISsEEEEbRKNS_17__normal_iteratorIT_T0_EESA_ [294]
0.00 0.00 153/31377020 __ZN13ifstream_lineC1EPKc [4844]
0.00 0.00 153/31377020 __ZN13ifstream_lineD0Ev [4845]
0.00 0.00 162/31377020 __ZN16feature_recorder13fname_counterEiSs [229]
0.00 0.00 442461/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EEixEm [12736]
0.00 0.00 442479/31377020 __ZNKSt6vectorIP13ifstream_lineSaIS1_EE4sizeEv [10022]
0.00 0.00 442605/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EE5beginEv [113]
0.00 0.00 442605/31377020 __ZN13ifstream_line8nextlineEv [112]
0.00 0.00 442704/31377020 __ZStltIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_ES8_ [14535]
0.00 0.00 6816415/31377020 __ZN9__gnu_cxx17__normal_iteratorIPP13ifstream_lineSt6vectorIS2_SaIS2_EEEppEi [92]
0.00 0.00 7258876/31377020 __ZN9__gnu_cxxneIPP13ifstream_lineSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_ [87]
0.00 0.00 7259020/31377020 __ZNSt6vectorIP13ifstream_lineSaIS1_EE3endEv [91]
0.00 0.00 7828118/31377020 __ZNK9__gnu_cxx17__normal_iteratorIPP13ifstream_lineSt6vectorIS2_SaIS2_EEEdeEv [9445] [86]
0.0 0.00 0.00 31377020 __ZN16feature_recorder9recombineEv [86]
0.00 0.00 9/57 __ZN20feature_recorder_set13recombine_allEv [384]
Pretty weird, huh? 31,377,020 calls through, but 0 time recorded.
Anybody know what's going on?
I have heard some time ago that gprof did not work correctly on Snow Leopard and symptoms were like you described. If you find no solution then you may try out some other profiler like shark.

C++ main only uses ~20% time says gprof

I tried profiling my C++ program with gprof. The program itself ran for about 53 seconds, so I dont understand why it says, main only ran for about 8.29 seconds. Any explanation on this?
Here is an excerpt:
index % time self children called name
<spontaneous>
[2] 20.5 0.00 8.29 main [2]
0.00 8.28 1/1 MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
0.00 0.01 1/1 MPQS::MPQS(NTL::ZZ, long) [36]
0.00 0.00 1/1 MPQS::~MPQS() [78]
-----------------------------------------------
0.00 8.28 1/1 main [2]
[3] 20.5 0.00 8.28 1 MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
7.15 1.08 801/801 MPQS::sieve() [4]
0.00 0.04 801/801 MPQS::find_smooth_vals() [23]
0.01 0.00 1/1 MPQS::try_solutions(NTL::mat_GF2&) [35]
0.00 0.00 801/801 MPQS::compute_coeffecients() [59]
-----------------------------------------------
7.15 1.08 801/801 MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
[4] 20.4 7.15 1.08 801 MPQS::sieve() [4]
1.08 0.00 801/801 MPQS::find_candidates() [9]
Were you printing results to the console? gprof doesn't count blocked time. See this.