"Fossies" - the Fresh Open Source Software Archive

Member "ftwin-master/src/debug.h" (15 Feb 2015, 2100 Bytes) of package /linux/privat/ftwin-master.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2007 Fran├žois Pesce : francois.pesce (at) gmail (dot) com
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  * 
    8  *  http://www.apache.org/licenses/LICENSE-2.0
    9  * 
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 #ifndef DEBUG_H
   18 #define DEBUG_H
   19 /**
   20  * @file debug.h
   21  * @brief UTIL debug output macros
   22  */
   23 
   24 #include <stdio.h>
   25 
   26 /**
   27  * Display error message at the level error.
   28  * @param str The format of the string.
   29  * @param arg The arguments to use while printing the data.
   30  */
   31 #define DEBUG_ERR(str, arg...) fprintf(stderr, "[DEBUG_ERR]: [%s] " str " at line %d\n", __FUNCTION__, ## arg, __LINE__), fflush(stderr)
   32 
   33 /**
   34  * Display error message at the level debug.
   35  * @param str The format of the string.
   36  * @param arg The arguments to use while printing the data.
   37  */
   38 #define DEBUG_DBG(str, arg...) fprintf(stderr, "[DEBUG_DBG]: [%s] " str " at line %d\n", __FUNCTION__, ## arg, __LINE__), fflush(stderr)
   39 
   40 #include <sys/time.h>
   41 #include <sys/resource.h>
   42 
   43 #define GET_MEMUSAGE(size)                      \
   44 {                                   \
   45     FILE *statm=fopen("/proc/self/statm", "r");             \
   46     if (statm) {                            \
   47     if (1 != fscanf(statm, "%lu",&size)) {              \
   48         DEBUG_ERR("Can't fscan proc self statm");           \
   49     }                               \
   50     if (fclose(statm)) {                        \
   51         DEBUG_ERR("Can't close proc self statm");           \
   52     }                               \
   53     } else {                                \
   54     DEBUG_ERR("Can't open proc self statm");            \
   55     }                                   \
   56 }
   57 
   58 #define DISPLAY_MEMLEAK_open()                      \
   59 {                                   \
   60     unsigned long int size1, size2;                 \
   61     GET_MEMUSAGE(size1);
   62 
   63 #define DISPLAY_MEMLEAK_close()         \
   64     GET_MEMUSAGE(size2);                \
   65     if(size2 != size1)                  \
   66         DEBUG_ERR("Delta memory %lu", size2 - size1);   \
   67 }
   68 
   69 /** @} */
   70 
   71 #endif /* DEBUG_H */