[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Added documentation, C bindings, and a test for VM_metrics.{start_time,



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1176134961 -3600
# Node ID 4add9eb83f7fc8590b4a698a272d3a7b4665734c
# Parent  3565e4883548fcb448c8c9489b83ee80035d27f7
Added documentation, C bindings, and a test for VM_metrics.{start_time,
VCPUs_CPU,VCPUs_params}.

Changed VM_metrics.start_time to be a DateTime, not an integer.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 docs/xen-api/xenapi-datamodel.tex      |   99 +++++++++++++++++++++++++++++++++
 tools/libxen/include/xen_int_int_map.h |   53 +++++++++++++++++
 tools/libxen/include/xen_internal.h    |    1 
 tools/libxen/include/xen_vm_metrics.h  |   26 ++++++++
 tools/libxen/src/xen_common.c          |   19 ++++++
 tools/libxen/src/xen_int_int_map.c     |   39 +++++++++++++
 tools/libxen/src/xen_vm_metrics.c      |   63 +++++++++++++++++++++
 tools/libxen/test/test_bindings.c      |   20 ++++++
 tools/python/xen/xend/XendAPI.py       |   11 +++
 tools/python/xen/xend/XendVMMetrics.py |    4 +
 tools/python/xen/xm/main.py            |    7 ++
 11 files changed, 339 insertions(+), 3 deletions(-)

diff -r 3565e4883548 -r 4add9eb83f7f docs/xen-api/xenapi-datamodel.tex
--- a/docs/xen-api/xenapi-datamodel.tex Mon Apr 09 12:20:35 2007 +0100
+++ b/docs/xen-api/xenapi-datamodel.tex Mon Apr 09 17:09:21 2007 +0100
@@ -4107,6 +4107,9 @@ Quals & Field & Type & Description \\
 $\mathit{RO}_\mathit{run}$ &  {\tt memory/actual} & int & Guest's actual 
memory (bytes) \\
 $\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/number} & int & Current number of 
VCPUs \\
 $\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/utilisation} & (int $\rightarrow$ 
float) Map & Utilisation for all of guest's current VCPUs \\
+$\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/CPU} & (int $\rightarrow$ int) Map & 
VCPU to PCPU map \\
+$\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/params} & (string $\rightarrow$ 
string) Map & The live equivalent to VM.VCPUs\_params \\
+$\mathit{RO}_\mathit{run}$ &  {\tt start\_time} & datetime & Time at which 
this VM was last booted \\
 $\mathit{RO}_\mathit{run}$ &  {\tt last\_updated} & datetime & Time at which 
this information was last updated \\
 \hline
 \end{longtable}
@@ -4253,6 +4256,102 @@ Get the VCPUs/utilisation field of the g
  \noindent {\bf Return Type:} 
 {\tt 
 (int $\rightarrow$ float) Map
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_VCPUs\_CPU}
+
+{\bf Overview:} 
+Get the VCPUs/CPU field of the given VM\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} ((int -> int) Map) get_VCPUs_CPU (session_id s, VM_metrics 
ref self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt VM\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+(int $\rightarrow$ int) Map
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_VCPUs\_params}
+
+{\bf Overview:} 
+Get the VCPUs/params field of the given VM\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} ((string -> string) Map) get_VCPUs_params (session_id s, 
VM_metrics ref self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt VM\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+(string $\rightarrow$ string) Map
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_start\_time}
+
+{\bf Overview:} 
+Get the start\_time field of the given VM\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} datetime get_start_time (session_id s, VM_metrics ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt VM\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+datetime
 }
 
 
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/include/xen_int_int_map.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxen/include/xen_int_int_map.h    Mon Apr 09 17:09:21 2007 +0100
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2006-2007, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef XEN_INT_INT_MAP_H
+#define XEN_INT_INT_MAP_H
+
+
+#include "xen_common.h"
+
+
+typedef struct xen_int_int_map_contents
+{
+  int64_t key;
+  int64_t val;
+} xen_int_int_map_contents;
+
+
+typedef struct xen_int_int_map
+{
+    size_t size;
+    xen_int_int_map_contents contents[];
+} xen_int_int_map;
+
+/**
+ * Allocate a xen_int_int_map of the given size.
+ */
+extern xen_int_int_map *
+xen_int_int_map_alloc(size_t size);
+
+/**
+ * Free the given xen_int_int_map, and all referenced values.  The
+ * given map must have been allocated by this library.
+ */
+extern void
+xen_int_int_map_free(xen_int_int_map *map);
+
+
+#endif
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/include/xen_internal.h
--- a/tools/libxen/include/xen_internal.h       Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/libxen/include/xen_internal.h       Mon Apr 09 17:09:21 2007 +0100
@@ -86,6 +86,7 @@ extern const abstract_type abstract_type
 
 extern const abstract_type abstract_type_string_string_map;
 extern const abstract_type abstract_type_int_float_map;
