Changeset 0f5d4de
- Timestamp:
- 01/15/19 16:46:02 (2 years ago)
- Branches:
- develop
- Children:
- edd0448
- Parents:
- be1b03a
- Location:
- examples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/parallel/network_capture.c
r10553bf r0f5d4de 21 21 #include <string.h> 22 22 23 static char *output = NULL;23 static char *outputfile = NULL; 24 24 25 25 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 26 26 static int count = 0; 27 static libtrace_t * trace = NULL;27 static libtrace_t *inptrace = NULL; 28 28 29 29 static int compress_level=-1; … … 32 32 static void stop(int signal UNUSED) 33 33 { 34 if ( trace)35 trace_pstop( trace);34 if (inptrace) 35 trace_pstop(inptrace); 36 36 } 37 37 … … 57 57 const char * first_extension = NULL; 58 58 59 file_index = strrchr(output , '/');59 file_index = strrchr(outputfile, '/'); 60 60 if (file_index) 61 61 first_extension = strchr(file_index, '.'); … … 64 64 65 65 if (first_extension) { 66 snprintf(name, sizeof(name), "%.*s-%d%s", (int) (first_extension - output ), output, my_id, first_extension);66 snprintf(name, sizeof(name), "%.*s-%d%s", (int) (first_extension - outputfile), outputfile, my_id, first_extension); 67 67 } else { 68 snprintf(name, sizeof(name), "%s-%d", output , my_id);68 snprintf(name, sizeof(name), "%s-%d", outputfile, my_id); 69 69 } 70 70 … … 232 232 return 1; 233 233 } 234 trace = trace_create(argv[optind]);235 output = argv[optind+1];236 237 if (trace_is_err( trace)) {238 trace_perror( trace,"Opening trace file");234 inptrace = trace_create(argv[optind]); 235 outputfile = argv[optind+1]; 236 237 if (trace_is_err(inptrace)) { 238 trace_perror(inptrace,"Opening trace file"); 239 239 return 1; 240 240 } … … 247 247 248 248 if (snaplen != -1) 249 trace_set_snaplen( trace, snaplen);249 trace_set_snaplen(inptrace, snaplen); 250 250 if(nb_threads != -1) 251 trace_set_perpkt_threads( trace, nb_threads);251 trace_set_perpkt_threads(inptrace, nb_threads); 252 252 253 253 /* We use a new version of trace_start(), trace_pstart() 254 254 * The reporter function argument is optional and can be NULL */ 255 if (trace_pstart( trace, NULL, processing, NULL)) {256 trace_perror( trace,"Starting trace");257 trace_destroy( trace);255 if (trace_pstart(inptrace, NULL, processing, NULL)) { 256 trace_perror(inptrace,"Starting trace"); 257 trace_destroy(inptrace); 258 258 trace_destroy_callback_set(processing); 259 259 return 1; … … 261 261 262 262 /* Wait for the trace to finish */ 263 trace_join( trace);264 265 if (trace_is_err( trace)) {266 trace_perror( trace,"Reading packets");267 trace_destroy( trace);263 trace_join(inptrace); 264 265 if (trace_is_err(inptrace)) { 266 trace_perror(inptrace,"Reading packets"); 267 trace_destroy(inptrace); 268 268 trace_destroy_callback_set(processing); 269 269 return 1; … … 271 271 272 272 /* Print stats before we destroy the trace */ 273 stats = trace_get_statistics( trace, NULL);273 stats = trace_get_statistics(inptrace, NULL); 274 274 fprintf(stderr, "Overall statistics\n"); 275 275 trace_print_statistics(stats, stderr, "\t%s: %"PRIu64"\n"); 276 276 277 277 trace_destroy_callback_set(processing); 278 trace_destroy( trace);278 trace_destroy(inptrace); 279 279 return 0; 280 280 } -
examples/skeleton/parallel.c
r389dd77 r0f5d4de 53 53 54 54 volatile int done = 0; 55 libtrace_t * trace = NULL;55 libtrace_t *inptrace = NULL; 56 56 57 57 static void cleanup_signal(int sig) { 58 58 (void)sig; /* avoid warnings about unused parameter */ 59 59 done = 1; 60 if ( trace)61 trace_pstop( trace);60 if (inptrace) 61 trace_pstop(inptrace); 62 62 } 63 63 … … 288 288 for (i = optind; i < argc; i++) { 289 289 290 trace = trace_create(argv[i]);291 292 if (trace_is_err( trace)) {293 trace_perror( trace, "Opening trace file");290 inptrace = trace_create(argv[i]); 291 292 if (trace_is_err(inptrace)) { 293 trace_perror(inptrace, "Opening trace file"); 294 294 retcode = -1; 295 295 break; 296 296 } 297 297 298 if (filter && trace_config( trace, TRACE_OPTION_FILTER, filter) == -1) {299 trace_perror( trace, "trace_config(filter)");298 if (filter && trace_config(inptrace, TRACE_OPTION_FILTER, filter) == -1) { 299 trace_perror(inptrace, "trace_config(filter)"); 300 300 retcode = -1; 301 301 break; 302 302 } 303 303 304 trace_set_perpkt_threads( trace, threads);305 trace_set_combiner( trace, &combiner_ordered,304 trace_set_perpkt_threads(inptrace, threads); 305 trace_set_combiner(inptrace, &combiner_ordered, 306 306 (libtrace_generic_t) {0}); 307 trace_set_hasher( trace, HASHER_BIDIRECTIONAL, NULL, NULL);308 309 if (trace_pstart( trace, &global, processing, reporter)) {310 trace_perror( trace, "Starting trace");307 trace_set_hasher(inptrace, HASHER_BIDIRECTIONAL, NULL, NULL); 308 309 if (trace_pstart(inptrace, &global, processing, reporter)) { 310 trace_perror(inptrace, "Starting trace"); 311 311 break; 312 312 } 313 313 314 314 /* Wait for all threads to stop */ 315 trace_join( trace);316 317 if (trace_is_err( trace)) {318 trace_perror( trace, "Processing packets");315 trace_join(inptrace); 316 317 if (trace_is_err(inptrace)) { 318 trace_perror(inptrace, "Processing packets"); 319 319 retcode = -1; 320 320 break; … … 327 327 if (filter) 328 328 trace_destroy_filter(filter); 329 trace_destroy( trace);329 trace_destroy(inptrace); 330 330 trace_destroy_callback_set(processing); 331 331 trace_destroy_callback_set(reporter);
Note: See TracChangeset
for help on using the changeset viewer.