LCOV - code coverage report
Current view: top level - test/core/profiling - timers_test.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 27 27 100.0 %
Date: 2015-10-10 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #include "src/core/profiling/timers.h"
      35             : #include <stdlib.h>
      36             : #include "test/core/util/test_config.h"
      37             : 
      38           1 : void test_log_events(size_t num_seqs) {
      39           1 :   size_t start = 0;
      40             :   size_t *state;
      41           1 :   state = calloc(num_seqs, sizeof(state[0]));
      42     1462075 :   while (start < num_seqs) {
      43             :     size_t i;
      44             :     size_t row;
      45     1462073 :     if (state[start] == 3) { /* Already done with this posn */
      46     1000000 :       start++;
      47     1000000 :       continue;
      48             :     }
      49             : 
      50      462073 :     row = (size_t)rand() % 10; /* how many in a row */
      51     2543054 :     for (i = start; (i < start + row) && (i < num_seqs); i++) {
      52             :       size_t j;
      53     2080981 :       size_t advance = 1 + (size_t)rand() % 3; /* how many to advance by */
      54     6244939 :       for (j = 0; j < advance; j++) {
      55     4163958 :         switch (state[i]) {
      56             :           case 0:
      57             :             GRPC_TIMER_MARK(STATE_0, i);
      58     1000000 :             state[i]++;
      59     1000000 :             break;
      60             :           case 1:
      61             :             GRPC_TIMER_MARK(STATE_1, i);
      62     1000000 :             state[i]++;
      63     1000000 :             break;
      64             :           case 2:
      65             :             GRPC_TIMER_MARK(STATE_2, i);
      66     1000000 :             state[i]++;
      67     1000000 :             break;
      68             :           case 3:
      69     1163958 :             break;
      70             :         }
      71             :       }
      72             :     }
      73             :   }
      74           1 :   free(state);
      75           1 : }
      76             : 
      77           1 : int main(int argc, char **argv) {
      78           1 :   grpc_test_init(argc, argv);
      79           1 :   grpc_timers_global_init();
      80           1 :   test_log_events(1000000);
      81           1 :   grpc_timers_global_destroy();
      82           1 :   return 0;
      83             : }

Generated by: LCOV version 1.10