+extern const abstract_type abstract_type_int_int_map;
 
 
 typedef struct abstract_value
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/include/xen_vm_metrics.h
--- a/tools/libxen/include/xen_vm_metrics.h     Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/libxen/include/xen_vm_metrics.h     Mon Apr 09 17:09:21 2007 +0100
@@ -21,6 +21,8 @@
 
 #include "xen_common.h"
 #include "xen_int_float_map.h"
+#include "xen_int_int_map.h"
+#include "xen_string_string_map.h"
 #include "xen_vm_metrics_decl.h"
 
 
@@ -66,6 +68,9 @@ typedef struct xen_vm_metrics_record
     int64_t memory_actual;
     int64_t vcpus_number;
     xen_int_float_map *vcpus_utilisation;
+    xen_int_int_map *vcpus_cpu;
+    xen_string_string_map *vcpus_params;
+    time_t start_time;
     time_t last_updated;
 } xen_vm_metrics_record;
 
@@ -191,6 +196,27 @@ xen_vm_metrics_get_vcpus_utilisation(xen
 
 
 /**
+ * Get the VCPUs/CPU field of the given VM_metrics.
+ */
+extern bool
+xen_vm_metrics_get_vcpus_cpu(xen_session *session, xen_int_int_map **result, 
xen_vm_metrics vm_metrics);
+
+
+/**
+ * Get the VCPUs/params field of the given VM_metrics.
+ */
+extern bool
+xen_vm_metrics_get_vcpus_params(xen_session *session, xen_string_string_map 
**result, xen_vm_metrics vm_metrics);
+
+
+/**
+ * Get the start_time field of the given VM_metrics.
+ */
+extern bool
+xen_vm_metrics_get_start_time(xen_session *session, time_t *result, 
xen_vm_metrics vm_metrics);
+
+
+/**
  * Get the last_updated field of the given VM_metrics.
  */
 extern bool
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/src/xen_common.c
--- a/tools/libxen/src/xen_common.c     Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/libxen/src/xen_common.c     Mon Apr 09 17:09:21 2007 +0100
@@ -35,6 +35,7 @@
 #include "xen_host.h"
 #include "xen_internal.h"
 #include "xen_int_float_map.h"
+#include "xen_int_int_map.h"
 #include "xen_string_string_map.h"
 
 
@@ -1697,3 +1698,21 @@ const abstract_type abstract_type_int_fl
         .struct_size = sizeof(xen_int_float_map_contents),
         .members = int_float_members
     };
