Пример #1
0
TimingStateMachine::ParentEvents TimingStateMachine::nextFrame(bool preWarmBetweenSamples) {
    ParentEvents parentEvent = kTiming_ParentEvents;
    switch (fState) {
        case kPreWarm_State: {
            if (fCurrentFrame >= FLAGS_gpuFrameLag) {
                fCurrentFrame = 0;
                fStartTime = now_ms();
                fState = kTiming_State;
            } else {
                fCurrentFrame++;
            }
            break;
        }
        case kTiming_State: {
            switch (fInnerState) {
                case kTuning_InnerState: {
                    if (1 << 30 == fLoops) {
                        // We're about to wrap.  Something's wrong with the bench.
                        SkDebugf("InnerLoops wrapped\n");
                        fLoops = 1;
                    } else {
                        double elapsedMs = this->elapsed();
                        if (elapsedMs < FLAGS_loopMs) {
                            fLoops *= 2;
                        } else {
                            fInnerState = kTiming_InnerState;
                        }
                        fState = kPreWarm_State;
                        this->resetTimingState();
                        parentEvent = kReset_ParentEvents;
                    }
                    break;
                }
                case kTiming_InnerState: {
                    if (fCurrentFrame >= FLAGS_frames) {
                        this->recordMeasurement();
                        this->resetTimingState();
                        parentEvent = kTimingFinished_ParentEvents;
                        if (preWarmBetweenSamples) {
                            fState = kPreWarm_State;
                        } else {
                            fStartTime = now_ms();
                        }
                    } else {
                        fCurrentFrame++;
                    }
                    break;
                }
            }
        }
        break;
    }
    return parentEvent;
}
Пример #2
0
void* SkiaAndroidApp::pthread_main(void* arg) {
    SkDebugf("pthread_main begins");

    auto skiaAndroidApp = (SkiaAndroidApp*)arg;

    // Because JNIEnv is thread sensitive, we need AttachCurrentThread to set our fPThreadEnv
    skiaAndroidApp->fJavaVM->AttachCurrentThread(&(skiaAndroidApp->fPThreadEnv), nullptr);

    ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
    pipe(skiaAndroidApp->fPipes);
    ALooper_addFd(looper, skiaAndroidApp->fPipes[0], LOOPER_ID_MESSAGEPIPE, ALOOPER_EVENT_INPUT,
                  message_callback, skiaAndroidApp);

    skiaAndroidApp->fApp = Application::Create(0, nullptr, skiaAndroidApp);

    double currentTime = 0.0;
    double previousTime = 0.0;
    while (true) {
        const int ident = ALooper_pollAll(0, nullptr, nullptr, nullptr);

        if (ident >= 0) {
            SkDebugf("Unhandled ALooper_pollAll ident=%d !", ident);
        } else {
            previousTime = currentTime;
            currentTime = now_ms();
            skiaAndroidApp->fApp->onIdle(currentTime - previousTime);
        }
    }

    SkDebugf("pthread_main ends");

    return nullptr;
}
Пример #3
0
void *power_set_measurement(void *arg)
{
    unsigned long poll_num = 0;
    struct mstimer timer;
    set_rapl_power(watt_cap, watt_cap);
    double watts = watt_cap;
    // According to the Intel docs, the counter wraps a most once per second.
    // 100 ms should be short enough to always get good information.
    init_msTimer(&timer, 1500);
    init_data();
    start = now_ms();

    poll_num++;
    timer_sleep(&timer);
    while (running)
    {
        take_measurement();
        if (poll_num%5 == 0)
        {
            if (watts >= watt_cap)
            {
                poll_dir = -5;
            }
            if (watts <= 30)
            {
                poll_dir = 5;
            }
            watts += poll_dir;
            set_rapl_power(watts, watts);
        }
        poll_num++;
        timer_sleep(&timer);
    }
}
Пример #4
0
void replica::init_state()
{
    memset(&_app_callbacks, 0, sizeof(_app_callbacks));
    bool r = dsn_get_app_callbacks(_app_info.app_type.c_str(), &_app_callbacks);
    dassert(r, "app '%s' must be registered at this point", _app_info.app_type.c_str());

    _inactive_is_transient = false;
    _prepare_list = new prepare_list(
        0, 
        _options->max_mutation_count_in_prepare_list,
        std::bind(
            &replica::execute_mutation,
            this,
            std::placeholders::_1
            )
    );

    _config.ballot = 0;
    _config.pid.set_app_id(0);
    _config.pid.set_partition_index(0);
    _config.status = partition_status::PS_INACTIVE;
    _primary_states.membership.ballot = 0;
    _last_config_change_time_ms = now_ms();
    _private_log = nullptr;
}
Пример #5
0
bool failure_detector::end_ping_internal(::dsn::error_code err, const beacon_ack& ack)
{
    /*
     * the caller of the end_ping_internal should lock necessarily!!!
     */
    uint64_t beacon_send_time = ack.time;
    auto node = ack.this_node;
    uint64_t now = now_ms();

    master_map::iterator itr = _masters.find(node);

    if (itr == _masters.end())
    {
        dwarn("received beacon ack without corresponding master, ignore it, "
            "remote_master[%s], local_worker[%s]",
            node.to_string(), primary_address().to_string());
        return false;
    }

    master_record& record = itr->second;
    if (!ack.allowed)
    {
        dwarn("worker rejected, stop sending beacon message, "
            "remote_master[%s], local_worker[%s]",
            node.to_string(), primary_address().to_string());
        record.rejected = true;
        record.send_beacon_timer->cancel(true);
        return false;
    }

    if (!is_time_greater_than(beacon_send_time, record.last_send_time_for_beacon_with_ack))
    {
        // out-dated beacon acks, do nothing
        dinfo("ignore out dated beacon acks");
        return false;
    }

    // now the ack is applicable

    if (err != ERR_OK)
    {
        dwarn("ping master failed, err=%s", err.to_string());
        return true;
    }

    // update last_send_time_for_beacon_with_ack
    record.last_send_time_for_beacon_with_ack = beacon_send_time;
    record.rejected = false;

    if (record.is_alive == false
        && now - record.last_send_time_for_beacon_with_ack <= _lease_milliseconds)
    {
        // report master connected
        report(node, true, true);
        itr->second.is_alive = true;
        on_master_connected(node);
    }
    return true;
}
JNIEXPORT void JNICALL Java_com_android_camera_panorama_MosaicRenderer_transferGPUtoCPU(
        JNIEnv * env, jobject obj)
{
    double t0, t1, time_c;

    gYVURenderer[LR].DrawTexture();
    gYVURenderer[HR].DrawTexture();

    glFlush();
    sem_wait(&gPreviewImage_semaphore);
    // Bind to the input LR FBO and read the Low-Res data from there...
    glBindFramebuffer(GL_FRAMEBUFFER, gBufferInputYVU[LR].GetFrameBufferName());
    t0 = now_ms();
    glReadPixels(0,
                 0,
                 gBufferInput[LR].GetWidth(),
                 gBufferInput[LR].GetHeight(),
                 GL_RGBA,
                 GL_UNSIGNED_BYTE,
                 gPreviewImage[LR]);

    checkGlError("glReadPixels LR");

    // Bind to the input HR FBO and read the high-res data from there...
    glBindFramebuffer(GL_FRAMEBUFFER, gBufferInputYVU[HR].GetFrameBufferName());
    t0 = now_ms();
    glReadPixels(0,
                 0,
                 gBufferInput[HR].GetWidth(),
                 gBufferInput[HR].GetHeight(),
                 GL_RGBA,
                 GL_UNSIGNED_BYTE,
                 gPreviewImage[HR]);

    checkGlError("glReadPixels HR");

    sem_post(&gPreviewImage_semaphore);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Пример #7
0
void failure_detector::register_master(::dsn::rpc_address target)
{
    bool setup_timer = false;
    uint64_t now = now_ms();

    zauto_lock l(_lock);

    master_record record(target, now);

    auto ret = _masters.insert(std::make_pair(target, record));
    if (ret.second)
    {
        dinfo("register master[%s] successfully", target.to_string());
        setup_timer = true;
    }
    else
    {
        // active the beacon again in case previously local node is not in target's allow list
        if (ret.first->second.rejected)
        {
            ret.first->second.rejected = false;
            setup_timer = true;            
        }
        dinfo("master[%s] already registered", target.to_string());
    }

    if (setup_timer)
    {
        ret.first->second.send_beacon_timer = tasking::enqueue_timer(LPC_BEACON_SEND, this,
            [this, target]() 
            {
                this->send_beacon(target, now_ms());
            },
            std::chrono::milliseconds(_beacon_interval_milliseconds)
            );
    }
}
Пример #8
0
void* power_measurement(void* arg) {
    struct mstimer timer;
    // according to the Intel docs, the counter wraps a most once per second
    // 100 ms should be short enough to always get good information
    init_msTimer(&timer, 100);
    init_data();
    read_rapl_init();
    start = now_ms();

    timer_sleep(&timer);
    while(running) {
        take_measurement();
        timer_sleep(&timer);
    }
}
Пример #9
0
void failure_detector::on_ping_internal(const beacon_msg& beacon, /*out*/ beacon_ack& ack)
{
    ack.time = beacon.time;
    ack.this_node = beacon.to_addr;
    ack.primary_node = primary_address();
    ack.is_master = true;
    ack.allowed = true;

    zauto_lock l(_lock);

    uint64_t now = now_ms();
    auto node = beacon.from_addr;

    worker_map::iterator itr = _workers.find(node);
    if (itr == _workers.end())
    {
        // if is a new worker, check allow list first if need
        if (_use_allow_list && _allow_list.find(node) == _allow_list.end())
        {
            dwarn("new worker[%s] is rejected", node.to_string());
            ack.allowed = false;
            return;
        }

        // create new entry for node
        worker_record record(node, now);
        record.is_alive = true;
        _workers.insert(std::make_pair(node, record));

        report(node, false, true);
        on_worker_connected(node);
    }
    else if (is_time_greater_than(now, itr->second.last_beacon_recv_time))
    {
        // update last_beacon_recv_time
        itr->second.last_beacon_recv_time = now;

        if (itr->second.is_alive == false)
        {
            itr->second.is_alive = true;

            report(node, false, true);
            on_worker_connected(node);
        }
    }
}
Пример #10
0
void failure_detector::register_worker( ::dsn::rpc_address target, bool is_connected)
{
    uint64_t now = now_ms();

    /*
     * callers should use the fd::_lock necessarily
     */
    worker_record record(target, now);
    record.is_alive = is_connected ? true : false;

    auto ret = _workers.insert(std::make_pair(target, record));
    if ( ret.second )
    {
        dinfo("register worker[%s] successfully", target.to_string());
    }
    else
    {
        dinfo("worker[%s] already registered", target.to_string());
    }
}
Пример #11
0
bool failure_detector::switch_master(::dsn::rpc_address from, ::dsn::rpc_address to, uint32_t delay_milliseconds)
{
    /* the caller of switch master shoud lock necessarily to protect _masters */
    auto it = _masters.find(from);
    auto it2 = _masters.find(to);
    if (it != _masters.end())
    {
        if (it2 != _masters.end())
        {
            dwarn("switch master failed as both are already registered, from[%s], to[%s]",
                  from.to_string(), to.to_string());
            return false;
        }

        it->second.node = to;
        it->second.rejected = false;
        it->second.send_beacon_timer->cancel(true);
        it->second.send_beacon_timer = tasking::enqueue_timer(LPC_BEACON_SEND, this,
            [this, to]()
            {
                this->send_beacon(to, now_ms());
            },
            std::chrono::milliseconds(_beacon_interval_milliseconds),
            0,
            std::chrono::milliseconds(delay_milliseconds)
            );

        _masters.insert(std::make_pair(to, it->second));
        _masters.erase(from);

        dinfo("switch master successfully, from[%s], to[%s]",
              from.to_string(), to.to_string());
    }
    else
    {
        dwarn("switch master failed as from node is not registered yet, from[%s], to[%s]",
              from.to_string(), to.to_string());
        return false;
    }
    return true;
}
Пример #12
0
void replica::init_state()
{
    _inactive_is_transient = false;
    _prepare_list = new prepare_list(
        0, 
        _options->max_mutation_count_in_prepare_list,
        std::bind(
            &replica::execute_mutation,
            this,
            std::placeholders::_1
            )
    );

    _config.ballot = 0;
    _config.pid.set_app_id(0);
    _config.pid.set_partition_index(0);
    _config.status = partition_status::PS_INACTIVE;
    _primary_states.membership.ballot = 0;
    _last_config_change_time_ms = now_ms();
    _private_log = nullptr;
}
Пример #13
0
void update_life_cycle() {
  static double s_lastTime = 0;
  double now = now_ms();
  double timeElapsed = 0;

  if (s_emitters.size() > 0) {
    if (s_lastTime != 0)
      timeElapsed = ((now - s_lastTime) / 1000.0f);
    //DEBUG_LOG_PRINT_D("gl_api", "update_life_cycle timeElapsed=%f", timeElapsed);
    std::vector<EmitterObject*>::iterator it = s_emitters.begin();
    for (; it != s_emitters.end();) {
      bool alive = (*it)->UpdateLifeCycle(timeElapsed);
      if (!alive) {
        delete *it;
        it = s_emitters.erase(it);
      } else
        ++it;
    }
  }
  s_lastTime = now;
}
Пример #14
0
void replica::init_state()
{
    _inactive_is_transient = false;
    _log = nullptr;
    _prepare_list = new prepare_list(
        0, 
        _options.staleness_for_start_prepare_for_potential_secondary,
        std::bind(
            &replica::execute_mutation,
            this,
            std::placeholders::_1
            ),
        _options.prepare_ack_on_secondary_before_logging_allowed
    );

    _config.ballot = 0;
    _config.gpid.pidx = 0;
    _config.gpid.app_id = 0;
    _config.status = PS_INACTIVE;
    _primary_states.membership.ballot = 0;
    _last_config_change_time_ms = now_ms();
}
Пример #15
0
int main(int argc, char**argv)
{
    printf("starting wrapper\n");
    if (argc < 3)
    {
        printf("Usage: %s <watt_cap> <executable> <args>...\n", argv[0]);
        return 1;
    }

    if (highlander())
    {
        /* Start the log file. */
        int logfd;
        char hostname[64];
        gethostname(hostname, 64);

        char *fname;
        int ret = asprintf(&fname, "%s.power.dat", hostname);
        if (ret < 0)
        {
            printf("Fatal Error: Cannot allocate memory for fname.\n");
            return 1;
        }

        logfd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_NOATIME|O_NDELAY, S_IRUSR|S_IWUSR);
        if (logfd < 0)
        {
            printf("Fatal Error: %s on %s cannot open the appropriate fd.\n", argv[0], hostname);
            return 1;
        }
        logfile = fdopen(logfd, "w");

        read_rapl_init();

        /* Set the cap. */
        watt_cap = strtod(argv[1], NULL);
        set_rapl_power(watt_cap, watt_cap);

        /* Start power measurement thread. */
        pthread_t mthread;
        pthread_create(&mthread, NULL, power_set_measurement, NULL);

        /* Fork. */
        pid_t app_pid = fork();
        if (app_pid == 0)
        {
            /* I'm the child. */
            execvp(argv[2], &argv[2]);
            return 1;
        }
        /* Wait. */
        waitpid(app_pid, NULL, 0);
        sleep(1);

        highlander_wait();

        /* Stop power measurement thread. */
        running = 0;
        take_measurement();
        end = now_ms();

        /* Output summary data. */
        char *msg;
        ret = asprintf(&msg, "host: %s\npid: %d\ntotal: %lf\nallocated: %lf\nmax_watts: %lf\nmin_watts: %lf\nruntime ms: %lu\n,start: %lu\nend: %lu\n", hostname, app_pid, total_joules, limit_joules, max_watts, min_watts, end-start, start, end);
        if (ret < 0)
        {
            printf("Fatal Error: Cannot allocate memory for msg.\n");
            return 1;
        }

        fprintf(logfile, "%s", msg);
        fclose(logfile);
        close(logfd);
        shmctl(shmid, IPC_RMID, NULL);
        shmdt(shmseg);
    }
    else
    {
        /* Fork. */
        pid_t app_pid = fork();
        if (app_pid == 0)
        {
            /* I'm the child. */
            execvp(argv[2], &argv[2]);
            return 1;
        }
        /* Wait. */
        waitpid(app_pid, NULL, 0);

        highlander_wait();
    }

    return 0;
}
Пример #16
0
void failure_detector::check_all_records()
{
    if (!_is_started)
    {
        return;
    }

    std::vector< ::dsn::rpc_address> expire;
    uint64_t now =now_ms();

    {
        zauto_lock l(_lock);
        master_map::iterator itr = _masters.begin();
        for (; itr != _masters.end() ; itr++)
        {
            master_record& record = itr->second;

            /*
             * "Check interval" and "send beacon" are interleaved, so we must
             * test if "record will expire before next time we check all the records"
             * in order to guarantee the perfect fd
             */
            if (record.is_alive
                && now + _check_interval_milliseconds - record.last_send_time_for_beacon_with_ack > _lease_milliseconds)
            {
                expire.push_back(record.node);
                record.is_alive = false;

                report(record.node, true, false);
            }
        }

        /*
         * The disconnected event MUST be under the protection of the _lock
         * we must guarantee that the record.is_alive switch and the connect/disconnect
         * callbacks are ATOMIC as these callbacks usually have side effects.
         *
         * And you must be careful with these 2 virtual functions as it is very likely to have
         * nested locks
         */
        if ( expire.size() > 0 )
        {
            on_master_disconnected(expire);
        }
    }


    // process recv record, for server
    expire.clear();
    now =now_ms();

    {
        zauto_lock l(_lock);
        worker_map::iterator itq = _workers.begin();
        for ( ; itq != _workers.end() ; itq++)
        {
            worker_record& record = itq->second;

            if (record.is_alive != false
                && now - record.last_beacon_recv_time > _grace_milliseconds)
            {
                expire.push_back(record.node);
                record.is_alive = false;

                report(record.node, false, false);
            }
        }
        /*
         * The worker disconnected event also need to be under protection of the _lock
         */
        if ( expire.size() > 0 )
        {
            on_worker_disconnected(expire);
        }
    }
}
 ~ScopedTimer() {
   double elapsed_ms = now_ms() - start_ms_;
   printf("Timer %s: %.1f\n", name_, elapsed_ms);
 }
 ScopedTimer(const char* name) {
   name_ = name;
   start_ms_ = now_ms();
 }
