Example #1
0
void Cartridge::dump(std::ostream& stream) const
{
    stream << "Title: " << title() << std::endl;
    stream << "Legit: " << (isLegit() ? "yes" : "no") << std::endl;
    stream << "Type: ";
    std::cout << std::hex;
    switch (type())
    {
#define X(NAME, CODE)                               \
        case CODE:                                  \
            stream << #NAME  << " (0x"              \
                   << CODE << ")" << std::endl;     \
            break;
        GBEMU_CARTRIDGE_TYPES
#undef X
        default:
            stream << "UNKNOWN (0x"
                   << (unsigned int)type() << ")"
                   << std::endl;
            break;
    };
    std::cout << std::dec;
    stream << "ROM size: " << bytesToHuman(ROMSize()) << std::endl;
    stream << "RAM size: " << bytesToHuman(RAMSize()) << std::endl;
    std::cout << std::hex;
    stream << "Header checksum: 0x" << (unsigned int)headerChecksum() << std::endl;
    stream << "Cartridge checksum: 0x" << (unsigned int)cartridgeChecksum() << std::endl;
    std::cout << std::dec;
    stream << "Header checksum valid? " << (isHeaderChecksumValid() ? "yes" : "no") << std::endl;
    stream << "Cartridge checksum valid? " << (isCartridgeChecksumValid() ? "yes" : "no") << std::endl;
}
Example #2
0
/* Create the string returned by the INFO command. This is decoupled
 * by the INFO command itself as we need to report the same information
 * on memory corruption problems. */
