<commit_before>/*******************************************************************************
* ALMA - Atacama Large Millimiter Array
* (c) European Southern Observatory, 2005 
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*
* "@(#) $Id: testACSThreadTiming.cpp,v 1.3 2006/03/24 12:42:31 vwang Exp $"
*
* who       when      what
* --------  --------  ----------------------------------------------
* bjeram  2005-02-15  created
*/

// Uncomment this if you are using the VLT environment
// #include "vltPort.h"


#include "acsThreadManager.h"
#include "acsThreadTest.h"


static char *rcsId="@(#) $Id: testACSThreadTiming.cpp,v 1.3 2006/03/24 12:42:31 vwang Exp $"; 
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

int main(int argc, char *argv[])
{
    LoggingProxy logger_m(0, 0, 31);
    LoggingProxy::init(&logger_m);

    ACS::ThreadManager tm;

    /*
     * Creates an autodelete thread that runs every 300 mseconds
     * and stops it after 10 iterations.
     */
    ACS::TimeInterval ti = 3000000;  /* 300ms */
    ACS_LOG(LM_SOURCE_INFO,"main", 
	    (LM_INFO, "Creating thread with time interval %ld", ti));

    /*
     * Since the Thread is autodelete and
     * we do n access it,
     * we do not need to assign it to a variable
     */
    // TestACSThread *a = 
	tm.create<TestACSThread>("TestThreadA", 
				 ti, ti,
				 true);
    tm.resume("TestThreadA");

    /**
     * TODO GCH
     * Add here measure of time.
     * For the time being we simply assume that in 4 seconds
     * it will have completed.
     */
    sleep(4);

    ACS_LOG(LM_SOURCE_INFO,"main", 
	    (LM_INFO, "Done"));
    return 0;

}







<commit_msg>Modified 'Timing' test to check the execution time of the thread<commit_after>/*******************************************************************************
* ALMA - Atacama Large Millimiter Array
* (c) European Southern Observatory, 2005 
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*
* "@(#) $Id: testACSThreadTiming.cpp,v 1.3 2006/03/24 12:42:31 vwang Exp $"
*
* who       when      what
* --------  --------  ----------------------------------------------
* bjeram   2005-02-15  created
* pcolomer 2015-04-23 upgraded code to check execution time of the thread
*/

// Uncomment this if you are using the VLT environment
// #include "vltPort.h"


#include "acsThreadManager.h"
#include "acsThreadTest.h"


static char *rcsId="@(#) $Id: testACSThreadTiming.cpp,v 1.3 2006/03/24 12:42:31 vwang Exp $"; 
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);


static uint64_t timeStart = 0;
static uint64_t timeStop = 0;

uint64_t getTimeInMs()
{
    struct timespec t;
    clock_gettime(CLOCK_MONOTONIC, &t);
    return t.tv_sec * 1000 + (t.tv_nsec / 1000000);
}

class TimingACSThread :public TestACSThread
{
  public:
    TimingACSThread(const ACE_CString& name, 
		  const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, 
		  const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime,
		  bool del=false
	) :
	TestACSThread(name, responseTime, sleepTime, del)
	{
	}

    virtual ~TimingACSThread()
	{
	}

    virtual void onStart()
    {
        timeStart = getTimeInMs();
    }

    virtual void onStop()
    {
        timeStop = getTimeInMs();
    }

};


int main(int argc, char *argv[])
{
    LoggingProxy logger_m(0, 0, 31);
    LoggingProxy::init(&logger_m);

    ACS::ThreadManager tm;

    /*
     * Creates an autodelete thread that runs every 300 mseconds
     * and stops it after 10 iterations.
     */
    ACS::TimeInterval ti = 3000000;  /* 300ms */
    ACS_LOG(LM_SOURCE_INFO,"main", 
	    (LM_INFO, "Creating thread with time interval %ld", ti));

    /*
     * Since the Thread is autodelete and
     * we do n access it,
     * we do not need to assign it to a variable
     */
    // TestACSThread *a = 
	tm.create<TimingACSThread>("TestThreadA", 
				 ti, ti,
				 true);
    tm.resume("TestThreadA");

    /**
     * We wait more than needed to ensure that the thread will be deleted before
     * manager's deletion
     */
    sleep(7);

    // Check execution time of the thread
    int64_t diff = timeStop - timeStart;
    if(diff >= 3400)
    {
        ACS_LOG(LM_SOURCE_INFO,"main",
            (LM_INFO, "Execution time of thread greater than 3400ms: %ld ms", diff));
    }

    ACS_LOG(LM_SOURCE_INFO,"main", 
	    (LM_INFO, "Done"));
    return 0;

}








{'fraction_non_alphanumeric': 0.14551460361613353, 'fraction_numerical': 0.03477051460361613, 'mean_word_length': 2.948524365133837, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6718833', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1714, 'n_words': 623}