Пример #19
0
JNIEXPORT jintArray JNICALL Java_my_exercise_videoprocess_VideoFrameUnit_getVideoFrame
(JNIEnv * env, jobject thiz) {

    int frameFinished = 0;
    AVPacket packet;
    jintArray result;

    int len = 0;
    int i = 0;
    int ret = 0;
    double t0, t1, time_dif;
    result = (*env)->NewIntArray(env, numBytes / 4);
    t0 =  now_ms();

    while( ret = av_read_frame(pFormatCtx, &packet) >= 0) {
        //while( av_seek_frame_generic(pCodecCtx, ) ) {

        if(ret == AVERROR(EAGAIN)) {
            continue;
        }

        // Is this a packet from the video stream?
        if(packet.stream_index==videoStream) {


            // Decode video frame
            t1 = now_ms();
            time_dif = t1 - t0;
            LOGI("VIDEOTIME before %g ms",time_dif);
            len = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
            t1 = now_ms();
            time_dif = t1 - t0;
            LOGI("VIDEOTIME after %g ms",time_dif);
            if ( len < 0 ) {
                //Problems decoding frame
                return NULL;
            }
            //LOGI("Frame decoded %d\n", len);
            // Did we get a video frame?
            if(frameFinished) {
                ++frameCount;

                sws_scale(img_convert_ctx,
                          (const uint8_t* const*)pFrame->data,
                          pFrame->linesize,
                          0,
                          pCodecCtx->height,
                          pFrameRGB->data,
                          pFrameRGB->linesize);
                //LOGI("Scaling finished\n");
                break;
            }
        }
        // Free the packet that was allocated by av_read_frame
        av_free_packet(&packet);
        i++;
    }

    if(len != 0) {
        //LOGI("Set region %d\n", i);
        (*env)->SetIntArrayRegion(env, result, 0, 65535, (jint*)pFrameRGB->data[0]);
        t1 = now_ms();
        time_dif = t1 - t0;
        LOGI("VIDEOTIME END %g ms",time_dif);
    }
    return result;
}
Пример #20
0
void take_measurement() {
#ifdef HAVE_LIBMSR1
    uint64_t inst[NUM_THREADS], core[NUM_THREADS], ref[NUM_THREADS];
#endif
    uint64_t instr0=0, instr1=0;
    uint64_t core0 =0, core1 =0;
    int i;
    double rapl_data[8];
    pthread_mutex_lock(&mlock);
    
    // RAPL reads
    read_rapl_energy_and_power(rapl_data);

#ifdef HAVE_LIBMSR1
    // counter reads
    read_data(inst,core,ref);
    for(i=0;i<8;i++) {
        instr0 += inst[i];
        core0  += core[i];
    }
    for(i=8;i<16;i++) {
        instr1 += inst[i];
        core1  += core[i];
    }
#endif

    total_joules += rapl_data[0] + rapl_data[1];
    limit_joules += rapl_data[2] + rapl_data[3];
    if(max_watts < rapl_data[4]) { max_watts = rapl_data[4]; }
    if(max_watts < rapl_data[5]) { max_watts = rapl_data[5]; }
    if(min_watts > rapl_data[4]) { min_watts = rapl_data[4]; }
    if(min_watts > rapl_data[5]) { min_watts = rapl_data[5]; }
    fprintf(logfile, "time:%ld 0joules:%lf 1joules:%lf 0limwatts:%lf 1limwatts:%lf instr0:%lu instr1:%lu core0:%lu core1:%lu\n",now_ms(),rapl_data[0],rapl_data[1],rapl_data[6],rapl_data[7],instr0,instr1,core0,core1);
    pthread_mutex_unlock(&mlock);
}
Пример #21
0
JSBool
jsFadeTick( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   
   if( 0 == argc )
   {
      jsval stVal ;
      jsval durVal ;
      jsval lhVal ;
      jsval rhVal ;
      jsval xVal, yVal ;
      if( JS_GetProperty( cx, obj, "startTick", &stVal ) 
          &&
          JS_GetProperty( cx, obj, "duration", &durVal ) 
          &&
          JS_GetProperty( cx, obj, "src", &lhVal )
          &&
          JS_GetProperty( cx, obj, "dest", &rhVal )
          &&
          JS_GetProperty( cx, obj, "x", &xVal )
          &&
          JS_GetProperty( cx, obj, "y", &yVal ) )
      {
         unsigned long const start = JSVAL_TO_INT( stVal );
         unsigned long const duration = JSVAL_TO_INT( durVal );
         unsigned long const msNow = now_ms();
         unsigned long const end = start+duration ;
         if( msNow < end )
         {
            unsigned long const _256ths = ((msNow-start)*256)/duration ;
//printf( "0x%02x /256ths\n", _256ths ); fflush( stdout );
      
            JSObject *const src = JSVAL_TO_OBJECT( lhVal );
            JSObject *const dest = JSVAL_TO_OBJECT( rhVal );
            jsval widthVal, heightVal, srcPixVal, destPixVal ;
            if( JS_GetProperty( cx, src, "width", &widthVal )
                &&
                JS_GetProperty( cx, src, "height", &heightVal )
                &&
                JS_GetProperty( cx, src, "pixBuf", &srcPixVal )
                &&
                JSVAL_IS_STRING( srcPixVal ) 
                &&
                JS_GetProperty( cx, dest, "pixBuf", &destPixVal )
                &&
                JSVAL_IS_STRING( destPixVal ) 
            )
            {
               int width  = JSVAL_TO_INT( widthVal ); 
               int height = JSVAL_TO_INT( heightVal );
               JSString *srcPixStr = JSVAL_TO_STRING( srcPixVal );
               unsigned short const *const srcPixMap = (unsigned short *)JS_GetStringBytes( srcPixStr );
               unsigned const srcLen = JS_GetStringLength( srcPixStr );

               JSString *destPixStr = JSVAL_TO_STRING( destPixVal );
               unsigned short const *const destPixMap = (unsigned short *)JS_GetStringBytes( destPixStr );
               unsigned const destLen = JS_GetStringLength( destPixStr );
               if( ( srcLen == destLen ) 
                   &&
                   ( srcLen == width * height * sizeof( srcPixMap[0] ) ) )
               {
                  fbDevice_t &fb = getFB();
         
                  fb.blend( JSVAL_TO_INT( xVal ), JSVAL_TO_INT( yVal ), width, height, srcPixMap, destPixMap, _256ths );
                  *rval = JSVAL_TRUE ;
               }
               else
                  JS_ReportError( cx, "Invalid pixMap(s)\n" );
            }
            else
               JS_ReportError( cx, "Object not initialized, can't draw\n" );
         }
         else
         {
            JSObject *dest = JSVAL_TO_OBJECT( rhVal );
            jsval params[2] = { xVal, yVal };
            jsImageDraw( cx, dest, 2, params, rval );
         } // just draw end item
      }
      else
         JS_ReportError( cx, "getting timeProperties" );
   } // need msNow parameter
   else
      JS_ReportError( cx, "Usage: fade.tick()" );

   return JS_TRUE ;
}
Пример #22
0
/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* state) {
	//struct engine engine;

const int FRAMES_PER_SECOND = 60;
const int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;

	// Make sure glue isn't stripped.
	app_dummy();

	memset(&engine, 0, sizeof(engine));
	state->userData = &engine;
	state->onAppCmd = engine_handle_cmd;
	state->onInputEvent = engine_handle_input;
	engine.app = state;
	
	createSoundEngine();
	createBufferQueueAudioPlayer();

	// Prepare to monitor accelerometer
	/*engine.sensorManager = ASensorManager_getInstance();
	engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
			ASENSOR_TYPE_ACCELEROMETER);
	engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
			state->looper, LOOPER_ID_USER, NULL, NULL);*/

	if (state->savedState != NULL) {
		// We are starting with a previous saved state; restore from it.
	   // engine.state = *(struct saved_state*)state->savedState;
	}

	int32_t next_game_tick = getTickCount();
	int sleep_time = 0;
//http://www.koonsolo.com/news/dewitters-gameloop/
	// loop waiting for stuff to do.
	while (1) {
		// Read all pending events.
		int ident;
		int events;
		struct android_poll_source* source;

		// If not animating, we will block forever waiting for events.
		// If animating, we loop until all events are read, then continue
		// to draw the next frame of animation.
		if ((ident = ALooper_pollAll(0, NULL, &events,
				(void**)&source)) >= 0) {
			// Process this event.
			if (source != NULL) {
				source->process(state, source);
			}
		}

		engine_draw_frame(&engine);
		next_game_tick += SKIP_TICKS;
        sleep_time = next_game_tick - now_ms();
        if( sleep_time >= 0 ) {
            sleep( sleep_time );
        }
	}

	shutdownAudio();
}
Пример #23
0
inline double TimingStateMachine::elapsed() {
    return now_ms() - fStartTime;
}
Пример #24
0
bool replica::update_local_configuration(const replica_configuration& config, bool same_ballot/* = false*/)
{
    dassert(config.ballot > get_ballot()
        || (same_ballot && config.ballot == get_ballot()), "");
    dassert (config.gpid == get_gpid(), "");

    partition_status old_status = status();
    ballot old_ballot = get_ballot();

    // skip unncessary configuration change
    if (old_status == config.status && old_ballot == config.ballot)
        return true;

    // skip invalid change
    switch (old_status)
    {
    case PS_ERROR:
        {
            ddebug(
                "%s: status change from %s @ %lld to %s @ %lld is not allowed",
                name(),
                enum_to_string(old_status),
                old_ballot,
                enum_to_string(config.status),
                config.ballot
                );
            return false;
        }
        break;
    case PS_INACTIVE:
        if ((config.status == PS_PRIMARY || config.status == PS_SECONDARY)
            && !_inactive_is_transient)
        {
            ddebug(
                "%s: status change from %s @ %lld to %s @ %lld is not allowed when inactive state is not transient",
                name(),
                enum_to_string(old_status),
                old_ballot,
                enum_to_string(config.status),
                config.ballot
                );
            return false;
        }
        break;
    case PS_POTENTIAL_SECONDARY:
        if (config.status == PS_ERROR || config.status == PS_INACTIVE)
        {
            if (!_potential_secondary_states.cleanup(false))
            {
                dwarn(
                    "%s: status change from %s @ %lld to %s @ %lld is not allowed coz learning remote state is still running",
                    name(),
                    enum_to_string(old_status),
                    old_ballot,
                    enum_to_string(config.status),
                    config.ballot
                    );
                return false;
            }
        }
        break;
    case PS_SECONDARY:
        if (config.status != PS_SECONDARY
            && _secondary_states.checkpoint_task != nullptr)
        {
            dwarn(
                "%s: status change from %s @ %lld to %s @ %lld is not allowed coz checkpointing is still running",
                name(),
                enum_to_string(old_status),
                old_ballot,
                enum_to_string(config.status),
                config.ballot
                );
            return false;
        }
        break;
    }

    uint64_t oldTs = _last_config_change_time_ms;
    _config = config;
    _last_config_change_time_ms =now_ms();
    dassert (max_prepared_decree() >= last_committed_decree(), "");
    
    switch (old_status)
    {
    case PS_PRIMARY:
        cleanup_preparing_mutations(true);
        switch (config.status)
        {
        case PS_PRIMARY:
            replay_prepare_list();
            break;
        case PS_INACTIVE:
            _primary_states.cleanup(old_ballot != config.ballot);
            break;
        case PS_SECONDARY:
        case PS_ERROR:
            _primary_states.cleanup();
            break;
        case PS_POTENTIAL_SECONDARY:
            dassert (false, "invalid execution path");
            break;
        default:
            dassert (false, "invalid execution path");
        }        
        break;
    case PS_SECONDARY:
        cleanup_preparing_mutations(true);
        switch (config.status)
        {
        case PS_PRIMARY:
            init_group_check();            
            replay_prepare_list();
            break;
        case PS_SECONDARY:
            break;
        case PS_POTENTIAL_SECONDARY:
            // InActive in config
            break;
        case PS_INACTIVE:
            break;
        case PS_ERROR:
            break;
        default:
            dassert (false, "invalid execution path");
        }
        break;
    case PS_POTENTIAL_SECONDARY:
        switch (config.status)
        {
        case PS_PRIMARY:
            dassert (false, "invalid execution path");
            break;
        case PS_SECONDARY:
            _prepare_list->truncate(_app->last_committed_decree());            
            _potential_secondary_states.cleanup(true);
            check_state_completeness();
            break;
        case PS_POTENTIAL_SECONDARY:
            break;
        case PS_INACTIVE:
            _potential_secondary_states.cleanup(true);
            break;
        case PS_ERROR:
            _prepare_list->reset(_app->last_committed_decree());
            _potential_secondary_states.cleanup(true);
            break;
        default:
            dassert (false, "invalid execution path");
        }
        break;
    case PS_INACTIVE:        
        switch (config.status)
        {
        case PS_PRIMARY:
            _inactive_is_transient = false;
            init_group_check();
            replay_prepare_list();
            break;
        case PS_SECONDARY:            
            _inactive_is_transient = false;
            break;
        case PS_POTENTIAL_SECONDARY:
            _inactive_is_transient = false;
            break;
        case PS_INACTIVE:
            break;
        case PS_ERROR:
            _inactive_is_transient = false;
            break;
        default:
            dassert (false, "invalid execution path");
        }
        break;
    case PS_ERROR:
        switch (config.status)
        {
        case PS_PRIMARY:
            dassert (false, "invalid execution path");
            break;
        case PS_SECONDARY:
            dassert (false, "invalid execution path");
            break;
        case PS_POTENTIAL_SECONDARY:
            dassert(false, "invalid execution path");
            break;
        case PS_INACTIVE:
            dassert (false, "invalid execution path");
            break;
        case PS_ERROR:
            break;
        default:
            dassert (false, "invalid execution path");
        }
        break;
    default:
        dassert (false, "invalid execution path");
    }

    dwarn(
        "%s: status change %s @ %lld => %s @ %lld, pre(%llu, %llu), app(%llu, %llu), duration=%llu ms",
        name(),
        enum_to_string(old_status),
        old_ballot,
        enum_to_string(status()),
        get_ballot(),
        _prepare_list->max_decree(),
        _prepare_list->last_committed_decree(),
        _app->last_committed_decree(),
        _app->last_durable_decree(),
        _last_config_change_time_ms - oldTs
        );

    if (status() != old_status)
    {
        bool isClosing = (status() == PS_ERROR || (status() == PS_INACTIVE && get_ballot() > old_ballot));
        _stub->notify_replica_state_update(config, isClosing);

        if (isClosing)
        {
            ddebug("%s: being close ...", name());
            _stub->begin_close_replica(this);
            return false;
        }
    }
    else
    {
        _stub->notify_replica_state_update(config, false);
    }
    return true;
}
Пример #25
0
int db_FrameToReferenceRegistration::AddFrame(const unsigned char * const * im, double H[9],bool force_reference,bool prewarp)
{
  m_current_is_reference = false;
  if(!m_reference_set || force_reference)
    {
      db_Identity3x3(m_H_ref_to_ins);
      db_Copy9(H,m_H_ref_to_ins);

      UpdateReference(im,true,true);
      return 0;
    }

  const unsigned char * const * imptr = im;

  if (m_quarter_resolution)
  {
    if (m_quarter_res_image)
    {
      GenerateQuarterResImage(im);
    }

    imptr = (const unsigned char * const* )m_quarter_res_image;
  }

  double H_last[9];
  db_Copy9(H_last,m_H_ref_to_ins);
  db_Identity3x3(m_H_ref_to_ins);

  m_sq_cost_computed = false;

  // detect corners on inspection image and match to reference image features:s

  // @jke - Adding code to time the functions.  TODO: Remove after test
#if PROFILE
  double iTimer1, iTimer2;
  char str[255];
  strcpy(profile_string,"\n");
  sprintf(str,"[%dx%d] %p\n",m_im_width,m_im_height,im);
  strcat(profile_string, str);
#endif

  // @jke - Adding code to time the functions.  TODO: Remove after test
#if PROFILE
  iTimer1 = now_ms();
#endif
  m_cd.DetectCorners(imptr, m_x_corners_ins,m_y_corners_ins,&m_nr_corners_ins);
  // @jke - Adding code to time the functions.  TODO: Remove after test
# if PROFILE
  iTimer2 = now_ms();
  double elapsedTimeCorner = iTimer2 - iTimer1;
  sprintf(str,"Corner Detection [%d corners] = %g ms\n",m_nr_corners_ins, elapsedTimeCorner);
  strcat(profile_string, str);
#endif

  // @jke - Adding code to time the functions.  TODO: Remove after test
#if PROFILE
  iTimer1 = now_ms();
#endif
    if(prewarp)
  m_cm.Match(m_reference_image,imptr,m_x_corners_ref,m_y_corners_ref,m_nr_corners_ref,
         m_x_corners_ins,m_y_corners_ins,m_nr_corners_ins,
         m_match_index_ref,m_match_index_ins,&m_nr_matches,H,0);
    else
  m_cm.Match(m_reference_image,imptr,m_x_corners_ref,m_y_corners_ref,m_nr_corners_ref,
         m_x_corners_ins,m_y_corners_ins,m_nr_corners_ins,
         m_match_index_ref,m_match_index_ins,&m_nr_matches);
  // @jke - Adding code to time the functions.  TODO: Remove after test
# if PROFILE
  iTimer2 = now_ms();
  double elapsedTimeMatch = iTimer2 - iTimer1;
  sprintf(str,"Matching [%d] = %g ms\n",m_nr_matches,elapsedTimeMatch);
  strcat(profile_string, str);
#endif


  // copy out matching features:
  for ( int i = 0; i < m_nr_matches; ++i )
    {
      int offset = 3*i;
      m_corners_ref[offset  ] = m_x_corners_ref[m_match_index_ref[i]];
      m_corners_ref[offset+1] = m_y_corners_ref[m_match_index_ref[i]];
      m_corners_ref[offset+2] = 1.0;

      m_corners_ins[offset  ] = m_x_corners_ins[m_match_index_ins[i]];
      m_corners_ins[offset+1] = m_y_corners_ins[m_match_index_ins[i]];
      m_corners_ins[offset+2] = 1.0;
    }

  // @jke - Adding code to time the functions.  TODO: Remove after test
#if PROFILE
  iTimer1 = now_ms();
#endif
  // perform the alignment:
  db_RobImageHomography(m_H_ref_to_ins, m_corners_ref, m_corners_ins, m_nr_matches, m_K, m_K, m_temp_double, m_temp_int,
            m_homography_type,NULL,m_max_iterations,m_max_nr_matches,m_scale,
            m_nr_samples, m_chunk_size);
  // @jke - Adding code to time the functions.  TODO: Remove after test
# if PROFILE
  iTimer2 = now_ms();
  double elapsedTimeHomography = iTimer2 - iTimer1;
  sprintf(str,"Homography = %g ms\n",elapsedTimeHomography);
  strcat(profile_string, str);
#endif


  SetOutlierThreshold();

  // Compute the inliers for the db compute m_H_ref_to_ins
  ComputeInliers(m_H_ref_to_ins);

  // Update the max inlier count
  m_max_inlier_count = (m_max_inlier_count > m_num_inlier_indices)?m_max_inlier_count:m_num_inlier_indices;

  // Fit a least-squares model to just the inliers and put it in m_H_ref_to_ins
  if(m_linear_polish)
    Polish(m_inlier_indices, m_num_inlier_indices);

  if (m_quarter_resolution)
  {
    m_H_ref_to_ins[2] *= 2.0;
    m_H_ref_to_ins[5] *= 2.0;
  }

#if PROFILE
  sprintf(str,"#Inliers = %d \n",m_num_inlier_indices);
  strcat(profile_string, str);
#endif
/*
  ///// CHECK IF CURRENT TRANSFORMATION GOOD OR BAD ////
  ///// IF BAD, then update reference to the last correctly aligned inspection frame;
  if(m_num_inlier_indices<5)//0.9*m_nr_matches || m_nr_matches < 20)
  {
    db_Copy9(m_H_ref_to_ins,H_last);
    UpdateReference(imptr,false);
//  UpdateReference(m_aligned_ins_image,false);
  }
  else
  {
  ///// IF GOOD, then update the last correctly aligned inspection frame to be this;
  //db_CopyImage_u(m_aligned_ins_image,imptr,m_im_width,m_im_height,m_over_allocation);
*/
  if(m_do_motion_smoothing)
    SmoothMotion();

   // Disable debug printing
   // db_PrintDoubleMatrix(m_H_ref_to_ins,3,3);

  db_Copy9(H, m_H_ref_to_ins);

  m_nr_frames_processed++;
{
  if ( (m_nr_frames_processed % m_reference_update_period) == 0 )
  {
    //UpdateReference(imptr,false, false);

    #if MB
    UpdateReference(imptr,false, true);
    #else
    UpdateReference(imptr,false, false);
    #endif
  }


  }



  return 1;
}
Пример #26
0
int main(int argc, char** argv) {
    if( argc < 2 ) {
        printf("usage: %s <executable> <args>...\n",argv[0]);
        return 1;
    }
        //saeid
        printf("Im here, beginning of main");
        //end saeid



//    if( highlander()) {
    if(1) {

        //saeid
       printf("after highlander() if, before gethostname");
        //end saeid


        // Start the log file
        int logfd;
        char hostname[64];
        gethostname(hostname,64);

        char* fname;
        asprintf(&fname,"%s.power.dat",hostname);

	//saeid
	printf("file name is: %s",fname);
	//end saeid


        logfd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_NOATIME|O_NDELAY, S_IRUSR|S_IWUSR);
        if( logfd < 0 ) {
            printf( "Fatal Error: %s on %s cannot open the appropriate fd.\n",argv[0], hostname);
        printf ("Error no is : %d\n", errno);

	//	printf("Oh dear, something went wrong with read()! %s\n", strerror(errno));
            return 1;
        }
        logfile = fdopen(logfd,"w");

        // Start power measurement thread
        pthread_t mthread;
        pthread_mutex_init(&mlock,NULL);
        pthread_create(&mthread, NULL, power_measurement, NULL);
	
	//saeid
        printf ("Press any key\n");
        char check;
	check = getchar();
	//end saeid
        
	// Fork
        pid_t app_pid = fork();
        if(app_pid == 0) {
            // I'm the child
            execvp(argv[1],&argv[1]);
            printf("fork failure\n");
            return 1;
        }
        // Wait
        waitpid(app_pid, NULL, 0);
        sleep(1);

        highlander_wait();
        
        // Stop power measurement thread
        running = 0;
        take_measurement();
        end = now_ms();

        // Output summary data
        char* msg;
        asprintf(&msg, "host: %s\npid: %d\ntotal: %lf\nallocated: %lf\nmax_watts: %lf\nmin_watts: %lf\nruntime ms: %lu\n,start: %lu\nend: %lu\n",hostname,app_pid,total_joules,limit_joules,max_watts,min_watts,end-start,start,end);

        fprintf(logfile,"%s",msg);
        fclose(logfile);
        close(logfd);
        shmctl(shmid,IPC_RMID,NULL);
        shmdt(shmseg);
       
    } else {
        // Fork
        pid_t app_pid = fork();
        if(app_pid == 0) {
            // I'm the child
            execvp(argv[1],&argv[1]);
            printf("Fork failure\n");
            return 1;
        }
        // Wait
        waitpid(app_pid, NULL, 0);
        printf("I'm here!\n");
     
        highlander_wait();
    }

    return 0;
}
Пример #27
0
int main(int argc, const char * argv[]) {
#ifdef ICMP
    // get the ping socket
    int ping = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
    {
        // Drop privelege immediately
        errno_t ping_errno = errno;
        setuid(getuid());
    
        if (0 > ping) {
            errno = ping_errno;
            DIE(EX_OSERR, "open ping socket");
        }
        
        LOG(2, "ping socket: %d", ping);
    }
#endif // ICMP
    
    
#ifdef DNS
    // get the dns socket
    int dns = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
    {
        if (0 > dns) {
            DIE(EX_OSERR, "open dns socket");
        }
        LOG(2, "dns socket: %d", dns);
    }
#endif // DNS
    
    struct pollfd fds[2] = {
#ifdef ICMP
        { ping, POLLIN, 0 }
#endif // ICMP
#ifdef BOTH
        ,
#endif // BOTH
#ifdef DNS
        { dns,  POLLIN, 0 }
#endif // DNS
    };

    int fd_count = 0;
#ifdef ICMP
    int ping_index = fd_count++;
#endif // ICMP
#ifdef DNS
    int dns_index = fd_count++;
#endif // DNS

    // process arguments
    struct opts_t opts;
    get_opts(argc, argv, &opts);
    const struct addrinfo * addr = get_one_host(opts.target);
    
#ifdef ICMP
    int sequence = -1;
    struct icmp icmp_template;
    construct_icmp_template(&icmp_template);
#endif // ICMP
    
#ifdef DNS
    void * dns_template;
    size_t template_size = construct_dns_template(&dns_template, opts.query);
    LOG(3, "template: ");
    if (verbose() >= 3) { fputbuf(stderr, dns_template, template_size);fputc('\n', stderr); }
#endif // DNS
    
    // initialize the prng
    srandomdev();
    
    int count = -1;
    while (1) {
        ++count;
        
#ifdef ICMP
        struct icmp icmp_message;
        size_t icmp_message_size;
        icmp_message_size = construct_icmp(&icmp_template, &icmp_message, ++sequence);
        
        ssize_t icmp_sent = sendto(ping, (const void *)&icmp_message, icmp_message_size, 0, addr->ai_addr, addr->ai_addrlen);
        if (0 > icmp_sent) DIE(EX_OSERR, "sendto ping");
        LOG(1, "ping sent %d bytes", icmp_sent);
        long icmp_send_time = now_us();
        long icmp_recv_time = -1;
#endif // ICMP
      
#ifdef DNS
        void * dns_message;
        size_t dns_message_size;
        short dns_id = (short)random();
        dns_message_size = construct_dns(dns_template, template_size, &dns_message, dns_id);
        
        ssize_t dns_sent = sendto(dns, (const void *)dns_message, dns_message_size, 0, addr->ai_addr, addr->ai_addrlen);
        LOG(1, "dns sent %d bytes", dns_sent);
        if (verbose() >= 3) { fputbuf(stderr, dns_message, dns_message_size);fputc('\n', stderr); }
        if (0 > dns_sent) DIE(EX_OSERR, "sendto dns");
        long dns_send_time = now_us();
        long dns_recv_time = -1;
#endif // DNS
        
        long ttd_ms = now_ms() + opts.period_ms;
        int poll_time = (int)opts.period_ms;
        int ret;
        while ((ret = poll(fds, fd_count, poll_time))) {
            if (0 > ret) DIE(EX_OSERR, "poll");
            
#ifdef ICMP
            if (fds[ping_index].revents & POLLERR) {
                int error = 0;
                socklen_t errlen = sizeof(error);
                if (0 < getsockopt(fds[0].fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen))
                    DIE(EX_OSERR, "getsockopt on ping while handling POLLERR");
                errno = error;
                DIE(EX_OSERR, "POLLERR on ping");
            }
            
            if (fds[ping_index].revents & POLLIN) {
                icmp_recv_time = process_ping(fds[ping_index].fd, sequence);
            }
#endif // ICMP
            
#ifdef DNS
            if (fds[dns_index].revents & POLLERR) {
                int error = 0;
                socklen_t errlen = sizeof(error);
                if (0 < getsockopt(fds[1].fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen))
                    DIE(EX_OSERR, "getsockopt on dns while handling POLLERR");
                errno = error;
                DIE(EX_OSERR, "POLLERR on dns");
            }
            
            if (fds[dns_index].revents & POLLIN) {
                dns_recv_time = process_dns(fds[dns_index].fd, dns_id);
            }
#endif // DNS
            
            poll_time = (int)(ttd_ms - now_ms());
            if (poll_time < 0) break;
        }
        
        LOG(1, "poll period %d ended", count);
        
#ifdef ICMP
        REPORT("icmp", icmp_send_time, icmp_recv_time, sequence);
#endif // ICMP
        
#ifdef DNS
        REPORT("dns", dns_send_time, dns_recv_time, dns_id);
#endif // DNS
    }
    
    return 0;
}
Пример #28
0
static JSBool fade( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   if( ( 5 == argc ) 
       && 
       JSVAL_IS_OBJECT( argv[0] )
       && 
       JSVAL_IS_OBJECT( argv[1] )
       && 
       JSVAL_IS_INT( argv[2] )
       && 
       JSVAL_IS_INT( argv[3] )
       && 
       JSVAL_IS_INT( argv[4] ) )
   {
      JSObject *thisObj = JS_NewObject( cx, &jsFadeClass_, NULL, NULL );

      if( thisObj )
      {
         *rval = OBJECT_TO_JSVAL( thisObj ); // root
         JSObject *const src = JSVAL_TO_OBJECT( argv[0] );
         JSObject *const dest = JSVAL_TO_OBJECT( argv[1] );
         jsval lhWidth, lhHeight,
               rhWidth, rhHeight ;
         if( JS_GetProperty( cx, src, "width", &lhWidth )
             &&
             JS_GetProperty( cx, src, "height", &lhHeight )
             &&
             JS_GetProperty( cx, dest, "width", &rhWidth )
             &&
             JS_GetProperty( cx, dest, "height", &rhHeight ) )
         {
            if( ( JSVAL_TO_INT( lhWidth ) == JSVAL_TO_INT( rhWidth ) )
                &&
                ( JSVAL_TO_INT( lhHeight ) == JSVAL_TO_INT( rhHeight ) ) )
            {
               int const duration = JSVAL_TO_INT( argv[2] );
               if( 0 < duration )
               {
                  int const x = JSVAL_TO_INT( argv[3] );
                  int const y = JSVAL_TO_INT( argv[4] );
                  fbDevice_t &fbDev = getFB();
                  if( ( 0 <= x ) && ( 0 <= y ) 
                      &&
                      ( fbDev.getWidth() > x )
                      &&
                      ( fbDev.getHeight() > y ) )
                  {
                     for( int i = 0 ; i < argc ; i++ )
                        JS_DefineProperty( cx, thisObj, 
                                           fadeProperties_[i].name, 
                                           argv[i], 0, 0,  JSPROP_ENUMERATE|JSPROP_PERMANENT|JSPROP_READONLY );
                     unsigned long const tickNow = now_ms();
                     JS_DefineProperty( cx, thisObj, fadeProperties_[argc].name, INT_TO_JSVAL( tickNow ),
                                        0, 0,  JSPROP_ENUMERATE|JSPROP_PERMANENT|JSPROP_READONLY );
                  }
               }
               else
                  JS_ReportError( cx, "duration must be > 0" );
            }
            else
               JS_ReportError( cx, "fade: images must be the same size\n"
                                   "%d/%d, %d/%d\n",
                               JSVAL_TO_INT( lhWidth ), JSVAL_TO_INT( rhWidth ),
                               JSVAL_TO_INT( lhHeight ), JSVAL_TO_INT( rhHeight ) );
         }
         else
            JS_ReportError( cx, "fade: getting image sizes" );
      }
      else
         JS_ReportError( cx, "Error allocating fade" );
   }
   else
      JS_ReportError( cx, "Usage : new fade( srcImg, destImg, durationMs );" );
      
   return JS_TRUE ;

}