+
+static struct struct_member int_int_members[] =
+{
+    {
+        .type = &abstract_type_int,
+        .offset = offsetof(xen_int_int_map_contents, key)
+    },
+    {
+        .type = &abstract_type_int,
+        .offset = offsetof(xen_int_int_map_contents, val)
+    }
+};
+const abstract_type abstract_type_int_int_map =
+    {
+        .typename = MAP,
+        .struct_size = sizeof(xen_int_int_map_contents),
+        .members = int_int_members
+    };
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/src/xen_int_int_map.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxen/src/xen_int_int_map.c        Mon Apr 09 17:09:21 2007 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006-2007, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+
+#include "xen_common.h"
+#include "xen_int_int_map.h"
+#include "xen_internal.h"
+
+
+xen_int_int_map *
+xen_int_int_map_alloc(size_t size)
+{
+    xen_int_int_map *result = calloc(1, sizeof(xen_int_int_map) +
+                                     size * sizeof(struct 
xen_int_int_map_contents));
+    result->size = size;
+    return result;
+}
+
+
+void
+xen_int_int_map_free(xen_int_int_map *map)
+{
+    free(map);
+}
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/src/xen_vm_metrics.c
--- a/tools/libxen/src/xen_vm_metrics.c Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/libxen/src/xen_vm_metrics.c Mon Apr 09 17:09:21 2007 +0100
@@ -22,7 +22,9 @@
 
 #include "xen_common.h"
 #include "xen_int_float_map.h"
+#include "xen_int_int_map.h"
 #include "xen_internal.h"
+#include "xen_string_string_map.h"
 #include "xen_vm_metrics.h"
 
 
@@ -49,6 +51,15 @@ static const struct_member xen_vm_metric
         { .key = "VCPUs_utilisation",
           .type = &abstract_type_int_float_map,
           .offset = offsetof(xen_vm_metrics_record, vcpus_utilisation) },
+        { .key = "VCPUs_CPU",
+          .type = &abstract_type_int_int_map,
+          .offset = offsetof(xen_vm_metrics_record, vcpus_cpu) },
+        { .key = "VCPUs_params",
+          .type = &abstract_type_string_string_map,
+          .offset = offsetof(xen_vm_metrics_record, vcpus_params) },
+        { .key = "start_time",
+          .type = &abstract_type_datetime,
+          .offset = offsetof(xen_vm_metrics_record, start_time) },
         { .key = "last_updated",
           .type = &abstract_type_datetime,
           .offset = offsetof(xen_vm_metrics_record, last_updated) }
@@ -74,6 +85,8 @@ xen_vm_metrics_record_free(xen_vm_metric
     free(record->handle);
     free(record->uuid);
     xen_int_float_map_free(record->vcpus_utilisation);
+    xen_int_int_map_free(record->vcpus_cpu);
+    xen_string_string_map_free(record->vcpus_params);
     free(record);
 }
 
