Context.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Context.c. Python interfaces for perf script.
  3. *
  4. * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <Python.h>
  22. #include "../../../perf.h"
  23. #include "../../../util/trace-event.h"
  24. PyMODINIT_FUNC initperf_trace_context(void);
  25. static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
  26. {
  27. static struct scripting_context *scripting_context;
  28. PyObject *context;
  29. int retval;
  30. if (!PyArg_ParseTuple(args, "O", &context))
  31. return NULL;
  32. scripting_context = PyCObject_AsVoidPtr(context);
  33. retval = common_pc(scripting_context);
  34. return Py_BuildValue("i", retval);
  35. }
  36. static PyObject *perf_trace_context_common_flags(PyObject *obj,
  37. PyObject *args)
  38. {
  39. static struct scripting_context *scripting_context;
  40. PyObject *context;
  41. int retval;
  42. if (!PyArg_ParseTuple(args, "O", &context))
  43. return NULL;
  44. scripting_context = PyCObject_AsVoidPtr(context);
  45. retval = common_flags(scripting_context);
  46. return Py_BuildValue("i", retval);
  47. }
  48. static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
  49. PyObject *args)
  50. {
  51. static struct scripting_context *scripting_context;
  52. PyObject *context;
  53. int retval;
  54. if (!PyArg_ParseTuple(args, "O", &context))
  55. return NULL;
  56. scripting_context = PyCObject_AsVoidPtr(context);
  57. retval = common_lock_depth(scripting_context);
  58. return Py_BuildValue("i", retval);
  59. }
  60. static PyMethodDef ContextMethods[] = {
  61. { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
  62. "Get the common preempt count event field value."},
  63. { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
  64. "Get the common flags event field value."},
  65. { "common_lock_depth", perf_trace_context_common_lock_depth,
  66. METH_VARARGS, "Get the common lock depth event field value."},
  67. { NULL, NULL, 0, NULL}
  68. };
  69. PyMODINIT_FUNC initperf_trace_context(void)
  70. {
  71. (void) Py_InitModule("perf_trace_context", ContextMethods);
  72. }