Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #include "NP.hh"
0002 #include "sprof.h"
0003 
0004 
0005 int main(int argc, char** argv)
0006 {
0007     const char* source = U::Resolve("$SPROF_PATH") ; 
0008     const char* ptn = U::GetEnv("SPROF_PTN", "QSim__")  ; 
0009     const char* SPROF_DUMMY_LAST = U::GetEnv("SPROF_DUMMY_LAST", nullptr ); 
0010 
0011     const char* prof = source ? U::ReadString(source) : nullptr ; 
0012     if(prof == nullptr) return 1 ; 
0013 
0014     std::string _dest = U::ChangeExt( source, ".txt", "_txt.npy" );  // not .npy to avoid stompage
0015     const char* dest = _dest.c_str(); 
0016     //std::cout << "prof:" << ( prof ? prof : "-" ) << std::endl ; 
0017 
0018 
0019     std::vector<std::string> keys ; 
0020     std::vector<std::string> vals ; 
0021     bool only_with_profile = true ; 
0022 
0023     NP::GetMetaKV_(prof, &keys, &vals, only_with_profile, ptn ); 
0024     assert( keys.size() == vals.size() ); 
0025     int num_keys0 = keys.size() ; 
0026     int num_keys = SPROF_DUMMY_LAST ? num_keys0 + 1 : num_keys0 ; 
0027 
0028     std::cout 
0029          << " num_keys0 " << num_keys0 << std::endl 
0030          << " num_keys " << num_keys << std::endl 
0031          << "  SPROF_DUMMY_LAST " << ( SPROF_DUMMY_LAST ? SPROF_DUMMY_LAST : "-" ) << std::endl
0032          ; 
0033 
0034     NP* a = NP::Make<int64_t>( num_keys, 3 ); 
0035     int64_t* aa = a->values<int64_t>(); 
0036 
0037     a->set_meta<std::string>("creator", "sysrap/tests/sprof.cc"); 
0038     a->set_meta<std::string>("source", source ); 
0039     a->set_meta<std::string>("dest", dest ); 
0040     a->set_meta<std::string>("ptn", ptn ); 
0041     a->set_meta<std::string>("SPROF_DUMMY_LAST", ( SPROF_DUMMY_LAST ? SPROF_DUMMY_LAST : "-" ) ); 
0042 
0043     int edge = 10 ; 
0044 
0045     for(int i=0 ; i < num_keys0 ; i++)
0046     {
0047          const char* k = keys[i].c_str(); 
0048          const char* v = vals[i].c_str(); 
0049 
0050          sprof p = {} ; 
0051          sprof::Import(p, v ); 
0052 
0053          if( i < edge || i >= num_keys - edge   ) std::cout 
0054               << std::setw(10) << i << " : " 
0055               << std::setw(20) << k << " : " 
0056               << std::setw(30) << v << " : " 
0057               << sprof::Desc_(p) 
0058               << std::endl
0059               ; 
0060 
0061          aa[3*i+0] = p.st ; 
0062          aa[3*i+1] = p.vm ; 
0063          aa[3*i+2] = p.rs ; 
0064 
0065          a->names.push_back(k) ; 
0066 
0067          if( SPROF_DUMMY_LAST && i == num_keys0 - 1 )
0068          {
0069              aa[3*(i+1)+0] = p.st ;  // dumplicate prior as dummy last  
0070              aa[3*(i+1)+1] = p.vm ; 
0071              aa[3*(i+1)+2] = p.rs ; 
0072              a->names.push_back(SPROF_DUMMY_LAST) ; 
0073          } 
0074     }
0075 
0076 
0077     std::cout << "saving to dest [" << ( dest ? dest : "-" ) << std::endl ;  
0078     a->save(dest); 
0079 
0080     return 0 ; 
0081 }