Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // ~/o/sysrap/tests/SProfTest.sh
0002 
0003 #include <iostream>
0004 #include "SProf.hh"
0005 
0006 struct SProfTest
0007 { 
0008     static int Add_Write_Read();
0009     static int Read();
0010     static int SetTag();
0011     static int Main();
0012 };
0013 
0014 inline int SProfTest::Add_Write_Read()
0015 {
0016     std::cout << __FUNCTION__ << std::endl ;
0017 
0018     SProf::Add("start");
0019     SProf::Add("red");
0020 
0021     for(int i=0 ; i < 10 ; i++ )
0022     {
0023         SProf::SetTag(i, "A%0.3d_" ) ;
0024         SProf::Add("red");
0025         SProf::Add("green");
0026         SProf::Add("blue");
0027         SProf::Add("cyan","photons=10");
0028         SProf::Write();      // frequent write to have something in case of crash
0029     }
0030     SProf::UnsetTag();
0031     SProf::Add("stop");
0032 
0033     std::cout << SProf::Desc() ;
0034 
0035     std::cout << "--------------------------------" << std::endl ;
0036 
0037     SProf::Write();
0038     SProf::Read();
0039 
0040     std::cout << SProf::Desc() ;
0041     return 0;
0042 }
0043 
0044 
0045 /**
0046 SProfTest::Read
0047 -----------------
0048 
0049 Note that running "Read" in the same process before "Add_Write_Read"
0050 without clearing makes it look like the writes are appending
0051 as the vectors get prepopulated, added to then written.
0052 
0053 **/
0054 
0055 
0056 inline int SProfTest::Read()
0057 {
0058     SProf::Read();
0059     std::cout << SProf::Desc() ;
0060     SProf::Clear();
0061     return 0;
0062 }
0063 
0064 inline int SProfTest::SetTag()
0065 {
0066     for(int i=0 ; i < 100 ; i++)
0067     {
0068         SProf::SetTag(i, "A%0.3d_" );
0069         if(i % 10 == 0 ) SProf::UnsetTag();
0070         std::cout << "[" << SProf::TAG << "]" << std::endl ;
0071     }
0072     SProf::UnsetTag();
0073     return 0;
0074 }
0075 
0076 
0077 
0078 inline int SProfTest::Main()
0079 {
0080     const char* TEST = ssys::getenvvar("TEST", "ALL");
0081     bool ALL = strcmp(TEST, "ALL") == 0 ;
0082     int rc = 0 ;
0083     if(ALL||0==strcmp(TEST, "Read"))   rc += Read();
0084     if(ALL||0==strcmp(TEST, "SetTag")) rc += SetTag();
0085     if(ALL||0==strcmp(TEST, "Add_Write_Read")) rc += Add_Write_Read() ;
0086 
0087     return rc ;
0088 }
0089 
0090 int main()
0091 {
0092     return SProfTest::Main();
0093 }