bool IsConnected() const { if (!IsOpen()) { return false; } auto timeout = timeval(); timeout.tv_sec = 0; timeout.tv_usec = 1000 * 100; fd_set writeSet; FD_ZERO(&writeSet); FD_SET(socket, &writeSet); int result = select(0, NULL, &writeSet, NULL, &timeout); switch (result) { case SOCKET_ERROR: throw std::runtime_error("TcpSocket.IsConnected - Error calling select"); case 0: return false; default: if (FD_ISSET(socket, &writeSet)) { return true; } else { return false; } } }
static void do_mmap(ssize_t size) { void *buf; int i; buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(stdout), 0); if ((ssize_t)buf < 0) { perror("mmap"); exit(EXIT_FAILURE); } for (i = 0; i < iterations; i++) { struct timeval start, stop, diff; unsigned long long time; gettimeofday(&start, NULL); memset(buf, 0xa0, size); gettimeofday(&stop, NULL); timersub(&stop, &start, &diff); time = timeval(&diff); fprintf(stderr, "memset(): %-2d mmap() write %Lu usec [%.02f MiB/s]\n", i, time, evaluate_bw((float)size, (float)time) / 1E6); } if (munmap(buf, size) < 0) { perror("munmap"); exit(EXIT_FAILURE); } }
struct timeval timespec2timeval(const struct timespec* ts) { if (!ts) { return timeval(); } struct timeval tv; tv.tv_sec = ts->tv_sec; tv.tv_usec = (ts->tv_nsec / 1000); return tv; }
struct timeval mstime2timeval(time64_t mst) { if (mst < 0) { return timeval(); } timeval tv; tv.tv_sec = mst / 1000; tv.tv_usec = (mst % 1000) * 1000; return tv; }
// Скорость исполнения (опреаций в секунду) // tv_seс - целая часть // tv_useс - дробная часть часть (милионная) // 0;500000 => 0;2 static timeval rate(const timeval& tv) { if (tv.tv_sec == 0 && tv.tv_usec == 0) return timeval(); timeval result; long rate_1000 = 1000000000/(tv.tv_sec*1000000 + tv.tv_usec); result.tv_sec = rate_1000 / 1000; result.tv_usec = (rate_1000 - result.tv_sec *1000) * 1000; return result; }
timeval TimeMeasureBase::getTotalTime(const char *identifier) { TimeMeasureObject* obj = getTimeMeasureObjectByIdentifier(identifier); if(obj == NULL) { Logger::warn(Logger::TIMEMEASURE, "getCallCount: Identifier %s not found!!!", identifier); return timeval(); } return obj->totalTime; }
DelayedCall::DelayedCall(double time, void (*func)()) :time(timeval()), func(func), canceller(NULL), cancelled(false), called(false) { gettimeofday(&this->time, NULL); this->time.tv_sec += (int) time; this->time.tv_usec += time-(int)time; }
void PacketWriter::write(PDU &pdu) { PDU::serialization_type buffer = pdu.serialize(); timeval tm; #ifndef _WIN32 gettimeofday(&tm, 0); #else // fixme tm = timeval(); #endif struct pcap_pkthdr header = { tm, static_cast<bpf_u_int32>(buffer.size()), static_cast<bpf_u_int32>(buffer.size()) }; pcap_dump((u_char*)dumper, &header, &buffer[0]); }
static void do_rw(ssize_t size) { void *buf; ssize_t sz, page_size; int i; page_size = sysconf(_SC_PAGESIZE); if (page_size < 0) { perror("sysconf"); exit(EXIT_FAILURE); } buf = alloca(page_size); memset(buf, 0xa0, page_size); for (i = 0; i < iterations; i++) { struct timeval start, stop, diff; unsigned long long time; sz = size; lseek(fileno(stdout), 0, SEEK_SET); gettimeofday(&start, NULL); while (sz > 0) { ssize_t written; written = write(fileno(stdout), buf, MIN(size, page_size)); fprintf(stderr, "written=%d, sz=%d\n", written, sz); if (written < 0) { perror("write"); exit(EXIT_FAILURE); } sz -= written; } gettimeofday(&stop, NULL); timersub(&stop, &start, &diff); time = timeval(&diff); fprintf(stderr, "memset(): %-2d write %Lu usec [%.02f MiB/s]\n", i, time, evaluate_bw((float)size, (float)time) / 1E6); } }
void nest::SimulationManager::simulate( Time const& t ) { assert( kernel().is_initialized() ); t_real_ = 0; t_slice_begin_ = timeval(); t_slice_end_ = timeval(); if ( t == Time::ms( 0.0 ) ) return; if ( t < Time::step( 1 ) ) { LOG( M_ERROR, "SimulationManager::simulate", String::compose( "Simulation time must be >= %1 ms (one time step).", Time::get_resolution().get_ms() ) ); throw KernelException(); } if ( t.is_finite() ) { Time time1 = clock_ + t; if ( !time1.is_finite() ) { std::string msg = String::compose( "A clock overflow will occur after %1 of %2 ms. Please reset network " "clock first!", ( Time::max() - clock_ ).get_ms(), t.get_ms() ); LOG( M_ERROR, "SimulationManager::simulate", msg ); throw KernelException(); } } else { std::string msg = String::compose( "The requested simulation time exceeds the largest time NEST can handle " "(T_max = %1 ms). Please use a shorter time!", Time::max().get_ms() ); LOG( M_ERROR, "SimulationManager::simulate", msg ); throw KernelException(); } to_do_ += t.get_steps(); to_do_total_ = to_do_; const size_t num_active_nodes = prepare_simulation_(); // from_step_ is not touched here. If we are at the beginning // of a simulation, it has been reset properly elsewhere. If // a simulation was ended and is now continued, from_step_ will // have the proper value. to_step_ is set as in advance_time(). delay end_sim = from_step_ + to_do_; if ( kernel().connection_manager.get_min_delay() < end_sim ) to_step_ = kernel() .connection_manager.get_min_delay(); // update to end of time slice else to_step_ = end_sim; // update to end of simulation time // Warn about possible inconsistencies, see #504. // This test cannot come any earlier, because we first need to compute // min_delay_ // above. if ( t.get_steps() % kernel().connection_manager.get_min_delay() != 0 ) LOG( M_WARNING, "SimulationManager::simulate", "The requested simulation time is not an integer multiple of the minimal " "delay in the network. This may result in inconsistent results under the " "following conditions: (i) A network contains more than one source of " "randomness, e.g., two different poisson_generators, and (ii) Simulate " "is called repeatedly with simulation times that are not multiples of " "the minimal delay." ); resume_( num_active_nodes ); finalize_simulation_(); }
#include <GL/glut.h> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include "glut.hpp" #define VIEWING_DISTANCE_MIN 3.0 #define TEXTURE_ID_CUBE 1 float g_view_dist = 3.0E11; float g_view_x = 0.5;//0.0; float g_view_y = 0.5;//7.5; float g_view_yaw = 0; float g_view_pitch = 0; struct timeval last_idle_time = timeval(); float g_time = 0;
std::map<std::string,double> TimerCpp::mean_time = std::map<std::string,double>(); std::map<std::string,double> TimerCpp::sum_time = std::map<std::string,double>(); std::map<std::string,unsigned long> TimerCpp::count = std::map<std::string,unsigned long>(); std::map<std::string,std::set<std::string> > TimerCpp::timer_tree = std::map<std::string,std::set<std::string> >(); std::string TimerCpp::top_node = ""; struct timeval TimerCpp::msTime = timeval(); //~ ---------------- PRIVATE METHODS ----------------------// void TimerCpp::printMsInternal(double t) { std::cout << t << " ms"; } void TimerCpp::printSecInternal(double t) { std::cout << t / 1000.0 << " sec"; } void TimerCpp::printMinInternal(double t) { std::cout << t / 1000.0 / 60.0 << " minutes"; }
static int timediff (const timespec &t1, const timespec &t2) { return ((timeval (t1) - timeval (t2)) / MILLION); }
void nest::SimulationManager::prepare() { assert( kernel().is_initialized() ); if ( prepared_ ) { std::string msg = "Prepare called twice."; LOG( M_ERROR, "SimulationManager::prepare", msg ); throw KernelException(); } if ( inconsistent_state_ ) { throw KernelException( "Kernel is in inconsistent state after an " "earlier error. Please run ResetKernel first." ); } t_real_ = 0; t_slice_begin_ = timeval(); // set to timeval{0, 0} as unset flag t_slice_end_ = timeval(); // set to timeval{0, 0} as unset flag // find shortest and longest delay across all MPI processes // this call sets the member variables kernel().connection_manager.update_delay_extrema_(); kernel().event_delivery_manager.init_moduli(); // Check for synchronicity of global rngs over processes. // We need to do this ahead of any simulation in case random numbers // have been consumed on the SLI level. if ( kernel().mpi_manager.get_num_processes() > 1 ) { if ( not kernel().mpi_manager.grng_synchrony( kernel().rng_manager.get_grng()->ulrand( 100000 ) ) ) { LOG( M_ERROR, "SimulationManager::prepare", "Global Random Number Generators are not synchronized prior to " "simulation." ); throw KernelException(); } } // if at the beginning of a simulation, set up spike buffers if ( not simulated_ ) { kernel().event_delivery_manager.configure_spike_buffers(); } kernel().node_manager.ensure_valid_thread_local_ids(); kernel().node_manager.prepare_nodes(); kernel().model_manager.create_secondary_events_prototypes(); // we have to do enter_runtime after prepare_nodes, since we use // calibrate to map the ports of MUSIC devices, which has to be done // before enter_runtime if ( not simulated_ ) // only enter the runtime mode once { double tick = Time::get_resolution().get_ms() * kernel().connection_manager.get_min_delay(); kernel().music_manager.enter_runtime( tick ); } prepared_ = true; }
timeval get_min() const { return min_span.tv_sec != LONG_MAX ? min_span : timeval(); } // Минимальный интервал
DateTime DateTime::operator-(const TimeSpan & ts) const { Glib::TimeVal timeval(m_date); timeval.add_milliseconds(ts.total_milliseconds()); return DateTime(timeval); }
MStatus motionTrace::redoIt() // // Description // This method performs the action of the command. // // This method iterates over all selected items and // prints out connected plug and dependency node type // information. // { MStatus stat; // Status code MObjectArray picked; MObject dependNode; // Selected dependency node // Create a selection list iterator // MSelectionList slist; MGlobal::getActiveSelectionList( slist ); MItSelectionList iter( slist, MFn::kInvalid,&stat ); // Iterate over all selected dependency nodes // and save them in a list // for ( ; !iter.isDone(); iter.next() ) { // Get the selected dependency node // if ( MS::kSuccess != iter.getDependNode( dependNode ) ) { cerr << "Error getting the dependency node" << endl; continue; } picked.append( dependNode ); } // array of arrays for object position MPointArray *pointArrays = new MPointArray [ picked.length() ]; unsigned int i; double time; // Sample the animation using start, end, by values for ( time = start; time <= end; time+=by ) { MTime timeval(time); MGlobal::viewFrame( timeval ); // Iterate over selected dependency nodes // for ( i = 0; i < picked.length(); i++ ) { // Get the selected dependency node // dependNode = picked[i]; // Create a function set for the dependency node // MFnDependencyNode fnDependNode( dependNode ); // Get the translation attribute values MObject txAttr; txAttr = fnDependNode.attribute( MString("translateX"), &stat ); MPlug txPlug( dependNode, txAttr ); double tx; stat = txPlug.getValue( tx ); MObject tyAttr; tyAttr = fnDependNode.attribute( MString("translateY"), &stat ); MPlug tyPlug( dependNode, tyAttr ); double ty; stat = tyPlug.getValue( ty ); MObject tzAttr; tzAttr = fnDependNode.attribute( MString("translateZ"), &stat ); MPlug tzPlug( dependNode, tzAttr ); double tz; stat = tzPlug.getValue( tz ); #if 0 fprintf( stderr, "Time = %2.2lf, XYZ = ( %2.2lf, %2.2lf, %2.2lf )\n\n", time, tx, ty, tz ); #endif pointArrays[i].append( MPoint( tx, ty, tz )) ; } } // make a path curve for each selected object for ( i = 0; i < picked.length(); i++ ) jMakeCurve( pointArrays[i] ); delete [] pointArrays; return MS::kSuccess; }