Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

platfDepend.cxx File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "infolines.h"
#include "abktypes.h"
#include "abkassert.h"

Include dependency graph for platfDepend.cxx:

Include dependency graph

Go to the source code of this file.

Functions

void abk_dump_stack ()
void abk_call_debugger ()
double getPeakMemoryUsage ()
double getMemoryUsageEstimate ()
int gethostname (char *, int)
int memused ()

Variables

const int kMegaByte = 1024*1024
const int kSmallChunks = 1000
const int kMaxAllocs = 20000
const double MemUsageEps = 3


Function Documentation

void abk_call_debugger  ) 
 

Definition at line 124 of file platfDepend.cxx.

00125 {
00126 #if defined(linux) || defined(sun) || defined(__SUNPRO_CC)
00127     unsigned ProcId=getpid();
00128     printf("\n  --- ATTACHING DEBUGGER to process %d ", ProcId);
00129     printf(" (an ABKGROUP utility) --- \n\n");
00130     fflush(stdout);
00131     char s[160];
00132  #if defined(linux)
00133     sprintf(s, "gdb -q /proc/%d/exe %d", ProcId,ProcId);
00134  #else // must be Solaris
00135     sprintf(s, "dbx - %d", ProcId);
00136  #endif
00137     system(s);
00138     printf("  ------------------ CONTINUING -------------- \n");
00139     fflush(stdout);
00140 #else
00141  fprintf(stderr," abk_call_debugger(): Can't call debugger on this platform\n");
00142  fflush(stderr);
00143 #endif
00144     return;
00145 }

void abk_dump_stack  ) 
 

Definition at line 100 of file platfDepend.cxx.

00101 {
00102     return;
00103 #if defined(linux) || defined(sun) || defined(__SUNPRO_CC)
00104     printf("\n  --- ABK GROUP DELIBERATE STACK DUMP  ----------- \n\n");
00105     fflush(stdout);
00106     char s[160];
00107     unsigned ProcId=getpid();
00108  #if defined(linux)
00109     sprintf(s, "/bin/echo \"bt   \nquit   \\n\" | "
00110                "gdb -q /proc/%d/exe %d", ProcId,ProcId);
00111  #else
00112     sprintf(s, "/bin/echo \"where\\ndetach \\n\" | dbx - %d", ProcId);
00113  #endif
00114     system(s);
00115     printf("  ------------------ END STACK DUMP -------------- \n");
00116     fflush(stdout);
00117 #else
00118 // fprintf(stderr," abk_dump_stack(): Can't dump stack on this platform\n");
00119 // fflush(stderr);
00120 #endif
00121     return;
00122 }

int gethostname char *  ,
int 
 

Referenced by User::User().

double getMemoryUsageEstimate  )  [static]
 

Definition at line 282 of file platfDepend.cxx.

References abkwarn, kMaxAllocs, kMegaByte, kSmallChunks, MemUsageEps, and memused().

Referenced by MemUsage::MemUsage(), and MemChange::resetMark().

