Ignore:
Timestamp:
09/16/14 02:35:10 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d994324
Parents:
50b1bee
Message:

Refactor the combining step to allow user defined functions here.

Remove the old trace_get_results, now instead simply provide a reporter function which gets called as soon as results are ready.
The combiner function used determines the order of these results and when they are released etc.
The combiner function can be selected from those built-in or a custom version can be defined results are provided when ready.
Quickly hacked the parallel tests to work with this update, these are still a bit messy.

Also some fixes some compile warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test-format-parallel.c

    rf051c1b r2498008  
    9191}
    9292
    93 
    9493struct TLS {
    9594        bool seen_start_message;
     
    9998        int count;
    10099};
     100
     101static int totalpkts = 0;
     102static void report_result(libtrace_t *trace, libtrace_result_t *result, libtrace_message_t *mesg) {
     103        static int totalthreads = 0;
     104        if (result) {
     105                assert(libtrace_result_get_key(result) == 0);
     106                printf("%d,", (int) libtrace_result_get_value(result));
     107                totalthreads++;
     108                totalpkts += (int) libtrace_result_get_value(result);
     109        } else {
     110                switch(mesg->code) {
     111                        case MESSAGE_STARTING:
     112                                printf("\tLooks like %d threads are being used!\n\tcounts(", libtrace_get_perpkt_count(trace));
     113                                break;
     114                        case MESSAGE_STOPPING:
     115                                printf(")\n");
     116                                assert(totalthreads == libtrace_get_perpkt_count(trace));
     117                                break;
     118                }
     119        }
     120}
     121
    101122int x;
    102 
    103 static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt,
     123static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt,
    104124                                                libtrace_message_t *mesg,
    105125                                                libtrace_thread_t *t) {
     
    111131        static __thread bool seen_paused_message = false;
    112132        static __thread bool seen_pausing_message = false;
    113         static __thread count = 0;
     133        static __thread int count = 0;
    114134        tls = trace_get_tls(t);
    115135
     
    176196int main(int argc, char *argv[]) {
    177197        int error = 0;
    178         int count = 0;
    179198        int expected = 100;
    180         int i;
    181199        const char *tracename;
    182200        libtrace_t *trace;
     
    194212        if (strcmp(argv[1],"rtclient")==0) expected=101;
    195213
    196         trace_pstart(trace, NULL, per_packet, NULL);
     214        trace_pstart(trace, NULL, per_packet, report_result);
    197215        iferr(trace,tracename);
    198216
     
    205223        /* Wait for all threads to stop */
    206224        trace_join(trace);
    207         libtrace_vector_t results;
    208 
    209         /* Now lets check the results */
    210         libtrace_vector_init(&results, sizeof(libtrace_result_t));
    211         trace_get_results(trace, &results);
    212         printf("\tLooks like %d threads were used!\n\tcounts(", libtrace_vector_get_size(&results));
    213         for (i = 0; i < libtrace_vector_get_size(&results); i++) {
    214                 int ret;
    215                 libtrace_result_t result;
    216                 ret = libtrace_vector_get(&results, i, (void *) &result);
    217                 assert(ret == 1);
    218                 assert(libtrace_result_get_key(&result) == 0);
    219                 count += (int) libtrace_result_get_value(&result);
    220                 printf("%d,", (int) libtrace_result_get_value(&result));
    221         }
    222         printf(")\n");
    223         libtrace_vector_destroy(&results);
    224 
     225
     226        /* Now check we have all received all the packets */
    225227        if (error == 0) {
    226                 if (count == expected) {
     228                if (totalpkts == expected) {
    227229                        printf("success: %d packets read\n",expected);
    228230                } else {
    229                         printf("failure: %d packets expected, %d seen\n",expected,count);
     231                        printf("failure: %d packets expected, %d seen\n",expected,totalpkts);
    230232                        error = 1;
    231233                }
     
    233235                iferr(trace,tracename);
    234236        }
     237
    235238    trace_destroy(trace);
    236239    return error;
Note: See TracChangeset for help on using the changeset viewer.