-
Notifications
You must be signed in to change notification settings - Fork 0
/
nativeUtils.txt
284 lines (183 loc) · 9.95 KB
/
nativeUtils.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
https://www.geeksforgeeks.org/c-plus-plus/
-------------------------------------------
Makefile tutorail
https://makefiletutorial.com/
-------------------------------------------
counting clock cycles
https://stackoverflow.com/questions/5121442/how-to-count-cycles
https://www.geeksforgeeks.org/chrono-in-c/
https://www.tutorialspoint.com/c_standard_library/c_function_clock.htm
The C library function clock_t clock(void) returns the number of clock ticks (processor time, as the linux man)
elapsed since the program was launched. To get the number of seconds used by the
CPU, you will need to divide by CLOCKS_PER_SEC.
-------------------------------------------
Optimization flags
https://www.rapidtables.com/code/linux/gcc/gcc-o.html
https://refspecs.linuxbase.org/elf/gabi4+/ch4.intro.html
-------------------------------------------
Overloading the << operator
https://learn.microsoft.com/en-us/cpp/standard-library/overloading-the-output-operator-for-your-own-classes?view=msvc-170
-------------------------------------------
difference between include with quotes and brackets...
https://www.geeksforgeeks.org/difference-between-include-and-include-in-c-c-with-examples
-------------------------------------------
Default constructors
https://en.cppreference.com/w/cpp/language/default_constructor
-------------------------------------------
Criando bibliotecas dinâmicas
https://iq.opengenus.org/create-shared-library-in-cpp/
-------------------------------------------
Lembrar que gcc/g++ não são apenas compilers!! São linkers tbem!!!!
Quando criamos um executável, gcc/g++ está compilando E linkando...
E tbem podemos fazer apenas um ou outro (compilação e/ou linking)
"For example, the -c option says not to run the linker. Then the
output consists of object files output"
-------------------------------------------
gbscluster-5.0.0-5000.x86_64.rpm
readelf -d /path/to/library.so | grep SONAME
-------------------------------------------
Name mangling -> C++ compilers do that (changing the name of a
function to allow function overloading). But C language doesn't have function overloading.
So, to enable C++ to use C code, they are all declared in an 'extern "C"' block
https://www.geeksforgeeks.org/extern-c-in-c/
-------------------------------------------
Testes unitários
https://google.github.io/googletest/primer.html
-------------------------------------------
int myNumbers[5] = {10, 20, 30, 40, 50};
int getArrayLength = sizeof(myNumbers) / sizeof(int);
cout << getArrayLength;
-------------------------------------------
https://www.geeksforgeeks.org/multithreading-in-cpp/
detach call to leave thread on its own (do not wait for it to finish)
https://stackoverflow.com/questions/21619682/sigabrt-signal-received-when-creating-a-stdthread-c11
-------------------------------------------
copy array
https://stackoverflow.com/questions/12328301/cleanest-way-to-copy-a-constant-size-array-in-c11
-------------------------------------------
https://stackoverflow.com/questions/2692383/convert-struct-into-bytes
https://stackoverflow.com/questions/3318410/pragma-pack-effect
https://stackoverflow.com/questions/2301007/determine-word-size-of-my-processor
https://stackoverflow.com/questions/19995440/c-cast-byte-array-to-struct
-------------------------------------------
https://engineering.linkedin.com/blog/2021/taming-memory-fragmentation-in-venice-with-jemalloc
-------------------------------------------
https://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-runtime-using-c
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int tSize = 0, resident = 0, share = 0;
ifstream buffer("/proc/self/statm");
buffer >> tSize >> resident >> share;
buffer.close();
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
double rss = resident * page_size_kb;
cout << "RSS - " << rss << " kB\n";
double shared_mem = share * page_size_kb;
cout << "Shared Memory - " << shared_mem << " kB\n";
cout << "Private Memory - " << rss - shared_mem << "kB\n";
return 0;
}
-------------------------------------------
https://stackoverflow.com/questions/1246260/why-dont-c-header-files-increase-the-binarys-size
-------------------------------------------
Most Efficient ways to read a file into a std::string
https://insanecoding.blogspot.com/2011/11/how-to-read-in-file-in-c.html
-------------------------------------------
https://www.prepbytes.com/blog/linked-list/merge-two-unsorted-linked-lists-to-get-a-sorted-list/
https://stackoverflow.com/questions/1449703/how-to-append-a-listt-object-to-another
-------------------------------------------
https://unix.stackexchange.com/questions/468766/understanding-output-of-lscpu
-------------------------------------------
https://stackoverflow.com/questions/11041299/python-h-no-such-file-or-directory
./configure --prefix=/opt/python3.7 --enable-shared
make
make test
sudo make install
-------------------------------------------
TODO
lib para contagem de ciclos de clock - ok
projeto com CMake linkando libs dinamicas - ok (exemplo de linkagem da nossa lib de contagem)
testes unitarios com gtest
projeto com OATPP
-> loggers debug/info
estudar JNA
Adress Sanitizer (ASAN)
"/home/pedro.bastos/videoFacesResultTest/video_examples/teste/video_0.20_0.35.mp4"
-------------------------------------------
std::multiset
https://stackoverflow.com/questions/15582504/is-there-a-sorted-container-in-the-stl
https://en.cppreference.com/w/cpp/container/multiset
https://stackoverflow.com/questions/9167745/in-stdmultiset-is-there-a-function-or-algorithm-to-erase-just-one-sample-unic
-------------------------------------------
nunca dar throw sem tratamento dentro de uma thread separada kkk
https://stackoverflow.com/questions/45783126/exception-not-caught-if-raised-after-spawning-stdthread
-------------------------------------------
if statements with Regex - shell script
https://www.baeldung.com/linux/regex-inside-if-clause
-------------------------------------------
reading file into byte buffer
long MatcherFacade::readTemplatesFromFile2(const std::string& tptPath, char **buffer) {
FILE *fileptr;
// char *buffer;
long filelen;
fileptr = fopen(tptPath.c_str(), "rb"); // Open the file in binary mode
fseek(fileptr, 0, SEEK_END); // Jump to the end of the file
filelen = ftell(fileptr); // Get the current byte offset in the file
rewind(fileptr); // Jump back to the beginning of the file
*buffer = (char *)malloc(filelen * sizeof(char)); // Enough memory for the file
fread(*buffer, filelen, 1, fileptr); // Read in the entire file
fclose(fileptr); // Close the file
return filelen;
}
-------------------------------------------
lembrar que cada máquina tem seu clock e que isso interfere bastante quando falamos testes de performance
principalmente com gigantescas quantidades de registros.... (1e6 ++)
-------------------------------------------
GCC é mais antigo, então não tem tantas otimizações quanto compiladores mais recentes tal como o LLVM.
-> LLVM compila código C++???
-> https://clang.llvm.org/
-> https://stackoverflow.com/questions/9148488/how-do-i-compile-c-with-clang
-------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS true) -> para imprimir flags de debug em todos os objetos se colocado no CMkaeList da raiz
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O3 -DNDEBUG -s") -> colocar no CMakeList da raiz para afetar todos os objetos
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O3 -DNDEBUG -s") -> colocar no CMakeList da raiz para afetar todos os objetos
-------------------------------------------
https://www.linuxfoundation.org/blog/blog/classic-sysadmin-understanding-linux-file-permissions
-------------------------------------------
mutex IPC (interprocess comunication)
https://stackoverflow.com/questions/42628949/using-pthread-mutex-shared-between-processes-correctly
https://pubs.opengroup.org/onlinepubs/007904875/functions/shm_open.html
https://stackoverflow.com/questions/36629713/shm-unlink-from-the-shell
-------------------------------------------
o que consegui fazer dar certo!!
https://stackoverflow.com/questions/12439099/interprocess-reader-writer-lock-with-boost
-------------------------------------------
Para printar um u_int8 como um HEX
// printf("%02X ", reference[0]);
// printf("%02X ", reference[1]);
-------------------------------------------
boomm...
pq às vezes é melhor deixar alguns headers na implementação?? no .cpp...
-> pq justamente ficarão apenas na implementação
-> se alguém for usar uma lib que implementei e der um include em um .h meu não irá pegar os .h adicionados na implementação....
-------------------------------------------
Valgrind tool suite (massif and etc...)
https://valgrind.org/info/tools.html
-------------------------------------------
Para ver todas as conexões TCP abertas via websocket (both ways)
netstat -tuplna | grep 8080
Para contagem de threads de um processo
ps -o thcount 189310
-------------------------------------------
gerando bytes aleatórios
https://stackoverflow.com/questions/25298585/efficiently-generating-random-bytes-of-data-in-c11-14
-------------------------------------------
-> Olha aí a explicação do pq o calloc = 0 quando otimizados não funcionaram.....
-> https://stackoverflow.com/questions/73555398/can-i-prevent-the-gcc-optimizer-from-delaying-memory-allocation
A simple and ugly way to ensure that the memory buffer gets its hardware backing would be to find the smallest possible
page size on your architecture (which would be 4 kiB on a x86_64, for example, so 1024 of those integers (well, in most
cases)) and then touch each (possible) page of that memory beforehand, as in: for (size_t i = 0; i < 0x80000000; i += 1024) buffer[i] = 1;
That may well be the case. I believe the point was that 0 might get optimized away by the kernel by swapping the page for a shared
read-only zero page (perhaps later on), not that it must happen.