auxtrace.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * auxtrace.c: AUX area tracing support
  3. * Copyright (c) 2013-2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #include <stdbool.h>
  16. #include "../../util/header.h"
  17. #include "../../util/debug.h"
  18. #include "../../util/pmu.h"
  19. #include "../../util/auxtrace.h"
  20. #include "../../util/intel-pt.h"
  21. #include "../../util/intel-bts.h"
  22. #include "../../util/evlist.h"
  23. static
  24. struct auxtrace_record *auxtrace_record__init_intel(struct perf_evlist *evlist,
  25. int *err)
  26. {
  27. struct perf_pmu *intel_pt_pmu;
  28. struct perf_pmu *intel_bts_pmu;
  29. struct perf_evsel *evsel;
  30. bool found_pt = false;
  31. bool found_bts = false;
  32. intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
  33. intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
  34. if (evlist) {
  35. evlist__for_each_entry(evlist, evsel) {
  36. if (intel_pt_pmu &&
  37. evsel->attr.type == intel_pt_pmu->type)
  38. found_pt = true;
  39. if (intel_bts_pmu &&
  40. evsel->attr.type == intel_bts_pmu->type)
  41. found_bts = true;
  42. }
  43. }
  44. if (found_pt && found_bts) {
  45. pr_err("intel_pt and intel_bts may not be used together\n");
  46. *err = -EINVAL;
  47. return NULL;
  48. }
  49. if (found_pt)
  50. return intel_pt_recording_init(err);
  51. if (found_bts)
  52. return intel_bts_recording_init(err);
  53. return NULL;
  54. }
  55. struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
  56. int *err)
  57. {
  58. char buffer[64];
  59. int ret;
  60. *err = 0;
  61. ret = get_cpuid(buffer, sizeof(buffer));
  62. if (ret) {
  63. *err = ret;
  64. return NULL;
  65. }
  66. if (!strncmp(buffer, "GenuineIntel,", 13))
  67. return auxtrace_record__init_intel(evlist, err);
  68. return NULL;
  69. }