00283 {
00284 #if ! (defined(linux) || defined(sun) || defined(__SUNPRO_CC))
00285         return -1;
00286 #endif
00287         static int prevMem=0;
00288         static int extra;
00289         static int fail=0;
00290 
00291         if (fail) return -1;
00292 
00293 //      new_handler oldHndl;
00294 //      oldHndl=set_new_handler(mH);
00295 
00296         void* ptr[kMaxAllocs];
00297         int numAllocs=0;
00298 
00299         int last=memused();
00300 //       cout << "Memused : " << last << endl;
00301         if (last<=0) return -1;
00302 //      cerr<<"memused()="<<memused()<<endl;
00303         int chunk=8192; // system allocates 8K chunks
00304         int allocated=0;
00305         int countSmallChunks=kSmallChunks;
00306         // if we allocate <8K, we'd get memused()+=8K, and allocated<8K - error
00307         while (1)
00308         {
00309 //              abkfatal(numAllocs<kMaxAllocs, "too many allocs");
00310                 if (numAllocs>=kMaxAllocs) 
00311                 {   
00312                    abkwarn(0,"too many allocs (may be okay for 64-bit builds)");
00313                    // FIFO destruction
00314                    for (int i=0; i!=numAllocs; ++i) free(ptr[i]);
00315                     return -1.0;     
00316                 }
00317 //              cerr<<"old: "<<memused()<<"; allocating "<<chunk<<"; now: ";
00318                 if (!(ptr[numAllocs++]=malloc(chunk)))
00319                 {
00320                         fail=1;
00321                         return -1;
00322                 }
00323 //              cerr<<memused()<<endl;
00324                 allocated+=chunk;
00325                 if (memused()>last+MemUsageEps)
00326                         break;
00327                 if (chunk<=kMegaByte && !countSmallChunks--)
00328                 {
00329                                 chunk*=2;
00330                                 countSmallChunks=kSmallChunks;
00331                 }
00332         }
00333 
00334 //     int result=memused()-allocated-prevMem;
00335 
00336 /* LIFO destruction
00337         while (numAllocs) free(ptr[--numAllocs]); */
00338 
00339         // FIFO destruction
00340         for (int i=0; i!=numAllocs; ++i) free(ptr[i]);
00341 
00342         extra=memused()-last;
00343 // handle extra correctly:
00344 // in some cases we need to add its prev value to current,
00345 // in some just store the new value
00346 
00347         prevMem=memused()-allocated;
00348 //      set_new_handler(oldHndl);
00349         return prevMem/double(kMegaByte);
00350 }

Here is the call graph for this function:

double getPeakMemoryUsage  ) 
 

Definition at line 147 of file platfDepend.cxx.

Referenced by MemUsage::MemUsage(), memused(), and MemChange::operator double().

00148 {
00149 
00150 #if ! (defined(sun) || defined(linux) || defined(__SUNPRO_CC))
00151   return -1;
00152 #endif
00153 
00154 #if defined(sun) || defined(__SUNPRO_CC)
00155   char procFileName[20];
00156   unsigned pid=getpid();
00157   sprintf(procFileName,"/proc/%d/as",pid);
00158   struct stat buf;
00159   if (stat(procFileName,&buf))  // no such file on Solaris 2.5 and earlier
00160   {                             // so we stat another file now
00161     char procFileNameOld[20];
00162     sprintf(procFileNameOld,"/proc/%d",pid);
00163     if (stat(procFileNameOld,&buf)) 
00164         return -1.0;
00165   }
00166   return (1.0/(1024*1024)) * buf.st_size;
00167 #elif defined(linux)
00168   char buf[1000];
00169   sprintf(buf,"/proc/%d/stat", static_cast<unsigned>(getpid()));
00170   ifstream ifs(buf);
00171   for(unsigned k=0; k!=23; k++) ifs >> buf;
00172       //  cout << k << ": " << buf << endl; }
00173   return (1.0/(1024*1024)) * atoi(buf);
00174 #else
00175   return -1;
00176 #endif
00177 }

int memused  )  [inline]
 

Definition at line 276 of file platfDepend.cxx.

References getPeakMemoryUsage(), and kMegaByte.

Referenced by getMemoryUsageEstimate().

00277 {
00278 // cout << " Peak memory " << getPeakMemoryUsage() << endl;
00279    return static_cast<int>(getPeakMemoryUsage()*kMegaByte);
00280 }

Here is the call graph for this function:


Variable Documentation

const int kMaxAllocs = 20000
 

Definition at line 271 of file platfDepend.cxx.

Referenced by getMemoryUsageEstimate().

const int kMegaByte = 1024*1024
 

Definition at line 269 of file platfDepend.cxx.

Referenced by getMemoryUsageEstimate(), and memused().

const int kSmallChunks = 1000
 

Definition at line 270 of file platfDepend.cxx.

Referenced by getMemoryUsageEstimate().

const double MemUsageEps = 3
 

Definition at line 272 of file platfDepend.cxx.

Referenced by getMemoryUsageEstimate().


Generated on Mon Apr 25 01:12:10 2005 for Parquete by doxygen 1.3.2