nomask static int cmd_hook(string cmd) { string file; string verb; int foo ; mapping before, after ; verb = query_verb(); if (environment() && environment()->valid_exit(verb)) { verb = "go"; cmd = query_verb(); } file = (string)CMD_D->find_cmd(verb, explode(query("PATH"), ":")); if(file && file != "") { #ifdef PROFILING before = rusage() ; #endif foo = (int)call_other(file, "cmd_" + verb, cmd); #ifdef PROFILING after = rusage() ; "/adm/daemons/profile"->log_cmd(verb,before,after) ; #endif return foo ; } if (environment() && environment()->query("quiet")) return 0 ; #ifdef PROFILING before = rusage() ; #endif foo = (int)EMOTE_D->parse(verb, cmd); if (foo) { #ifdef PROFILING after = rusage() ; "/adm/daemons/profile"->log_cmd(verb,before,after) ; #endif return foo ; } #ifdef PROFILING before = rusage(); #endif #ifndef INTERMUD if(verb == "gwiz" || verb == "interwiz"){ printf("Sorry, %s does not support intermud.\n",capitalize(mud_name())); return 1; } #endif /* INTERMUD */ foo = (int) CHANNELS_D -> parse_channel( verb, cmd ); #ifdef PROFILING if( foo ) { after = rsuage(); "/adm/daemons/profile" -> log_cmd( verb, before, after ); } #endif return foo; }
nomask static int cmd_hook(string cmd) { string file; string verb; int foo ; mapping before, after ; verb = query_verb(); if (environment() && environment()->valid_exit(verb)) { verb = "go"; cmd = query_verb(); } file = (string)CMD_D->find_cmd(verb, explode(query("PATH"), ":")); if(file && file != "") { #ifdef PROFILING before = rusage() ; #endif foo = (int)call_other(file, "cmd_" + verb, cmd); #ifdef PROFILING after = rusage() ; "/adm/daemons/profile"->log_cmd(verb,before,after) ; #endif return foo ; } if (environment() && environment()->query("quiet")) return 0 ; #ifdef PROFILING before = rusage() ; #endif foo = (int)EMOTE_D->parse(verb, cmd); if (foo) { #ifdef PROFILING after = rusage() ; "/adm/daemons/profile"->log_cmd(verb,before,after) ; #endif return foo ; } #ifdef PROFILING before = rusage(); #endif foo = (int) CHANNELS_D -> parse_channel( verb, cmd ); #ifdef PROFILING if( foo ) { after = rsuage(); "/adm/daemons/profile" -> log_cmd( verb, before, after ); } #endif return foo; }
void create() { mapping r; return; memory = memory_info() / 1000; users = sizeof(users()); // rusage() not available everywhere. If you really // really need it, figure it out. #if 0 r = rusage(); #endif cpu = (r["utime"] + r["stime"]) / ( uptime() + 1 ) / 10.0; obs = sizeof(objects()); pastobs = allocate(TRACK_NUM); pastusers = allocate(TRACK_NUM); pastmem = allocate(TRACK_NUM); pastcpu = allocate(TRACK_NUM); pastmem[counter] = memory; pastusers[counter] = users; pastobs[counter] = obs; pastcpu[counter] = cpu; lastmem = 0; lastusers = 0; lastcpu = 0.0; lastobs = 0; counter = 0; times = 0.0; call_out("sample", CALL_TIME); }
int main(object me) { float value; mapping r; if (time() - me->query_temp("scan_time") < 10 && ! wizardp(me)) return notify_fail("等等,系统喘气中……\n"); r = rusage(); value = SCALE * (r["utime"] + r["stime"]) / uptime(); write(NOR + WHT "\n\t\t .__________ 系 统 资 讯 __________.\n"); write(NOR + WHT "\t\t ─────────────────────────\n"); write(NOR + WHT "\t\t 游戏的识别名称: " + MUD_NAME + "\n"); write(NOR + WHT "\t\t 界面系统的版本: " + __VERSION__ + "\n"); write(NOR + WHT "\t\t 系统函数库版本: Nitan Mudlib Version 2.1\n"); printf(NOR + WHT "\t\t CPU 使用百分比: %f %% 被这个游戏使用中\n", value ); write(NOR + WHT "\t\t CPU 的负担状况: " + query_load_average() + "\n"); printf(NOR + WHT "\t\t 共使用的记忆体: %s bytes\n", memory_expression(memory_info()) ); write(NOR + WHT "\t\t 线上使用者总数: " + sizeof( users() ) + " 个人在线上\n"); write(NOR + WHT "\t\t 注册使用者总数: " + count_ppls() + " 个人在本游戏注册\n"); write(NOR + WHT "\t\t 载入的物件总数: " + sizeof( objects() ) + " 个物件\n"); write(NOR + WHT "\t\t 心跳总数的资讯: " + sizeof(heart_beats()) + " 个\n"); write(NOR + WHT "\t\t 延迟呼叫数资讯: " + sizeof(call_out_info()) + " 个\n"); write(NOR + WHT "\t\t 系统负载的资讯: " + query_load_average() + "\n"); write(NOR + WHT "\t\t 讯息传输的资讯: " + query_rusage_message() + "\n"); write(NOR + WHT "\t\t 连续执行的时间: " + dotime() + "\n"); write(NOR + WHT "\t\t 游戏现在的状态: " + STATUS + "\n" NOR); write(NOR + WHT "\t\t 游戏对 PK 限制: 每天不超过 8 人,每人不超过 2 次\n\n" NOR); me->set_temp("scan_time", time()); return 1; }
string do_info(string args) { mapping r; float cpu; string mach, vers, name, up, memory, listing; int obs, i; mixed *info, *services; if(args && args != ""){ args = I3_D->query_network_name(args); if(!args){ return("Could not obtain information about that MUD\n"); } info = I3_D->query_mud(args); services = keys(info[10]); listing = ""; for(i=0;i<sizeof(services);i++) listing += services[i]+", "; listing += "\n"; return ( "" + pad( "MUD NAME: " + args, PAD ) + "MUDLIB: " + info[5] + "\n" + pad( "ADDRESS: " + info[1] + " " + info[2], PAD ) + "DRIVER: " + info[7] + "\n" + pad("MUD TYPE: " + info[8], PAD ) + "CPU USE: " + "Unknown" + " %\n" + pad("CURRENT USERS: " + "Unknown", PAD ) + "MEMORY: " + "Unknown" + "\n" + pad("MUD STATUS: " + info[9], PAD ) + "OBJECTS: " + "Unknown\n" + pad("SERVICES: " + listing, PAD) + "" ); } r = rusage(); obs = sizeof( objects() ); mach = arch(); name = capitalize( mud_name() ); vers = version(); cpu = SCALE * (r["utime"] + r["stime"]) / uptime(); memory = (string) CMD_MEM -> parse_mem( memory_info() ); up = format_time( uptime() ); return ( "" + pad( "MUD NAME: " + name, PAD ) + "MUDLIB: " + MUDLIB_NAME + " (" + MUDLIB_VERSION_NUMBER + ")\n" + pad( "ARCHITECTURE: " + mach, PAD ) + "DRIVER: " + vers + "\n" + pad("DRIVER UPTIME: " + up, PAD ) + "CPU USE: " + cpu + " %\n" + pad("CURRENT USERS: " + sizeof( users() ), PAD ) + "MEMORY: " + memory + "\n" + pad("MUD STATUS: " + STATUS, PAD ) + "OBJECTS: " + obs + " loaded.\n" + "" ); }
mixed cmd(string arg) { mapping info; info = rusage(); printf("Current statistics are:\n"+ "Memory: %d\nMajorfaults: %d\nUser time: %d\nSystem time: %d\n", info["maxrss"], info["majflt"], info["minflt"], info["utime"] / 1000, info["stime"] / 1000); return 1; }
mixed cmd(string str) { mapping info; string *cles; string ret; float x, fraction; if(!archp(previous_object())) return 0; info = rusage(); cles = keys(info); foreach(string schlussel in cles){ write(schlussel + ": "+info[schlussel]); }
int main(object me) { mapping info; float x, fraction; string str; info = rusage(); x = info["utime"] + info["stime"]; // time is in msec, convert to sec x = (info["utime"] + info["stime"])/1000; fraction = x / uptime(); str = sprintf("CPU usage: %2.2f%%\n", fraction * 100); write( str ); return 1; }
void sample() { mapping r; memory = lastmem + memory + (lastmem = memory_info() / 1000); users = lastusers + users + (lastusers = sizeof(users())); obs = lastobs + obs + (lastobs = sizeof(objects())); #if 0 r = rusage(); #endif cpu = lastcpu + cpu + (lastcpu = (r["utime"] + r["stime"]) / uptime() / 10.0); times = times + 1.0; pastmem[counter] = memory / times / 2; pastusers[counter] = users / times / 2; pastobs[counter] = obs / times / 2; pastcpu[counter] = cpu / times / 2; if (times == AVERAGING_NUM.0) { times = 0.0; counter = counter + 1; if (counter == TRACK_NUM) counter = 0; memory = lastmem; users = lastusers; cpu = lastcpu; obs = lastobs; pastmem[counter] = memory; pastusers[counter] = users; pastobs[counter] = obs; pastcpu[counter] = cpu; lastmem = 0; lastusers = 0; lastcpu = 0.0; lastobs = 0; } call_out ("sample", CALL_TIME); }
// This is the add_action hook handling movement, commands, emotes and // channels. Optimization is needed. // private nomask int command_hook(string arg) nomask int command_hook(string arg) { string verb, file; object me=this_object(); #ifdef PROFILE_COMMANDS int mem, utime, stime; mapping info; int ecost; // added by mon. 2/25/98 mem = memory_info(); info = rusage(); utime = info["utime"]; stime = info["stime"]; ecost=eval_cost(); #endif verb = query_verb(); //added by mon 11/23/97 if(userp(me)&& (me->query_temp("d_mana"))>0) { if(me->query_temp("is_living")!=1) { if(verb!="bian" && verb!="say" && verb!="tell" && verb!="reply" && verb!="look") { write("别忘了你现在是一"+ (undefinedp(me->query_temp("unit"))? "个":me->query_temp("unit")) +me->name()+"!\n"); return 1; } } } /* mon 10/10/98 if( !arg && (environment() && stringp(environment()->query("exits/" + verb))) && stringp(file = find_command("go")) && call_other(file, "main", this_object(), verb)) ; */ if( !arg && (environment() && environment()->query("exits/" + verb)) && stringp(file = find_command("go")) && call_other(file, "main", this_object(), verb)) ; else if( stringp(file = find_command(verb)) && call_other(file, "main", this_object(), arg)) ; else if( EMOTE_D->do_emote( this_object(), verb, arg ) ) ; else if( CHANNEL_D->do_channel( this_object(), verb, arg ) ) ; else return 0; #ifdef PROFILE_COMMANDS info = rusage(); PROFILE_D->log_command(verb, memory_info() - mem, info["stime"] - stime, info["utime"] - utime, ecost-eval_cost()); #endif return 1; }