Parsing lcov total.info - c++

I'm parsing the total.info file which is the result of running a few lcov commands on my source code in order to build a service that provides coverage information when needed.
lcov also provides a nice html ui to browse code coverage.
The problem is that i'm getting different values in terms of function coverage in my service than the html ui of lcov.
I'm calculating code coverage on end to end tests and not on unit tests.
Gcc version is 4.8.5 Red Hat
Lcov version is 1.14
The launched lcov commands are in the following order:
1- time lcov -c -i -d . --rc geninfo_adjust_src_path="{path} => " -o base.info
2- time lcov -c -d . --rc geninfo_adjust_src_path="{path} => " -o test.info
3- time lcov -rc geninfo_adjust_src_path="{path} => " -a base.info -a test.info -o total.info
To make it simpler here are 2 sections from the total.info file.
In this section, the parsing is working correctly
There are 5 functions
TN:
SF:{path}/FileOne.hpp
FN:22,_methodName
FN:29,_methodName
FN:31,_methodName
FN:40,_methodName
FN:48,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:6,_methodName
FNDA:6,_methodName
FNDA:0,_methodName
FNF:5
FNH:2
DA:22,6
DA:29,12
DA:31,6
DA:33,24
DA:34,0
DA:35,6
DA:36,6
DA:40,0
DA:42,0
DA:43,0
DA:45,0
DA:48,0
DA:50,0
DA:51,0
DA:54,0
LF:15
LH:6
end_of_record
The parsing problems are happening in the section below as some functions appear to have duplicate FN statement (They all start at the same line, so I assume this is referring to the same function)
TN:
SF:{path}/FileTwo.hpp
FN:32,_methodName
FN:39,_methodName
FN:48,_methodName
FN:58,_methodName
FN:64,_methodName
FN:100,_methodName
FN:116,_methodName
FN:116,_methodName
FN:128,_methodName
FN:128,_methodName
FN:128,_methodName
FN:128,_methodName
FN:132,_methodName
FN:138,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNDA:0,_methodName
FNF:14
FNH:0
DA:32,0
DA:33,0
DA:39,0
DA:40,0
DA:41,0
DA:44,0
DA:48,0
DA:49,0
DA:51,0
DA:52,0
DA:55,0
DA:56,0
DA:58,0
DA:59,0
DA:60,0
DA:61,0
DA:62,0
DA:64,0
DA:65,0
DA:66,0
DA:68,0
DA:91,0
DA:92,0
DA:96,0
DA:97,0
DA:100,0
DA:101,0
DA:102,0
DA:104,0
DA:105,0
DA:106,0
DA:112,0
DA:116,0
DA:117,0
DA:118,0
DA:121,0
DA:122,0
DA:125,0
DA:128,0
DA:129,0
DA:130,0
DA:132,0
DA:133,0
DA:134,0
DA:135,0
DA:138,0
DA:139,0
DA:140,0
DA:141,0
DA:142,0
DA:145,0
LF:51
LH:0
end_of_record
At lines 116 & 128, the functions are as follows:
115 : template <typename UnaryOp>
116 0 : void remove_if(UnaryOp op) {
117 0 : for (typename Items::iterator it = m_items.begin(), end = m_items.end(); it != end;) {
118 0 : if (!op(*it))
119 : ++it;
120 : else {
121 0 : shutItem(*it);
122 0 : m_items.erase(it++);
123 : }
124 : }
125 0 : }
127 : template <typename Op>
128 0 : void for_each(Op &op) {
129 0 : std::for_each(m_items.begin(), m_items.end(), op);
130 0 : }
My question is why are some functions appearing multiple times (who's "FN:{}" start at the same line)?

Related

How do I send text from TextView to 'Export to PDF'?

I'm new to GTK4, an open source toolkit for C++ binding. I want to send text from current TextView buffer (from a saved file) to a PDF file using GTK libraries (gtkmm4), but couldn't get anything printed out.
This is the code I have started from reading the documentation:
void MainWindow:export_note() {
auto op = Gtk::PrintOperation::create();
// setup op
cout << save_file_path << endl;
string content = editor.get_buffer()->get_text();
ofstream out(work_dir + save_file_path);
out << content;
out.close();
curr_state = edit_file;
op->set_export_filename("test.pdf");
auto res = op->run(Gtk::PrintOperation::Action::EXPORT);
return;
}
This only exports to a blank PDF, but I'm expecting text to show up on PDF.
It looks like you are not using any binary application to attempt conversion from text to text/pdf or more commonly binary application/pdf. You cannot simply stuff text data into a container called Test.pdf
There are simple means to convert Text to PDF, traditionally by using PostScript Printer files, but more commonly recently using a PDF printer driver direct
so start at the most basic level Hello World needs a file something like this, where the body is built up from stacked vectors or font labelled strings at X&Y co-ordinates.
Test.pdf
%PDF-1.1
%âãÏÓ
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
2 0 obj<</Type/Pages/Kids [3 0 R]/Count 1/MediaBox [0 0 594 792]>>endobj
3 0 obj<</Type/Page/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>>>>>/Contents 4 0 R>>endobj
4 0 obj<</Length 81
>>
stream
BT /F1 18 Tf 036 740 Td (Hello) Tj ET
BT /F1 18 Tf 036 720 Td (World!) Tj ET
endstream
endobj xref
0 5
0000000000 65535 f
0000000019 00000 n
0000000063 00000 n
0000000137 00000 n
0000000267 00000 n
trailer<</Root 1 0 R /Size 5>>startxref
399 %%EOF

lldb: `frame variable` has no value return

I use electron/build_tools to build electron and run e init --root=~/electron --bootstrap testing; e debug.(e debug runs local Electron build inside of lldb.)
Set a breakpoint by (lldb) br set --file archive.cc --line 155
Print any variable in this file, eg p header ,p size but return error.
Run frame variable , frame variable -g but no value return.
(lldb) br set --file archive.cc --line 155
(lldb) r
Process 30523 launched: '/Users/electron/src/out/Testing/Electron.app/Contents/MacOS/Electron' (x86_64)
Electron Framework was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 30523 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100352d90 Electron Framework`::Init() at archive.cc:155:63 [opt]
152 }
153
154 base::PickleIterator header_pickle(
-> 155 base::Pickle(reinterpret_cast<const char*>(file_.data() + 8), size));
156 std::string header;
157 if (!header_pickle.ReadString(&header)) {
158 LOG(ERROR) << "Failed to read header string at '" << path_.value() << "'";
Target 0: (Electron) stopped.
(lldb) frame variable
(lldb) p file_
error: <user expression 21>:1:1: use of undeclared identifier 'file_'
file_
^
(lldb) p size
error: <user expression 23>:1:1: reference to overloaded function could not be resolved; did you mean to call it?
size
^~~~
note: possible target for call

Reproduce list of data frame

today I wanted to run TropFishR package, the problem is (to me), every data must be arranged in list. So I tried to reconstruct the alba dataset in order to replicate with my own data in the future. Here is what I have done:
library(TropFishR)
data("alba")
str(alba) #the list contain 4 variables
List of 4
$ sample.no : int [1:14] 1 2 3 4 5 6 7 8 9 10 ...
$ midLengths: num [1:14] 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 ...
$ dates : Date[1:7], format: "1976-04-17" "1976-07-02" "1976-09-19" ...
$ catch : num [1:14, 1:7] 0 0 0 1 1 1 3 9 5 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:7] "1976.29315068493" "1976.50136986301" "1976.71780821918" "1976.95616438356" ...
- attr(*, "class")= chr "lfq"
And this is what I did:
#1 We create sample.no
sample.no <- c(1:14)
sample.no
#2 We create "midlengths"
midlengths <- seq(from = 1.5, to = 14.5, by = 1)
midlengths
#3 We create "dates"
dates <- as.Date(c("1976-04-17","1976-07-02", "1976-09-19", "1976-12-15", "1977-02-18",
"1977-04-30", "1977-06-24"))
dates
#4 We create "catch"
catch <- as.matrix(read.csv(file.choose(), header=T))
#I copied the alba length freq data, move it to excel and imported as csv file
colnames(catch)<-NULL
print(catch)
#5 create list files
synLFQb <- list(sample.no,midlengths,dates,catch)
synLFQb #just checked if it turned out to be as desired format
#6 create a name for the data list
names(synLFQb) <- c("sample.no","midlengths","dates","catch")
#Finally, we need to assign the class lfq to our new object in order to allow it to be recognized by other TropFishR functions, e.g. plot.lfq:
class(synLFQb) <- "lfq"
it will produce "similar" data list
str(synLFQb)
List of 4
$ sample.no : int [1:14] 1 2 3 4 5 6 7 8 9 10 ...
$ midlengths: num [1:14] 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 ...
$ dates : Date[1:7], format: "1976-04-17" "1976-07-02" "1976-09-19" ...
$ catch : int [1:14, 1:7] 0 0 0 1 1 1 3 9 5 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : NULL
- attr(*, "class")= chr "lfq"
However, when everytime I tried to do this simple command:
plot(synLFQb, Fname="catch", hist.sc = 1)
It resulted in error:
> plot(synLFQb, Fname="catch", hist.sc = 1)
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
Any help will be much appreciated.
Please make sure that you call the mid lengths vector in your list "midLengths" with a capital "L". I hope that will does the trick in your example.

error in abline when run via RInside

I'm running into a problem using RInside vs the console. This is all run on ubuntu 14.04 using R 3.2.4 installed via apt-get from CRAN. Here is the c++ and R code:
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
R.parseEval("source('abline.R')");
}
abline.R
bp <- data.frame(
age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)
bp.lm <- lm(systolic ~ age)
plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)
The R code works fine from the console, but errors when the program is run.
mlilback#rc2x:/tmp/abtest$ ./abtest
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
what(): Error evaluating: source('abline.R')
Aborted (core dumped)
The if (noInt) { is from the source of abline (line 18 in my version of R). I'm completely stumped as to why this only happens via RInside.
Any ideas?
Works for me without any issues. Ubuntu 16.04. Running out of the examples directory to get the GNUmakefile-based build for free:
~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
-I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
-Wno-unused -Wall soquestion.cpp -Wl,--export-dynamic -fopenmp \
-L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm -lblas -llapack \
-L/usr/local/lib/R/site-library/RInside/lib -lRInside \
-Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$
I literally just copied an pasted your two files. Also:
~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$
You probably want to open a device file via pdf() or png() ...

Raising exceptions in Rcpp

I am trying to report errors from my rcpp code. I am using the constructor exception (const char *message_, const char *file, int line) from http://dirk.eddelbuettel.com/code/rcpp/html/classRcpp_1_1exception.html. To isolate the problem, I wrote the following bar.cpp:
#include <Rcpp.h>
RcppExport SEXP bar( SEXP x){
throw(Rcpp::exception("My Error Message","bar.cpp",4));
return x ;
}
When I run it in R, this is what I get:
> dyn.load("bar.so")
> is.loaded("bar")
[1] TRUE
> .Call("bar",12)
Error: SET_VECTOR_ELT() can only be applied to a 'list', not a 'NULL'
>
You can either
use the inline package which puts a try/catch block into the function it generates for you (by using two simple macros)
or do it manually yourself as shown in a bunch of examples on my blog, or in the examples/ section of the Rcpp package,
but doing what you (ie: throwing outside of a try/catch block) can never work.
As an added bonus, here is a complete example (which essentially already existed in the unit tests):
R> library(inline)
R> f <- cxxfunction(signature(), plugin="Rcpp", body='
+ throw std::range_error("boom");
+ return R_NilValue;
+ ')
R> f()
Error in f() : boom
R>
Again, cxxfunction() puts a try/catch() block in here for you as you can see if you turn verbose on:
R> f <- cxxfunction(signature(), plugin="Rcpp", body='
+ throw std::range_error("boom");
+ return R_NilValue;
+ ', verbose=TRUE)
>> setting environment variables:
PKG_LIBS = -L/usr/local/lib/R/site-library/Rcpp/lib \
-lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib
>> LinkingTo : Rcpp
CLINK_CPPFLAGS = -I"/usr/local/lib/R/site-library/Rcpp/include"
>> Program source :
1 :
2 : // includes from the plugin
3 :
4 : #include <Rcpp.h>
5 :
6 :
7 : #ifndef BEGIN_RCPP
8 : #define BEGIN_RCPP
9 : #endif
10 :
11 : #ifndef END_RCPP
12 : #define END_RCPP
13 : #endif
14 :
15 : using namespace Rcpp;
16 :
17 :
18 :
19 : // user includes
20 :
21 :
22 : // declarations
23 : extern "C" {
24 : SEXP file4cc53282( ) ;
25 : }
26 :
27 : // definition
28 :
29 : SEXP file4cc53282( ){
30 : BEGIN_RCPP
31 :
32 : throw std::range_error("boom");
33 : return R_NilValue;
34 :
35 : END_RCPP
36 : }
37 :
38 :
Compilation argument:
/usr/lib/R/bin/R CMD SHLIB file4cc53282.cpp 2> file4cc53282.cpp.err.txt
ccache g++-4.6 -I/usr/share/R/include \
-I"/usr/local/lib/R/site-library/Rcpp/include" \
-fpic -g0 -O3 -Wall -pipe -Wno-unused -pedantic -c file4cc53282.cpp \
-o file4cc53282.o
g++ -shared -o file4cc53282.so file4cc53282.o \
-L/usr/local/lib/R/site-library/Rcpp/lib \
-lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib \
-L/usr/lib/R/lib -lR
R>
The BEGIN_RCPP and END_CPP add the magic you need here.
Please do move your questions to rcpp-devel.
Just wrap your code inside BEGIN_RCPP/END_RCPP:
RcppExport SEXP bar( SEXP x){
BEGIN_RCPP
throw(Rcpp::exception("My Error Message","bar.cpp",4));
return x ;
END_RCPP
}
Note that you can throw normal std exceptions too:
throw std::invalid_argument("'x' is too short");