sds genVireInfoString(char *section) {
    sds info = sdsempty();
    time_t uptime = time(NULL)-server.starttime;
    int j, numcommands;
    struct rusage self_ru;
    unsigned long lol, bib;
    int allsections = 0, defsections = 0;
    int sections = 0;
    long long keys_all, vkeys_all, avg_ttl_all;
    int nexit = 0;
    
    keys_all = vkeys_all = avg_ttl_all = 0;

    if (section == NULL) section = "default";
    allsections = strcasecmp(section,"all") == 0;
    defsections = strcasecmp(section,"default") == 0;

    getrusage(RUSAGE_SELF, &self_ru);

    /* Server */
    if (allsections || defsections || !strcasecmp(section,"server")) {
        static int call_uname = 1;
        static struct utsname name;
        char *mode;

        mode = "standalone";

        if (sections++) info = sdscat(info,"\r\n");

        if (call_uname) {
            /* Uname can be slow and is always the same output. Cache it. */
            uname(&name);
            call_uname = 0;
        }

        info = sdscatprintf(info,
            "# Server\r\n"
            "vire_version:%s\r\n"
            "vire_mode:%s\r\n"
            "os:%s %s %s\r\n"
            "arch_bits:%d\r\n"
            "multiplexing_api:%s\r\n"
            "gcc_version:%d.%d.%d\r\n"
            "process_id:%ld\r\n"
            "run_id:%s\r\n"
            "tcp_port:%d\r\n"
            "uptime_in_seconds:%jd\r\n"
            "uptime_in_days:%jd\r\n"
            "hz:%d\r\n"
            "executable:%s\r\n"
            "config_file:%s\r\n",
            VR_VERSION_STRING,
            mode,
            name.sysname, name.release, name.machine,
            server.arch_bits,
            aeGetApiName(),
#ifdef __GNUC__
            __GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__,
#else
            0,0,0,
#endif
            (long) getpid(),
            server.runid,
            server.port,
            (intmax_t)uptime,
            (intmax_t)(uptime/(3600*24)),
            server.hz,
            server.executable ? server.executable : "",
            server.configfile ? server.configfile : "");
    }

    /* Memory */
    if (allsections || defsections || !strcasecmp(section,"memory")) {
        char hmem[64];
        char peak_hmem[64];
        char total_system_hmem[64];
        char used_memory_lua_hmem[64];
        char used_memory_rss_hmem[64];
        char maxmemory_hmem[64];
        size_t vr_used_memory = vr_alloc_used_memory();
        size_t total_system_mem = server.system_memory_size;

        /* Peak memory is updated from time to time by serverCron() so it
         * may happen that the instantaneous value is slightly bigger than
         * the peak value. This may confuse users, so we update the peak
         * if found smaller than the current memory usage. */
        if (vr_used_memory > server.stat_peak_memory)
            server.stat_peak_memory = vr_used_memory;

        bytesToHuman(hmem,vr_used_memory);
        bytesToHuman(peak_hmem,server.stat_peak_memory);
        bytesToHuman(total_system_hmem,total_system_mem);
        bytesToHuman(maxmemory_hmem,server.maxmemory);

        if (sections++) info = sdscat(info,"\r\n");
        info = sdscatprintf(info,
            "# Memory\r\n"
            "used_memory:%zu\r\n"
            "used_memory_human:%s\r\n"
            "used_memory_peak:%zu\r\n"
            "used_memory_peak_human:%s\r\n"
            "total_system_memory:%lu\r\n"
            "total_system_memory_human:%s\r\n"
            "maxmemory:%lld\r\n"
            "maxmemory_human:%s\r\n"
            "mem_allocator:%s\r\n",
            vr_used_memory,
            hmem,
            server.stat_peak_memory,
            peak_hmem,
            (unsigned long)total_system_mem,
            total_system_hmem,
            server.maxmemory,
            maxmemory_hmem,
            VR_MALLOC_LIB
            );
    }

    /* Stats */
    if (allsections || defsections || !strcasecmp(section,"stats")) {
        uint32_t idx;
        vr_worker *worker;
        vr_stats *stats;
        long long stat_numconnections=0, stat_numcommands=0;
        long long stat_net_input_bytes=0, stat_net_output_bytes=0;
        long long stat_rejected_conn=0;
        long long stat_expiredkeys=0;
        long long stat_keyspace_hits=0, stat_keyspace_misses=0;

        for (idx = 0; idx < array_n(&workers); idx ++) {
            worker = array_get(&workers, idx);
            stats = worker->vel.stats;
#if (defined(__ATOMIC_RELAXED) || defined(HAVE_ATOMIC)) && defined(STATS_ATOMIC_FIRST)
            stat_numcommands += update_stats_add(stats, numcommands, 0);
            stat_numconnections += update_stats_add(stats, numconnections, 0);
            stat_expiredkeys += update_stats_add(stats, expiredkeys, 0);
            stat_net_input_bytes += update_stats_add(stats, net_input_bytes, 0);
            stat_net_output_bytes += update_stats_add(stats, net_output_bytes, 0);
            stat_keyspace_hits += update_stats_add(stats, keyspace_hits, 0);
            stat_keyspace_misses += update_stats_add(stats, keyspace_misses, 0);
#else
            pthread_spin_lock(&stats->statslock);
            stat_numcommands += stats->numcommands;
            stat_numconnections += stats->numconnections;
            stat_expiredkeys += stats->expiredkeys;
            stat_net_input_bytes += stats->net_input_bytes;
            stat_net_output_bytes += stats->net_output_bytes;
            stat_keyspace_hits += stats->keyspace_hits;
            stat_keyspace_misses += stats->keyspace_misses;
            pthread_spin_unlock(&stats->statslock);
#endif
        }

#if (defined(__ATOMIC_RELAXED) || defined(HAVE_ATOMIC)) && defined(STATS_ATOMIC_FIRST)
        stat_rejected_conn += update_stats_add(master.vel.stats, rejected_conn, 0);
#else
        pthread_spin_lock(&master.vel.stats->statslock);
        stat_rejected_conn = master.vel.stats->rejected_conn;
        pthread_spin_unlock(&master.vel.stats->statslock);
#endif
        
        if (sections++) info = sdscat(info,"\r\n");
        info = sdscatprintf(info,
            "# Stats\r\n"
            "total_connections_received:%lld\r\n"
            "total_commands_processed:%lld\r\n"
            "total_net_input_bytes:%lld\r\n"
            "total_net_output_bytes:%lld\r\n"
            "rejected_connections:%lld\r\n"
            "expired_keys:%lld\r\n"
            "keyspace_hits:%lld\r\n"
            "keyspace_misses:%lld\r\n",
            stat_numconnections,
            stat_numcommands,
            stat_net_input_bytes,
            stat_net_output_bytes,
            stat_rejected_conn,
            stat_expiredkeys,
            stat_keyspace_hits,
            stat_keyspace_misses);
    }

    /* CPU */
    if (allsections || defsections || !strcasecmp(section,"cpu")) {
        if (sections++) info = sdscat(info,"\r\n");
        info = sdscatprintf(info,
        "# CPU\r\n"
        "used_cpu_sys:%.2f\r\n"
        "used_cpu_user:%.2f\r\n",
        (float)self_ru.ru_stime.tv_sec+(float)self_ru.ru_stime.tv_usec/1000000,
        (float)self_ru.ru_utime.tv_sec+(float)self_ru.ru_utime.tv_usec/1000000);
    }
    
    /* Internal */
    if (allsections || !strcasecmp(section,"internal")) {
        redisDb *db;
        long long keys, vkeys, avg_ttl;
        if (sections++) info = sdscat(info,"\r\n");
        info = sdscatprintf(info, "# Internal\r\n");
        for (j = 0; j < server.dbnum; j++) {
            db = array_get(&server.dbs, j);
            pthread_rwlock_rdlock(&db->rwl);
            keys = dictSize(db->dict);
            vkeys = dictSize(db->expires);
            avg_ttl = db->avg_ttl;
            pthread_rwlock_unlock(&db->rwl);
            if (keys || vkeys) {
                info = sdscatprintf(info,
                    "db%d:keys=%lld,expires=%lld,avg_ttl=%lld\r\n",
                    j, keys, vkeys, db->avg_ttl);
            }
            keys_all += keys;
            vkeys_all += vkeys;
            avg_ttl_all += avg_ttl;
            if (avg_ttl > 0) nexit ++;
        }
    }

    /* Key space */
    if (allsections || defsections || !strcasecmp(section,"keyspace")) {
        redisDb *db;
        if (sections++) info = sdscat(info,"\r\n");
        info = sdscatprintf(info, "# Keyspace\r\n");
        if (keys_all == 0) {
            for (j = 0; j < server.dbnum; j++) {
                db = array_get(&server.dbs, j);
                pthread_rwlock_rdlock(&db->rwl);
                keys_all += dictSize(db->dict);
                vkeys_all += dictSize(db->expires);
                avg_ttl_all += db->avg_ttl;
                if (db->avg_ttl > 0) nexit ++;
                pthread_rwlock_unlock(&db->rwl);
            }
        }
        if (keys_all || vkeys_all) {
            info = sdscatprintf(info,
                "keys=%lld,expires=%lld,avg_ttl=%lld\r\n",
                keys_all, vkeys_all, nexit > 0 ? (avg_ttl_all/nexit) : 0);
        }
    }

    return info;
}
Example #3
0
static void statMode() {
    redisReply *reply;
    long aux, requests = 0;
    int i = 0;

    while(1) {
        char buf[64];
        int j;

        reply = reconnectingInfo();
        if (reply->type == REDIS_REPLY_ERROR) {
            printf("ERROR: %s\n", reply->str);
            exit(1);
        }

        if ((i++ % 20) == 0) {
            printf(
"------- data ------ --------------------- load -------------------- - child -\n"
"keys       mem      clients blocked requests            connections          \n");
        }

        /* Keys */
        aux = 0;
        for (j = 0; j < 20; j++) {
            long k;

            sprintf(buf,"db%d:keys",j);
            k = getLongInfoField(reply->str,buf);
            if (k == LONG_MIN) continue;
            aux += k;
        }
        sprintf(buf,"%ld",aux);
        printf("%-11s",buf);

        /* Used memory */
        aux = getLongInfoField(reply->str,"used_memory");
        bytesToHuman(buf,aux);
        printf("%-8s",buf);

        /* Clients */
        aux = getLongInfoField(reply->str,"connected_clients");
        sprintf(buf,"%ld",aux);
        printf(" %-8s",buf);

        /* Blocked (BLPOPPING) Clients */
        aux = getLongInfoField(reply->str,"blocked_clients");
        sprintf(buf,"%ld",aux);
        printf("%-8s",buf);

        /* Requets */
        aux = getLongInfoField(reply->str,"total_commands_processed");
        sprintf(buf,"%ld (+%ld)",aux,requests == 0 ? 0 : aux-requests);
        printf("%-19s",buf);
        requests = aux;

        /* Connections */
        aux = getLongInfoField(reply->str,"total_connections_received");
        sprintf(buf,"%ld",aux);
        printf(" %-12s",buf);

        /* Children */
        aux = getLongInfoField(reply->str,"bgsave_in_progress");
        aux |= getLongInfoField(reply->str,"aof_rewrite_in_progress") << 1;
        switch(aux) {
        case 0: break;
        case 1:
            printf("SAVE");
            break;
        case 2:
            printf("AOF");
            break;
        case 3:
            printf("SAVE+AOF");
            break;
        }

        printf("\n");
        freeReplyObject(reply);
        usleep(config.interval);
    }
}