auxtrace.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <errno.h>
  16. #include <stdbool.h>
  17. #include "../../util/header.h"
  18. #include "../../util/debug.h"
  19. #include "../../util/pmu.h"
  20. #include "../../util/auxtrace.h"
  21. #include "../../util/intel-pt.h"
  22. #include "../../util/intel-bts.h"
  23. #include "../../util/evlist.h"
  24. static
  25. struct auxtrace_record *auxtrace_record__init_intel(struct perf_evlist *evlist,
  26. int *err)
  27. {
  28. struct perf_pmu *intel_pt_pmu;
  29. struct perf_pmu *intel_bts_pmu;
  30. struct perf_evsel *evsel;
  31. bool found_pt = false;
  32. bool found_bts = false;
  33. intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
  34. intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
  35. evlist__for_each_entry(evlist, evsel) {
  36. if (intel_pt_pmu && evsel->attr.type == intel_pt_pmu->type)
  37. found_pt = true;
  38. if (intel_bts_pmu && evsel->attr.type == intel_bts_pmu->type)
  39. found_bts = true;
  40. }
  41. if (found_pt && found_bts) {
  42. pr_err("intel_pt and intel_bts may not be used together\n");
  43. *err = -EINVAL;
  44. return NULL;
  45. }
  46. if (found_pt)
  47. return intel_pt_recording_init(err);
  48. if (found_bts)
  49. return intel_bts_recording_init(err);
  50. return NULL;
  51. }
  52. struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
  53. int *err)
  54. {
  55. char buffer[64];
  56. int ret;
  57. *err = 0;
  58. ret = get_cpuid(buffer, sizeof(buffer));
  59. if (ret) {
  60. *err = ret;
  61. return NULL;
  62. }
  63. if (!strncmp(buffer, "GenuineIntel,", 13))
  64. return auxtrace_record__init_intel(evlist, err);
  65. return NULL;
  66. }