Added a stroke memusage command to show memory usage
authorMartin Willi <martin@revosec.ch>
Fri, 29 Apr 2011 13:13:15 +0000 (15:13 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:22:21 +0000 (15:22 +0200)
src/libcharon/plugins/stroke/stroke_socket.c
src/stroke/stroke.c
src/stroke/stroke_keywords.h
src/stroke/stroke_keywords.txt
src/stroke/stroke_msg.h

index 88d0270..592c776 100644 (file)
@@ -418,6 +418,18 @@ static void stroke_leases(private_stroke_socket_t *this,
 }
 
 /**
+ * Show memory usage
+ */
+static void stroke_memusage(private_stroke_socket_t *this,
+                                                       stroke_msg_t *msg, FILE *out)
+{
+       if (lib->leak_detective)
+       {
+               lib->leak_detective->usage(lib->leak_detective, out);
+       }
+}
+
+/**
  * set the verbosity debug output
  */
 static void stroke_loglevel(private_stroke_socket_t *this,
@@ -572,6 +584,9 @@ static job_requeue_t process(stroke_job_context_t *ctx)
                case STR_LEASES:
                        stroke_leases(this, msg, out);
                        break;
+               case STR_MEMUSAGE:
+                       stroke_memusage(this, msg, out);
+                       break;
                default:
                        DBG1(DBG_CFG, "received unknown stroke");
                        break;
index 2c5a03d..6dbaf64 100644 (file)
@@ -326,6 +326,15 @@ static int leases(stroke_keyword_t kw, char *pool, char *address)
        return send_stroke_msg(&msg);
 }
 
+static int memusage()
+{
+       stroke_msg_t msg;
+
+       msg.type = STR_MEMUSAGE;
+       msg.length = offsetof(stroke_msg_t, buffer);
+       return send_stroke_msg(&msg);
+}
+
 static int set_loglevel(char *type, u_int level)
 {
        stroke_msg_t msg;
@@ -530,6 +539,9 @@ int main(int argc, char *argv[])
                        res = leases(token->kw, argc > 2 ? argv[2] : NULL,
                                                 argc > 3 ? argv[3] : NULL);
                        break;
+               case STROKE_MEMUSAGE:
+                       res = memusage();
+                       break;
                default:
                        exit_usage(NULL);
        }
index ff2ba36..dd00dc2 100644 (file)
@@ -54,6 +54,7 @@ typedef enum {
        STROKE_PURGE_IKE,
        STROKE_EXPORT_X509,
        STROKE_LEASES,
+       STROKE_MEMUSAGE,
 } stroke_keyword_t;
 
 #define STROKE_LIST_FIRST              STROKE_LIST_PUBKEYS
index dafd1ab..f87b157 100644 (file)
@@ -61,3 +61,4 @@ purgecerts,      STROKE_PURGE_CERTS
 purgeike,        STROKE_PURGE_IKE
 exportx509,      STROKE_EXPORT_X509
 leases,          STROKE_LEASES
+memusage,        STROKE_MEMUSAGE
index 9800d43..2fbacec 100644 (file)
@@ -212,6 +212,8 @@ struct stroke_msg_t {
                STR_LEASES,
                /* export credentials */
                STR_EXPORT,
+               /* print memory usage details */
+               STR_MEMUSAGE,
                /* more to come */
        } type;