Concatenate a string representing the state of a client in a human * readable format, into the sds string 's'. */
| 2297 | /* Concatenate a string representing the state of a client in a human |
| 2298 | * readable format, into the sds string 's'. */ |
| 2299 | sds catClientInfoString(sds s, client *client) { |
| 2300 | char flags[16], events[3], conninfo[CONN_INFO_LEN], *p; |
| 2301 | |
| 2302 | p = flags; |
| 2303 | if (client->flags & CLIENT_SLAVE) { |
| 2304 | if (client->flags & CLIENT_MONITOR) |
| 2305 | *p++ = 'O'; |
| 2306 | else |
| 2307 | *p++ = 'S'; |
| 2308 | } |
| 2309 | if (client->flags & CLIENT_MASTER) *p++ = 'M'; |
| 2310 | if (client->flags & CLIENT_PUBSUB) *p++ = 'P'; |
| 2311 | if (client->flags & CLIENT_MULTI) *p++ = 'x'; |
| 2312 | if (client->flags & CLIENT_BLOCKED) *p++ = 'b'; |
| 2313 | if (client->flags & CLIENT_TRACKING) *p++ = 't'; |
| 2314 | if (client->flags & CLIENT_TRACKING_BROKEN_REDIR) *p++ = 'R'; |
| 2315 | if (client->flags & CLIENT_TRACKING_BCAST) *p++ = 'B'; |
| 2316 | if (client->flags & CLIENT_DIRTY_CAS) *p++ = 'd'; |
| 2317 | if (client->flags & CLIENT_CLOSE_AFTER_REPLY) *p++ = 'c'; |
| 2318 | if (client->flags & CLIENT_UNBLOCKED) *p++ = 'u'; |
| 2319 | if (client->flags & CLIENT_CLOSE_ASAP) *p++ = 'A'; |
| 2320 | if (client->flags & CLIENT_UNIX_SOCKET) *p++ = 'U'; |
| 2321 | if (client->flags & CLIENT_READONLY) *p++ = 'r'; |
| 2322 | if (p == flags) *p++ = 'N'; |
| 2323 | *p++ = '\0'; |
| 2324 | |
| 2325 | p = events; |
| 2326 | if (client->conn) { |
| 2327 | if (connHasReadHandler(client->conn)) *p++ = 'r'; |
| 2328 | if (connHasWriteHandler(client->conn)) *p++ = 'w'; |
| 2329 | } |
| 2330 | *p = '\0'; |
| 2331 | |
| 2332 | /* Compute the total memory consumed by this client. */ |
| 2333 | size_t obufmem = getClientOutputBufferMemoryUsage(client); |
| 2334 | size_t total_mem = obufmem; |
| 2335 | total_mem += zmalloc_size(client); /* includes client->buf */ |
| 2336 | total_mem += sdsZmallocSize(client->querybuf); |
| 2337 | /* For efficiency (less work keeping track of the argv memory), it doesn't include the used memory |
| 2338 | * i.e. unused sds space and internal fragmentation, just the string length. but this is enough to |
| 2339 | * spot problematic clients. */ |
| 2340 | total_mem += client->argv_len_sum; |
| 2341 | if (client->argv) |
| 2342 | total_mem += zmalloc_size(client->argv); |
| 2343 | |
| 2344 | return sdscatfmt(s, |
| 2345 | "id=%U addr=%s laddr=%s %s name=%s age=%I idle=%I flags=%s db=%i sub=%i psub=%i multi=%i qbuf=%U qbuf-free=%U argv-mem=%U obl=%U oll=%U omem=%U tot-mem=%U events=%s cmd=%s user=%s redir=%I", |
| 2346 | (unsigned long long) client->id, |
| 2347 | getClientPeerId(client), |
| 2348 | getClientSockname(client), |
| 2349 | connGetInfo(client->conn, conninfo, sizeof(conninfo)), |
| 2350 | client->name ? (char*)client->name->ptr : "", |
| 2351 | (long long)(server.unixtime - client->ctime), |
| 2352 | (long long)(server.unixtime - client->lastinteraction), |
| 2353 | flags, |
| 2354 | client->db->id, |
| 2355 | (int) dictSize(client->pubsub_channels), |
| 2356 | (int) listLength(client->pubsub_patterns), |
no test coverage detected