Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // ~/opticks/sysrap/tests/NP_delete_test.sh
0002 
0003 #include "sprof.h"
0004 #include "sstr.h"
0005 #include "sstamp.h"
0006 
0007 #include "NPFold.h"
0008 
0009 struct NP_delete_test
0010 {
0011     static constexpr const int M = 1000000 ; 
0012     static constexpr const int K = 1000 ; 
0013 
0014     static void t0(); 
0015     static void t1(); 
0016     static void t2(); 
0017 
0018     static void main(); 
0019 };
0020 
0021 
0022 /**
0023 NP_delete_test::t0
0024 ---------------------
0025 
0026 Looks like no cleanup ...
0027 
0028 NP::descSize arr_bytes 64000000 arr_kb 64000
0029 398833,73441,64095
0030 279619,0,8
0031 
0032 WHAT TO LEARN FROM THIS : DONT TRY CHECKING 
0033 CLEANUP OF A SINGLE ACTION, THERES LOTS OF 
0034 RUNTIME "PEDESTAL" TOO.  INSTEAD : DO THINGS 
0035 IN A LOOP AND LOOK FOR VARIATIONS, SEE BELOW. 
0036 
0037 **/
0038 
0039 void NP_delete_test::t0()
0040 {
0041     sprof p0, p1, p2 ; 
0042 
0043     sprof::Stamp(p0);  
0044 
0045     NP* a = NP::Make<float>( 1*M, 4, 4 ) ; 
0046     std::cout << a->descSize() << std::endl ; 
0047 
0048     sprof::Stamp(p1);  
0049 
0050     //a->clear() ; 
0051 
0052     a->data.clear() ; 
0053     a->data.shrink_to_fit();
0054     //delete a ; 
0055     //a = nullptr ; 
0056 
0057     sprof::Stamp(p2);  
0058 
0059     std::cout << sprof::Desc(p0,p1) << std::endl ;  
0060     std::cout << sprof::Desc(p1,p2) << std::endl ;  
0061 }
0062 
0063 
0064 /**
0065 NP_delete_test::t1
0066 --------------------
0067 
0068 Without the delete the RSS keeps sloping upwards, with it it stays flat. 
0069 
0070 YES: but using the same size every time is disceptive, that makes it 
0071 easy for the system to allocate after the delete 
0072 
0073 **/
0074 
0075 void NP_delete_test::t1()
0076 {
0077     const char* NumPhotonSpec = "M1,1,1,1,1" ; 
0078     std::vector<int>* nums = sstr::ParseIntSpecList<int>( NumPhotonSpec, ',' ) ; 
0079     int num_event = nums ? nums->size() : 0 ; 
0080 
0081     NP* run = NP::Make<int>(num_event); 
0082     int* rr = run->values<int>(); 
0083 
0084     run->set_meta<std::string>("TEST", "t1") ; 
0085 
0086     bool CLEAR = getenv("CLEAR") != nullptr ; 
0087     bool DELETE = getenv("DELETE") != nullptr ; 
0088     run->set_meta<std::string>("CLEAR", CLEAR ? "YES" : "NO" ) ; 
0089     run->set_meta<std::string>("DELETE", DELETE ? "YES" : "NO" ) ; 
0090 
0091 
0092     for(int idx=0 ; idx < 10 ; idx++)
0093     {
0094         std::string head = U::FormName_("head_", idx, nullptr, 3 ) ; 
0095         run->set_meta<std::string>(head.c_str(), sprof::Now() ); 
0096 
0097         int num = (*nums)[idx] ; 
0098         rr[idx] = num ;  
0099 
0100         NP* a = NP::Make<float>( num, 4, 4 ) ; 
0101 
0102         std::string body = U::FormName_("body_", idx, nullptr, 3 ) ; 
0103         run->set_meta<std::string>(body.c_str(), sprof::Now() ); 
0104  
0105         if(CLEAR) a->clear() ;     
0106         if(DELETE) delete a ; 
0107 
0108         std::string tail = U::FormName_("tail_", idx, nullptr, 3 ) ; 
0109         run->set_meta<std::string>(tail.c_str(), sprof::Now() ); 
0110 
0111         sstamp::sleep_us(100000); 
0112     }
0113 
0114     NPFold* fold = new NPFold ;  
0115     fold->add( "run", run ); 
0116     fold->add( "runprof", run->makeMetaKVProfileArray() ); 
0117     fold->save("$FOLD"); 
0118 }
0119 
0120 
0121 
0122 
0123 /**
0124 NP_delete_test::t2
0125 --------------------
0126 
0127 Varying the sizes gives a much less flat RSS, but still 
0128 not deleting allows it to grow it seems that when deleting 
0129 are left with the largest size allocation. 
0130 
0131 ::
0132 
0133     In [5]: f.run*16*4/1e9   ## estmating GB for  "M1,2,3,1,2,3"
0134     Out[5]: array([0.064, 0.128, 0.192, 0.064, 0.128, 0.192])
0135 
0136 
0137 **/
0138 
0139 void NP_delete_test::t2()
0140 {
0141     //const char* NumPhotonSpec = "H1,2,4,8,16" ; 
0142     const char* NumPhotonSpec = "M1,2,3,4,3,2,1" ; 
0143     std::vector<int>* nums = sstr::ParseIntSpecList<int>( NumPhotonSpec, ',' ) ; 
0144     
0145     int num_event = nums ? nums->size() : 0 ; 
0146 
0147     NP* run = NP::Make<int>(num_event); 
0148     int* rr = run->values<int>(); 
0149 
0150     run->set_meta<std::string>("TEST", "t2" ) ; 
0151 
0152     bool CLEAR = getenv("CLEAR") != nullptr ; 
0153     bool DELETE = getenv("DELETE") != nullptr ; 
0154     run->set_meta<std::string>("CLEAR", CLEAR ? "YES" : "NO" ) ; 
0155     run->set_meta<std::string>("DELETE", DELETE ? "YES" : "NO" ) ; 
0156 
0157 
0158     for(int idx=0 ; idx < num_event  ; idx++)
0159     {
0160         int num = (*nums)[idx] ; 
0161         rr[idx] = num ;  
0162         std::cout << std::setw(4) << idx << " : " << num << std::endl ; 
0163 
0164         std::string head = U::FormName_("head_", idx, nullptr, 3 ) ; 
0165         sstamp::sleep_us(100000); 
0166         run->set_meta<std::string>(head.c_str(), sprof::Now() ); 
0167 
0168         NP* a = NP::Make<float>( num, 4, 4 ) ; 
0169 
0170 
0171         std::string body = U::FormName_("body_", idx, nullptr, 3 ) ; 
0172         sstamp::sleep_us(100000); 
0173         run->set_meta<std::string>(body.c_str(), sprof::Now() ); 
0174 
0175         if(CLEAR) a->clear() ;     
0176         if(DELETE) delete a ; 
0177 
0178 
0179         std::string tail = U::FormName_("tail_", idx, nullptr, 3 ) ; 
0180         sstamp::sleep_us(100000); 
0181         run->set_meta<std::string>(tail.c_str(), sprof::Now() ); 
0182     }
0183 
0184     NPFold* fold = new NPFold ;  
0185     fold->add( "run", run ); 
0186     fold->add( "runprof", run->makeMetaKVProfileArray() ); 
0187     fold->save("$FOLD"); 
0188 
0189 }
0190 
0191 
0192 
0193 
0194 
0195 void NP_delete_test::main()
0196 {
0197     char* TEST = getenv("TEST") ; 
0198     int test = TEST && strlen(TEST) > 0 && TEST[0] == 't'  ? strtol(TEST+1, nullptr, 10) : -1 ; 
0199     switch(test)
0200     {
0201         case 0: t0() ; break ; 
0202         case 1: t1() ; break ; 
0203         case 2: t2() ; break ; 
0204         case 3: t3() ; break ; 
0205     }
0206 }
0207 
0208 int main()
0209 {
0210     NP_delete_test::main(); 
0211     return 0 ; 
0212 }
0213 
0214 // ~/opticks/sysrap/tests/NP_delete_test.sh
0215