Refactor stats generation code

Signed-off-by: John Else <john.else@citrix.com>
CA-137766: Add GC stats reporting

rrdd was erronously reporting its own GC stats as xapi's - this code is
adapted from the code removed from rrdd.

Signed-off-by: John Else <john.else@citrix.com>
CA-148243: Getting rid of bad assertion failures during VM lifecycle
operations

Issue: After a VM lifecycle operation, assert statement throws assertion
failure in an ugly manner.

Fix: Removing the assert statements and replacing them with
vm_bad_power_state error in case the power state of VM doesn't match the
expected state after some lifecycle operation.

Signed-off-by: Ravi Pandey <ravi.pandey@citrix.com>
Whitespace: Fix indentation of Xapi_services.fix_cookie

$ camlp4o -printer o -no_comments ocaml/xapi/xapi_services.ml | md5sum
1bd6d207550eaf578eec4fe996447924  -
$ git checkout HEAD^
$ camlp4o -printer o -no_comments ocaml/xapi/xapi_services.ml | md5sum
1bd6d207550eaf578eec4fe996447924  -

Signed-off-by: John Else <john.else@citrix.com>
CA-140037: Fix handling of HTTP with an empty cookie

If the cookie is empty, don't attempt to do anything to it.

Code change just adds a pattern match for the empty list; apart from
that it's just indentation.

Signed-off-by: John Else <john.else@citrix.com>
CA-140037: Add some tests for fix_cookie

Signed-off-by: John Else <john.else@citrix.com>
Adding a function check_power_state
Signed-off-by: Ravi Pandey <ravi.pandey@citrix.com>
Add opam file

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Add backtrace design document

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Register an exception printer for API_ERROR

This means that Printexc.to_string will print the full parameter list
rather than just '_'.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Remove the exnhook: it's gone

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Use new Debug.with_thread_named API

This replaces the leak-friendly 'name_thread' function.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
The generated OCaml code should use Backtrace.reraise

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Update to new Backtrace manipulation APIs

- call Backtrace.is_important in exception handlers to prevent
  accidentally forgetting where we came from
- avoid calling log_exception all over the place -- we want single
  backtraces not lots of fragments
- update taskHelper.failed to take the exception, so it can later
  fetch the backtrace and process it.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Xenops: unmarshal the backtrace from failed Tasks and rethrow

This allows xenopsd backtraces to be joined up with xapi backtraces.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
XenAPI: Add Task.backtrace, and populate it when a task is failed

The field will contain an s-expression encoded Backtrace.t value. It
should be considered an opaque value.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
xe: support a '--trace' option

If '--trace' is provided then, if a failure occurs, a backtrace will be
fetched from the Task and printed.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Merge pull request #1997 from johnelse/ca-137766

CA-137766: Add GC stats reporting
Merge pull request #1998 from johnelse/ca-140037

CA-140037: Fix handling of HTTP with an empty cookie
Merge pull request #1976 from ravippandey/CA-148243_tr3

CA-148243: Getting rid of bad assertion failure after VM starts