@@ -168,6 +181,56 @@ xen_vm_metrics_get_vcpus_utilisation(xen
 
 
 bool
+xen_vm_metrics_get_vcpus_cpu(xen_session *session, xen_int_int_map **result, 
xen_vm_metrics vm_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = vm_metrics }
+        };
+
+    abstract_type result_type = abstract_type_int_int_map;
+
+    *result = NULL;
+    XEN_CALL_("VM_metrics.get_VCPUs_CPU");
+    return session->ok;
+}
+
+
+bool
+xen_vm_metrics_get_vcpus_params(xen_session *session, xen_string_string_map 
**result, xen_vm_metrics vm_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = vm_metrics }
+        };
+
+    abstract_type result_type = abstract_type_string_string_map;
+
+    *result = NULL;
+    XEN_CALL_("VM_metrics.get_VCPUs_params");
+    return session->ok;
+}
+
+
+bool
+xen_vm_metrics_get_start_time(xen_session *session, time_t *result, 
xen_vm_metrics vm_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = vm_metrics }
+        };
+
+    abstract_type result_type = abstract_type_datetime;
+
+    XEN_CALL_("VM_metrics.get_start_time");
+    return session->ok;
+}
+
+
+bool
 xen_vm_metrics_get_last_updated(xen_session *session, time_t *result, 
xen_vm_metrics vm_metrics)
 {
     abstract_value param_values[] =
diff -r 3565e4883548 -r 4add9eb83f7f tools/libxen/test/test_bindings.c
--- a/tools/libxen/test/test_bindings.c Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/libxen/test/test_bindings.c Mon Apr 09 17:09:21 2007 +0100
@@ -757,6 +757,10 @@ static void print_vm_metrics(xen_session
     my_strftime(time, 256, "Metrics updated at %c, local time.\n", tm);
     printf(time);
 
+    tm = localtime(&vm_metrics_record->start_time);
+    my_strftime(time, 256, "VM running since %c, local time.\n", tm);
+    printf(time);
+
     for (size_t i = 0; i < vm_metrics_record->vcpus_utilisation->size; i++)
     {
         printf("%"PRId64" -> %lf.\n",
@@ -764,6 +768,22 @@ static void print_vm_metrics(xen_session
                vm_metrics_record->vcpus_utilisation->contents[i].val);
     }
 
+    printf("VCPU -> PCPU mapping:\n");
+    for (size_t i = 0; i < vm_metrics_record->vcpus_cpu->size; i++)
+    {
+        printf("  %"PRId64" -> %"PRId64".\n",
+               vm_metrics_record->vcpus_cpu->contents[i].key,
+               vm_metrics_record->vcpus_cpu->contents[i].val);
+    }
+
+    printf("Live scheduling parameters:\n");
+    for (size_t i = 0; i < vm_metrics_record->vcpus_params->size; i++)
+    {
+        printf("  %s -> %s.\n",
+               vm_metrics_record->vcpus_params->contents[i].key,
+               vm_metrics_record->vcpus_params->contents[i].val);
+    }
+
     xen_vm_metrics_record_free(vm_metrics_record);
     xen_vm_metrics_free(vm_metrics);
 
diff -r 3565e4883548 -r 4add9eb83f7f tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Mon Apr 09 17:09:21 2007 +0100
@@ -87,7 +87,16 @@ def xen_api_todo():
 
 
 def now():
-    return xmlrpclib.DateTime(time.strftime("%Y%m%dT%H:%M:%S", time.gmtime()))
+    return datetime()
+
+
+def datetime(when = None):
+    """Marshall the given time as a Xen-API DateTime.
+
+    @param when The time in question, given as seconds since the epoch, UTC.
+                May be None, in which case the current time is used.
+    """
+    return xmlrpclib.DateTime(time.gmtime(when))
 
 
 # ---------------------------------------------------
diff -r 3565e4883548 -r 4add9eb83f7f tools/python/xen/xend/XendVMMetrics.py
--- a/tools/python/xen/xend/XendVMMetrics.py    Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/python/xen/xend/XendVMMetrics.py    Mon Apr 09 17:09:21 2007 +0100
@@ -138,7 +138,9 @@ class XendVMMetrics:
             return {}
 
     def get_start_time(self):
-        return self.xend_domain_instance.info.get("start_time", -1)
+        import xen.xend.XendAPI as XendAPI
+        return XendAPI.datetime(
+            self.xend_domain_instance.info.get("start_time", 0))
     
     def get_last_updated(self):
         import xen.xend.XendAPI as XendAPI
diff -r 3565e4883548 -r 4add9eb83f7f tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Mon Apr 09 12:20:35 2007 +0100
+++ b/tools/python/xen/xm/main.py       Mon Apr 09 17:09:21 2007 +0100
@@ -731,6 +731,10 @@ def xm_restore(args):
         server.xend.domain.restore(savefile, paused)
 
 
+def datetime_to_secs(v):
+    return time.mktime(time.strptime(str(v) + 'UTC', '%Y%m%dT%H:%M:%S%Z'))
+
+
 def getDomains(domain_names, state, full = 0):
     if serverType == SERVER_XEN_API:
         doms_sxp = []
@@ -756,7 +760,8 @@ def getDomains(domain_names, state, full
                             'vcpus':    dom_metrics['VCPUs_number'],
                             'state':    state_str,
                             'cpu_time': dom_metrics['VCPUs_utilisation'],
-                            'start_time': dom_metrics['start_time']})
+                            'start_time': datetime_to_secs(
+                                              dom_metrics['start_time'])})
 
             doms_sxp.append(['domain'] + map2sxp(dom_rec))
             doms_dict.append(dom_rec)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.