MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / catClientInfoString

Function catClientInfoString

src/networking.cpp:2878–2948  ·  view source on GitHub ↗

Concatenate a string representing the state of a client in a human * readable format, into the sds string 's'. */

Source from the content-addressed store, hash-verified

2876/* Concatenate a string representing the state of a client in a human
2877 * readable format, into the sds string 's'. */
2878sds catClientInfoString(sds s, client *client) {
2879 char flags[16], events[3], conninfo[CONN_INFO_LEN], *p;
2880
2881 p = flags;
2882 if (client->flags & CLIENT_SLAVE) {
2883 if (client->flags & CLIENT_MONITOR)
2884 *p++ = 'O';
2885 else
2886 *p++ = 'S';
2887 }
2888 if (client->flags & CLIENT_MASTER) *p++ = 'M';
2889 if (client->flags & CLIENT_PUBSUB) *p++ = 'P';
2890 if (client->flags & CLIENT_MULTI) *p++ = 'x';
2891 if (client->flags & CLIENT_BLOCKED) *p++ = 'b';
2892 if (client->flags & CLIENT_TRACKING) *p++ = 't';
2893 if (client->flags & CLIENT_TRACKING_BROKEN_REDIR) *p++ = 'R';
2894 if (client->flags & CLIENT_TRACKING_BCAST) *p++ = 'B';
2895 if (client->flags & CLIENT_DIRTY_CAS) *p++ = 'd';
2896 if (client->flags & CLIENT_CLOSE_AFTER_REPLY) *p++ = 'c';
2897 if (client->flags & CLIENT_UNBLOCKED) *p++ = 'u';
2898 if (client->flags & CLIENT_CLOSE_ASAP) *p++ = 'A';
2899 if (client->flags & CLIENT_UNIX_SOCKET) *p++ = 'U';
2900 if (client->flags & CLIENT_READONLY) *p++ = 'r';
2901 if (p == flags) *p++ = 'N';
2902 *p++ = '\0';
2903
2904 p = events;
2905 if (client->conn) {
2906 if (connHasReadHandler(client->conn)) *p++ = 'r';
2907 if (connHasWriteHandler(client->conn)) *p++ = 'w';
2908 }
2909 *p = '\0';
2910
2911 /* Compute the total memory consumed by this client. */
2912 size_t obufmem = getClientOutputBufferMemoryUsage(client);
2913 size_t total_mem = obufmem;
2914 total_mem += zmalloc_size(client); /* includes client->buf */
2915 total_mem += sdsZmallocSize(client->querybuf);
2916 /* For efficiency (less work keeping track of the argv memory), it doesn't include the used memory
2917 * i.e. unused sds space and internal fragmentation, just the string length. but this is enough to
2918 * spot problematic clients. */
2919 total_mem += client->argv_len_sum();
2920 if (client->argv)
2921 total_mem += zmalloc_size(client->argv);
2922
2923 return sdscatfmt(s,
2924 "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",
2925 (unsigned long long) client->id,
2926 getClientPeerId(client),
2927 getClientSockname(client),
2928 connGetInfo(client->conn, conninfo, sizeof(conninfo)),
2929 client->name ? (char*)szFromObj(client->name) : "",
2930 (long long)(g_pserver->unixtime - client->ctime),
2931 (long long)(g_pserver->unixtime - client->lastinteraction),
2932 flags,
2933 client->db->id,
2934 (int) dictSize(client->pubsub_channels),
2935 (int) listLength(client->pubsub_patterns),

Callers 12

feedReplicationBacklogFunction · 0.85
syncCommandFunction · 0.85
replicaofCommandFunction · 0.85
logCurrentClientFunction · 0.85
AddReplyFromClientFunction · 0.85
setProtocolErrorFunction · 0.85
readQueryFromClientFunction · 0.85
getAllClientsInfoStringFunction · 0.85
clientCommandFunction · 0.85
addACLLogEntryFunction · 0.85

Calls 13

connHasReadHandlerFunction · 0.85
connHasWriteHandlerFunction · 0.85
zmalloc_sizeFunction · 0.85
sdsZmallocSizeFunction · 0.85
sdscatfmtFunction · 0.85
getClientPeerIdFunction · 0.85
getClientSocknameFunction · 0.85
connGetInfoFunction · 0.85
szFromObjFunction · 0.85
sdslenFunction · 0.85
sdsavailFunction · 0.85

Tested by

no test coverage detected