<commit_before>/****************** <VPR heading BEGIN do not edit this line> *****************
 *
 * VR Juggler Portable Runtime
 *
 * Original Authors:
 *   <NAME>, <NAME>, <NAME>, <NAME>
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 ****************** <VPR heading END do not edit this line> ******************/

/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2002 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vpr/vprConfig.h>

#include <vpr/Sync/Mutex.h>
#include <vpr/Thread/Thread.h>
#include <vpr/Thread/TSObjectProxy.h>
#include <vpr/Util/StreamLock.h>
#include <vpr/Util/Debug.h>


namespace vpr {

/*
Debug* Debug::_instance = NULL;
Mutex  Debug::_inst_lock;
*/

// Some thread specific global variables
// They are globals because I can't include their type in the vjDEBUG header file
// If I did, then we could not output debug info in the Thread manager itself
TSObjectProxy<std::vector<int> > gVprDebugCurColumn;       // What column to indent to
TSObjectProxy<std::vector<std::string> > gVprDebugCurColor;        // What color to display "everything" in

// Register DEBUG categories
/*

NOTE: These primitive types are instead registered by the constructor (Debug::Debug) directly
as to avoid any initialization order dependencies.

vprREGISTER_DBG_CATEGORY(vprDBG_ALL, DBG_ALL, "DBG:");
vprREGISTER_DBG_CATEGORY(vprDBG_ERROR, DBG_ERROR, "ERR:");
vprREGISTER_DBG_CATEGORY(vprDBG_SIM, DBG_SIM, "I'm a little simulator:");
vprREGISTER_DBG_CATEGORY(vprDBG_VPR, DBG_VPR, "VPR:");
*/


vprSingletonImpWithInitFunc(Debug, init);

Debug::Debug()
{
   indentLevel = 0;     // Initialy don't indent
   debugLevel = 1;      // Should actually try to read env variable
   mUseThreadLocal = false;   // Initially set to false

   char* debug_lev = getenv("VPR_DEBUG_NFY_LEVEL");
   if(debug_lev != NULL)
   {
      debugLevel = atoi(debug_lev);
      std::cout << "VPR_DEBUG_NFY_LEVEL: Set to " << debugLevel << std::endl
                << std::flush;
   } else {
      std::cout << "VPR_DEBUG_NFY_LEVEL: Not found. " << std::endl
                << std::flush;
      std::cout << "VPR_DEBUG_NFY_LEVEL: Defaults to " << debugLevel
                << std::endl << std::flush;
   }

   char* debug_enable = getenv("VPR_DEBUG_ENABLE");
   if(debug_enable != NULL)
   {
      unsigned debug_enable_val = atoi(debug_enable);
      if(debug_enable_val)
         mDebugEnabled = true;
      else
         mDebugEnabled = false;
      std::cout << "VPR_DEBUG_ENABLE: Set to " << mDebugEnabled << std::endl
                << std::flush;
   } else {
      mDebugEnabled = true;
      std::cout << "VPR_DEBUG_ENABLE: Not found. " << std::endl
                << std::flush;
      std::cout << "VPR_DEBUG_ENABLE: Defaults to " << mDebugEnabled
                << std::endl << std::flush;
   }   
}

void Debug::init()
{
   // --- Register primitive categories --- //
   /*
   addCategory(vprDBG_ALL, "DBG_ALL", "DBG:");
   addCategory(vprDBG_ERROR, "DBG_ERROR", "ERR:");
   addCategory(vprDBG_SIM, "DBG_SIM", "I'm a little simulator:");
   addCategory(vprDBG_VPR, "DBG_VPR", "VPR:");
   */
}

std::ostream& Debug::getStream(const vpr::DebugCategory& cat, const int level, const bool show_thread_info,
                               const bool use_indent, const int indentChange,
                               const bool lockStream)
{
   if(indentChange < 0)                // If decreasing indent
      indentLevel += indentChange;

   vprASSERT(indentLevel >= 0 && "Decreased indent below 0, look for bad code");   

   // Lock the stream
#ifdef LOCK_DEBUG_STREAM
   if(lockStream)
   {
      debugLock().acquire();     // Get the lock
   }
#endif

   // --- Create stream header --- //
   // If we have thread local stuff to do
   if(mUseThreadLocal)
   {
      if((*gVprDebugCurColor).size() == 0)
         std::cout << clrRESET;
      else
         std::cout << clrSetBOLD((*gVprDebugCurColor).back());
   }

   // Autoregister
   if(mCategories.find(cat.mGuid) == mCategories.end())
   {
      addCategory(cat);
   }

   vprASSERT(mCategories.find(cat.mGuid) != mCategories.end() && "Failed to auto-register");

   // Ouput thread info
   // If not, then output space if we are also using indent (assume this means
   // new line used)
   if(show_thread_info)
      std::cout << "[" << vpr::Thread::self() << "] " << (*mCategories.find(cat.mGuid)).second.mPrefix;
   else if(use_indent)
      std::cout << "                  ";


      // Insert the correct number of tabs into the stream for indenting
   if(use_indent)
   {
      for(int i=0;i<indentLevel;i++)
      {
         std::cout << "\t";
      }

      ///* For debugging indentation
      // Output the indent level that we are going to of coming from
      if(getLevel() >= 3)
      {
         if(indentChange >0)  // Not incremented yet
         {
            std::cout << " ind-";
            for(int i=0;i<indentLevel+indentChange;++i)
            {
               std::cout << indentLevel+indentChange << "-";
            }
            std::cout << "> ";
         }
         else if(indentChange < 0) // Already decremented
         {
            std::cout << " ind-";
            for(int i=0;i<indentLevel-indentChange;++i)
            {
               std::cout << indentLevel-indentChange << "-";
            }
            std::cout << "< ";
         }
      }
      //*/
   }
<commit_msg>Up the level used before indent debugging<commit_after>/****************** <VPR heading BEGIN do not edit this line> *****************
 *
 * VR Juggler Portable Runtime
 *
 * Original Authors:
 *   <NAME>, <NAME>, <NAME>, <NAME>
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 ****************** <VPR heading END do not edit this line> ******************/

/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2002 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>ling, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

#include <vpr/vprConfig.h>

#include <vpr/Sync/Mutex.h>
#include <vpr/Thread/Thread.h>
#include <vpr/Thread/TSObjectProxy.h>
#include <vpr/Util/StreamLock.h>
#include <vpr/Util/Debug.h>


namespace vpr {

/*
Debug* Debug::_instance = NULL;
Mutex  Debug::_inst_lock;
*/

// Some thread specific global variables
// They are globals because I can't include their type in the vjDEBUG header file
// If I did, then we could not output debug info in the Thread manager itself
TSObjectProxy<std::vector<int> > gVprDebugCurColumn;       // What column to indent to
TSObjectProxy<std::vector<std::string> > gVprDebugCurColor;        // What color to display "everything" in

// Register DEBUG categories
/*

NOTE: These primitive types are instead registered by the constructor (Debug::Debug) directly
as to avoid any initialization order dependencies.

vprREGISTER_DBG_CATEGORY(vprDBG_ALL, DBG_ALL, "DBG:");
vprREGISTER_DBG_CATEGORY(vprDBG_ERROR, DBG_ERROR, "ERR:");
vprREGISTER_DBG_CATEGORY(vprDBG_SIM, DBG_SIM, "I'm a little simulator:");
vprREGISTER_DBG_CATEGORY(vprDBG_VPR, DBG_VPR, "VPR:");
*/


vprSingletonImpWithInitFunc(Debug, init);

Debug::Debug()
{
   indentLevel = 0;     // Initialy don't indent
   debugLevel = 1;      // Should actually try to read env variable
   mUseThreadLocal = false;   // Initially set to false

   char* debug_lev = getenv("VPR_DEBUG_NFY_LEVEL");
   if(debug_lev != NULL)
   {
      debugLevel = atoi(debug_lev);
      std::cout << "VPR_DEBUG_NFY_LEVEL: Set to " << debugLevel << std::endl
                << std::flush;
   } else {
      std::cout << "VPR_DEBUG_NFY_LEVEL: Not found. " << std::endl
                << std::flush;
      std::cout << "VPR_DEBUG_NFY_LEVEL: Defaults to " << debugLevel
                << std::endl << std::flush;
   }

   char* debug_enable = getenv("VPR_DEBUG_ENABLE");
   if(debug_enable != NULL)
   {
      unsigned debug_enable_val = atoi(debug_enable);
      if(debug_enable_val)
         mDebugEnabled = true;
      else
         mDebugEnabled = false;
      std::cout << "VPR_DEBUG_ENABLE: Set to " << mDebugEnabled << std::endl
                << std::flush;
   } else {
      mDebugEnabled = true;
      std::cout << "VPR_DEBUG_ENABLE: Not found. " << std::endl
                << std::flush;
      std::cout << "VPR_DEBUG_ENABLE: Defaults to " << mDebugEnabled
                << std::endl << std::flush;
   }   
}

void Debug::init()
{
   // --- Register primitive categories --- //
   /*
   addCategory(vprDBG_ALL, "DBG_ALL", "DBG:");
   addCategory(vprDBG_ERROR, "DBG_ERROR", "ERR:");
   addCategory(vprDBG_SIM, "DBG_SIM", "I'm a little simulator:");
   addCategory(vprDBG_VPR, "DBG_VPR", "VPR:");
   */
}

std::ostream& Debug::getStream(const vpr::DebugCategory& cat, const int level, const bool show_thread_info,
                               const bool use_indent, const int indentChange,
                               const bool lockStream)
{
   if(indentChange < 0)                // If decreasing indent
      indentLevel += indentChange;

   vprASSERT(indentLevel >= 0 && "Decreased indent below 0, look for bad code");   

   // Lock the stream
#ifdef LOCK_DEBUG_STREAM
   if(lockStream)
   {
      debugLock().acquire();     // Get the lock
   }
#endif

   // --- Create stream header --- //
   // If we have thread local stuff to do
   if(mUseThreadLocal)
   {
      if((*gVprDebugCurColor).size() == 0)
         std::cout << clrRESET;
      else
         std::cout << clrSetBOLD((*gVprDebugCurColor).back());
   }

   // Autoregister
   if(mCategories.find(cat.mGuid) == mCategories.end())
   {
      addCategory(cat);
   }

   vprASSERT(mCategories.find(cat.mGuid) != mCategories.end() && "Failed to auto-register");

   // Ouput thread info
   // If not, then output space if we are also using indent (assume this means
   // new line used)
   if(show_thread_info)
      std::cout << "[" << vpr::Thread::self() << "] " << (*mCategories.find(cat.mGuid)).second.mPrefix;
   else if(use_indent)
      std::cout << "                  ";


      // Insert the correct number of tabs into the stream for indenting
   if(use_indent)
   {
      for(int i=0;i<indentLevel;i++)
      {
         std::cout << "\t";
      }

      ///* For debugging indentation
      // Output the indent level that we are going to of coming from
      if(getLevel() >= 7)
      {
         if(indentChange >0)  // Not incremented yet
         {
            std::cout << " ind-";
            for(int i=0;i<indentLevel+indentChange;++i)
            {
               std::cout << indentLevel+indentChange << "-";
            }
            std::cout << "> ";
         }
         else if(indentChange < 0) // Already decremented
         {
            std::cout << " ind-";
            for(int i=0;i<indentLevel-indentChange;++i)
            {
               std::cout << indentLevel-indentChange << "-";
            }
            std::cout << "< ";
         }
      }
      //*/
   }

{'fraction_non_alphanumeric': 0.1607717041800643, 'fraction_numerical': 0.0053590568060021436, 'mean_word_length': 2.4751263633945197, 'pattern_counts': {'":': 0, '<': 215, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865817', 'n_tokens_mistral': 4048, 'n_tokens_neox': 3914, 'n_words': 1114}