int main(int argc, char **argv) { if(argc < 2) { fprintf(stderr, "usage: %s 'script.k'\n", argv[0]); return 1; } memcached_st *mc = memcached_create(NULL); memcached_server_list_st servers; memcached_return_t rc; servers = memcached_server_list_append(NULL, "127.0.0.1", 11211, &rc); if(rc != MEMCACHED_SUCCESS) { fprintf(stderr, "memcached_server_list_append failed\n"); } rc = memcached_server_Push(mc, servers); memcached_server_list_Free(servers); logpool_t *logpool = logpool_open_client(NULL, "0.0.0.0", 14801); size_t script_len; char *script = loadFile(argv[1], &script_len); memcached_set(mc, "dump_Init", strlen("dump_Init"), script, script_len, 0, 0); logpool_procedure(logpool, "dump", strlen("dump")); struct Log *logbuf = alloca(sizeof(struct Log) + 256); while(1) { if(logpool_client_get(logpool, logbuf, 256) == NULL) { break; } log_dump(stderr, "log=(", logbuf, ")\n", 1); usleep(1); } logpool_close(logpool); free(script); return 0; }
int main(int argc, char **argv) { if(argc < 2) { fprintf(stderr, "usage: %s 'compiled-llvm-bitcode'\n", argv[0]); return 1; } llcache_t *llmc = llcache_new("0.0.0.0", 11211); logpool_t *logpool = logpool_open_client(NULL, "0.0.0.0", 14801); llcache_set(llmc, "tid_usage_init", argv[1]); logpool_procedure(logpool, "tid_usage", strlen("tid_usage")); struct Log *logbuf = alloca(sizeof(struct Log) + 256); while(1) { if(logpool_client_get(logpool, logbuf, 256) == NULL) { break; } log_dump(stderr, "log=(", logbuf, ")\n", 1); usleep(1); } logpool_close(logpool); llcache_delete(llmc); return 0; }
int main(int argc, char **argv) { logpool_t *logpool; logpool = logpool_open_client(NULL, "0.0.0.0", 14801); if(argc < 2) { fprintf(stderr, "usage: %s key value key value ...\n", argv[0]); goto L_error; } logpool_procedure(logpool, argv[1], strlen(argv[1])); struct Log *logbuf = alloca(sizeof(struct Log) + 256); while(1) { logpool_client_get(logpool, logbuf, 256); log_dump(stdout, "log=(", logbuf, ")\n", 1); usleep(1); } logpool_close(logpool); return 0; L_error:; logpool_close(logpool); return 1; }
// LogPool LogPool.loadFile(String key, String file); static KMETHOD LogPool_loadFile(KonohaContext *kctx, KonohaStack *sfp) { logpool_t *lp = (logpool_t *) ((kRawPtr *) sfp[0].asObject)->rawptr; kString *key = sfp[1].asString; kString *file = sfp[2].s; memcached_st *mc = memcached_create(NULL); memcached_server_list_st servers; memcached_return_t rc; servers = memcached_server_list_append(NULL, "127.0.0.1", 11211, &rc); if (rc != MEMCACHED_SUCCESS) { fprintf(stderr, "memcached_server_list_append failed\n"); RETURNvoid_(); } rc = memcached_server_push(mc, servers); memcached_server_list_free(servers); size_t len; char *script = loadFile(S_text(file), &len); memcached_set(mc, S_text(key), S_size(key), script, len, 0, 0); logpool_procedure(lp, (char*)S_text(key), S_size(key)); free(script); RETURNvoid_(); }