4545/* Create a new slowlog entry.
4646 * Incrementing the ref count of all the objects retained is up to
4747 * this function. */
48- slowlogEntry * slowlogCreateEntry (robj * * argv , int argc , long long duration ) {
48+ slowlogEntry * slowlogCreateEntry (client * c , robj * * argv , int argc , long long duration ) {
4949 slowlogEntry * se = zmalloc (sizeof (* se ));
5050 int j , slargc = argc ;
5151
@@ -81,6 +81,8 @@ slowlogEntry *slowlogCreateEntry(robj **argv, int argc, long long duration) {
8181 se -> time = time (NULL );
8282 se -> duration = duration ;
8383 se -> id = server .slowlog_entry_id ++ ;
84+ se -> peerid = sdsnew (getClientPeerId (c ));
85+ se -> cname = c -> name ? sdsnew (c -> name -> ptr ) : sdsempty ();
8486 return se ;
8587}
8688
@@ -95,6 +97,8 @@ void slowlogFreeEntry(void *septr) {
9597 for (j = 0 ; j < se -> argc ; j ++ )
9698 decrRefCount (se -> argv [j ]);
9799 zfree (se -> argv );
100+ sdsfree (se -> peerid );
101+ sdsfree (se -> cname );
98102 zfree (se );
99103}
100104
@@ -109,10 +113,11 @@ void slowlogInit(void) {
109113/* Push a new entry into the slow log.
110114 * This function will make sure to trim the slow log accordingly to the
111115 * configured max length. */
112- void slowlogPushEntryIfNeeded (robj * * argv , int argc , long long duration ) {
116+ void slowlogPushEntryIfNeeded (client * c , robj * * argv , int argc , long long duration ) {
113117 if (server .slowlog_log_slower_than < 0 ) return ; /* Slowlog disabled */
114118 if (duration >= server .slowlog_log_slower_than )
115- listAddNodeHead (server .slowlog ,slowlogCreateEntry (argv ,argc ,duration ));
119+ listAddNodeHead (server .slowlog ,
120+ slowlogCreateEntry (c ,argv ,argc ,duration ));
116121
117122 /* Remove old entries if needed. */
118123 while (listLength (server .slowlog ) > server .slowlog_max_len )
@@ -152,13 +157,15 @@ void slowlogCommand(client *c) {
152157 int j ;
153158
154159 se = ln -> value ;
155- addReplyMultiBulkLen (c ,4 );
160+ addReplyMultiBulkLen (c ,6 );
156161 addReplyLongLong (c ,se -> id );
157162 addReplyLongLong (c ,se -> time );
158163 addReplyLongLong (c ,se -> duration );
159164 addReplyMultiBulkLen (c ,se -> argc );
160165 for (j = 0 ; j < se -> argc ; j ++ )
161166 addReplyBulk (c ,se -> argv [j ]);
167+ addReplyBulkCBuffer (c ,se -> peerid ,sdslen (se -> peerid ));
168+ addReplyBulkCBuffer (c ,se -> cname ,sdslen (se -> cname ));
162169 sent ++ ;
163170 }
164171 setDeferredMultiBulkLength (c ,totentries ,sent );
0 commit comments