LCOV - code coverage report
Current view: top level - runtime - profiler.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 10 0.0 %
Date: 2018-01-11 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             : START OF LICENSE STUB
       3             :     DeDOS: Declarative Dispersion-Oriented Software
       4             :     Copyright (C) 2017 University of Pennsylvania, Georgetown University
       5             : 
       6             :     This program is free software: you can redistribute it and/or modify
       7             :     it under the terms of the GNU General Public License as published by
       8             :     the Free Software Foundation, either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     This program is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :     GNU General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : END OF LICENSE STUB
      19             : */
      20             : /**
      21             :  * @file profiler.c
      22             :  *
      23             :  * For profiling the path of MSU messages through DeDOS
      24             :  */
      25             : #include "profiler.h"
      26             : #include "stats.h"
      27             : #include "logging.h"
      28             : #include "rt_stats.h"
      29             : 
      30             : /** The probability that an MSU message will get marked for profiling */
      31             : static float tag_probability = -1;
      32             : 
      33             : /** The stat IDs relevant to profiling */
      34             : enum stat_id profiler_stat_ids[] = {
      35             :     PROF_ENQUEUE,
      36             :     PROF_DEQUEUE,
      37             :     PROF_REMOTE_SEND,
      38             :     PROF_REMOTE_RECV,
      39             :     PROF_DEDOS_ENTRY,
      40             :     PROF_DEDOS_EXIT
      41             : };
      42             : #define N_PROF_STAT_IDS sizeof(profiler_stat_ids) / sizeof(*profiler_stat_ids)
      43             : 
      44             : /** Sets the profiling flag on the header based on the ::tag_probability */
      45           0 : void set_profiling(struct msu_msg_hdr *hdr) {
      46             : #ifdef DEDOS_PROFILER
      47             :     float r = (float)rand() / (float)RAND_MAX;
      48             :     if (r > tag_probability) {
      49             :         hdr->do_profile = false;
      50             :         return;
      51             :     }
      52             :     hdr->do_profile = true;
      53             : #endif
      54           0 :     return;
      55             : }
      56             : 
      57             : /** Initializes the profiler to tag headers with tag_prob probability. */
      58           0 : void init_profiler(float tag_prob) {
      59           0 :     if (tag_probability != -1) {
      60           0 :         log_warn("Profiler initialized twice!");
      61             :     }
      62           0 :     tag_probability = tag_prob;
      63           0 :     srand(time(NULL));
      64             : 
      65           0 :     for (int i=0; i<N_PROF_STAT_IDS; i++) {
      66           0 :         init_stat_item(profiler_stat_ids[i], PROFILER_ITEM_ID);
      67             :     }
      68           0 : }

Generated by: LCOV version 1.10