Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:20

0001 /*
0002  * Copyright (c) 2019 Opticks Team. All Rights Reserved.
0003  *
0004  * This file is part of Opticks
0005  * (see https://bitbucket.org/simoncblyth/opticks).
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License"); 
0008  * you may not use this file except in compliance with the License.  
0009  * You may obtain a copy of the License at
0010  *
0011  *   http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software 
0014  * distributed under the License is distributed on an "AS IS" BASIS, 
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0016  * See the License for the specific language governing permissions and 
0017  * limitations under the License.
0018  */
0019 
0020 // TEST=SProcTest om-t
0021 
0022 #include <cassert>
0023 #include <iomanip>
0024 #include "SProc.hh"
0025 #include "OPTICKS_LOG.hh"
0026 
0027 
0028 void test_leaking(int argc, char** argv)
0029 {
0030     typedef unsigned long long ULL ; 
0031 
0032     //ULL MB = 1000000 ; 
0033     ULL MB = 1 << 20 ;   // 1048576  
0034 
0035     ULL MB128 = 1 << 20 << 7 ; 
0036 
0037     int nleak = argc > 1 ? atoi(argv[1]) : 25 ;   // reduced default from 100, to prevent std::bad_alloc fail at ~5GB on lxslc702
0038 
0039     char** leaks = new char*[nleak] ; 
0040 
0041     float vmb0 = SProc::VirtualMemoryUsageMB();
0042 
0043     LOG(info) 
0044         << " nleak " << nleak
0045         << " vmb0 " << vmb0 
0046         ; 
0047 
0048     ULL increment = MB128 ;  
0049 
0050     ULL total = 0ull ; 
0051 
0052     for(int i=0 ; i < nleak ; i++)
0053     {
0054         leaks[i] = new char[increment] ;
0055 
0056         total += increment ;    
0057 
0058         float dvmb = SProc::VirtualMemoryUsageMB() - vmb0 ;
0059 
0060         float x_dvmb = float(total/MB) ;  
0061 
0062         assert(leaks[i]); 
0063 
0064         LOG(info) 
0065               << std::setw(10) << i 
0066               << " vm " 
0067               << std::setw(10) << dvmb 
0068               << " x_vm " 
0069               << std::setw(10) << x_dvmb 
0070               << " vm/x_vm " 
0071               << std::setw(10) << std::fixed << std::setprecision(4) << dvmb/x_dvmb 
0072  
0073               ;
0074 
0075         //delete [] leaks[i] ; 
0076     } 
0077 }
0078 
0079 
0080 
0081 void test_ExecutablePath(int argc, char** argv)
0082 {
0083     const char* p = SProc::ExecutablePath();
0084     std::cout << "argv[0]:                 " << argv[0] << std::endl ;  
0085     std::cout << "SProc::ExecutablePath(): " << p << std::endl ;  
0086 
0087     const char* n = SProc::ExecutableName();
0088     std::cout << "SProc::ExecutableName(): " << n << std::endl ;  
0089 
0090     const char* l4 = strdup( n + strlen(n) - 4 ); 
0091     std::cout << " l4 [" << l4 << "]" << std::endl ; 
0092     assert( strlen(n) > 4 && strncmp( n + strlen(n) - 4 ,  "Test", 4) == 0 );  
0093 }
0094 
0095 
0096 
0097 int main(int argc, char** argv)
0098 {
0099     OPTICKS_LOG(argc, argv);
0100 
0101     test_leaking(argc, argv); 
0102     //test_ExecutablePath(argc, argv); 
0103 
0104     return 0 ; 
0105 }
0106 
0107 /*
0108 When skipping the delete the VM grows linearly at close to expected 100 MB for each loop::
0109 
0110     simon:sysrap blyth$ SProcTest 
0111     2016-09-14 20:31:57.967 INFO  [310051] [main@25]          0 vm        100
0112     2016-09-14 20:31:57.968 INFO  [310051] [main@25]          1 vm        209
0113     2016-09-14 20:31:57.968 INFO  [310051] [main@25]          2 vm        309
0114     ...
0115     2016-09-14 20:31:57.970 INFO  [310051] [main@25]         97 vm       9810
0116     2016-09-14 20:31:57.970 INFO  [310051] [main@25]         98 vm       9910
0117     2016-09-14 20:31:57.970 INFO  [310051] [main@25]         99 vm      10010
0118 
0119 
0120 Bad alloc on lxslc702.ihep.ac.cn when get to 50th, ie 5000MB::
0121 
0122     2019-04-28 19:14:09.130 INFO  [17056] [main@27]         47 vm          0
0123     2019-04-28 19:14:09.130 INFO  [17056] [main@27]         48 vm          0
0124     2019-04-28 19:14:09.130 INFO  [17056] [main@27]         49 vm          0
0125     terminate called after throwing an instance of 'std::bad_alloc'
0126       what():  std::bad_alloc
0127     Aborted (core dumped)
0128 
0129 
0130 
0131 
0132 */