| | 281 | inline static void |
| | 282 | log_upload_chunk_mincore(Chunk* chunk, const Piece& piece, bool new_index) { |
| | 283 | #ifdef LT_LOG_MINCORE_FILE |
| | 284 | static int mincore_fd = -1; |
| | 285 | static int32_t ticker = rak::timer::current().seconds() / 10 * 10; |
| | 286 | |
| | 287 | static int counter_incore = 0; |
| | 288 | static int counter_not_incore = 0; |
| | 289 | static int counter_incore_new = 0; |
| | 290 | static int counter_not_incore_new = 0; |
| | 291 | |
| | 292 | if (rak::timer::current().seconds() >= ticker + 10) { |
| | 293 | char buffer[256]; |
| | 294 | |
| | 295 | if (mincore_fd == -1) { |
| | 296 | snprintf(buffer, 256, "%s.%u", LT_LOG_MINCORE_FILE, getpid()); |
| | 297 | |
| | 298 | if ((mincore_fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC)) == -1) |
| | 299 | throw internal_error("Could not open mincore log file."); |
| | 300 | } |
| | 301 | |
| | 302 | // Log the result of mincore for every piece uploaded to a file. |
| | 303 | unsigned int buf_lenght = snprintf(buffer, 256, "%i %u %u %u %u\n", |
| | 304 | ticker, counter_incore, counter_incore_new, counter_not_incore, counter_not_incore_new); |
| | 305 | |
| | 306 | write(mincore_fd, buffer, buf_lenght); |
| | 307 | |
| | 308 | ticker = rak::timer::current().seconds() / 10 * 10; |
| | 309 | |
| | 310 | counter_incore = 0; |
| | 311 | counter_not_incore = 0; |
| | 312 | counter_incore_new = 0; |
| | 313 | counter_not_incore_new = 0; |
| | 314 | } |
| | 315 | |
| | 316 | bool is_incore = (chunk->incore_length(piece.offset(), piece.length()) == piece.length()); |
| | 317 | |
| | 318 | counter_incore += !new_index && is_incore; |
| | 319 | counter_incore_new += new_index && is_incore; |
| | 320 | counter_not_incore += !new_index && !is_incore; |
| | 321 | counter_not_incore_new += new_index && !is_incore; |
| | 322 | #endif |
| | 323 | } |
| | 324 | |