torvalds/linux

View on GitHub
tools/perf/scripts/python/intel-pt-events.py

Summary

Maintainability
F
5 days
Test Coverage

File intel-pt-events.py has 417 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-License-Identifier: GPL-2.0
# intel-pt-events.py: Print Intel PT Events including Power Events and PTWRITE
# Copyright (c) 2017-2021, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
Severity: Minor
Found in tools/perf/scripts/python/intel-pt-events.py - About 6 hrs to fix

    Function print_common_ip has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def print_common_ip(param_dict, sample, symbol, dso):
        ip   = sample["ip"]
        offs = get_offset(param_dict, "symoff")
        if "cyc_cnt" in sample:
            cyc_cnt = sample["cyc_cnt"]
    Severity: Minor
    Found in tools/perf/scripts/python/intel-pt-events.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function print_srccode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
        ip = sample["ip"]
        if symbol == "[unknown]":
            start_str = common_start_str(comm, sample) + ("%x" % ip).rjust(16).ljust(40)
        else:
    Severity: Minor
    Found in tools/perf/scripts/python/intel-pt-events.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function do_process_event has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def do_process_event(param_dict):
        sample       = param_dict["sample"]
        raw_buf       = param_dict["raw_buf"]
        comm       = param_dict["comm"]
        name       = param_dict["ev_name"]
    Severity: Minor
    Found in tools/perf/scripts/python/intel-pt-events.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function context_switch has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
        if glb_args.interleave:
            flush_stashed_output()
        if out:
            out_str = "Switch out "
    Severity: Minor
    Found in tools/perf/scripts/python/intel-pt-events.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function auxtrace_error has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x):
    Severity: Major
    Found in tools/perf/scripts/python/intel-pt-events.py - About 1 hr to fix

      Function context_switch has 10 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
      Severity: Major
      Found in tools/perf/scripts/python/intel-pt-events.py - About 1 hr to fix

        Function flush_stashed_output has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def flush_stashed_output():
            global glb_stash_dict
            while glb_stash_dict:
                cpus = list(glb_stash_dict.keys())
                # Output at most glb_args.interleave output strings per cpu
        Severity: Minor
        Found in tools/perf/scripts/python/intel-pt-events.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function print_srccode has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
        Severity: Minor
        Found in tools/perf/scripts/python/intel-pt-events.py - About 45 mins to fix

          Function auxtrace_error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x):
              if glb_args.interleave:
                  flush_stashed_output()
              if len(x) >= 2 and x[0]:
                  machine_pid = x[0]
          Severity: Minor
          Found in tools/perf/scripts/python/intel-pt-events.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function print_evt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def print_evt(raw_buf):
              data = struct.unpack_from("<BBH", raw_buf)
              typ = data[0] & 0x1f
              ip_flag = (data[0] & 0x80) >> 7
              vector = data[1]
          Severity: Minor
          Found in tools/perf/scripts/python/intel-pt-events.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              if source_file_name:
                  if glb_line_number == line_number and glb_source_file_name == source_file_name:
                      src_str = ""
                  else:
                      if len(source_file_name) > 40:
          Severity: Major
          Found in tools/perf/scripts/python/intel-pt-events.py and 1 other location - About 1 day to fix
          tools/perf/scripts/python/arm-cs-trace-disasm.py on lines 152..170

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 183.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              if symbol == "[unknown]":
                  start_str = common_start_str(comm, sample) + ("%x" % ip).rjust(16).ljust(40)
              else:
                  offs = get_offset(param_dict, "symoff")
                  start_str = common_start_str(comm, sample) + (symbol + offs).ljust(40)
          Severity: Major
          Found in tools/perf/scripts/python/intel-pt-events.py and 1 other location - About 4 hrs to fix
          tools/perf/scripts/python/arm-cs-trace-disasm.py on lines 141..145

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 83.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 3 locations. Consider refactoring.
          Open

          def trace_unhandled(event_name, context, event_fields_dict):
                  print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
          Severity: Major
          Found in tools/perf/scripts/python/intel-pt-events.py and 2 other locations - About 2 hrs to fix
          tools/perf/scripts/python/arm-cs-trace-disasm.py on lines 126..127
          tools/perf/scripts/python/event_analyzing_sample.py on lines 191..192

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 53.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          def get_offset(perf_dict, field):
              if field in perf_dict:
                  return "+%#x" % perf_dict[field]
              return ""
          Severity: Minor
          Found in tools/perf/scripts/python/intel-pt-events.py and 1 other location - About 45 mins to fix
          tools/perf/scripts/python/arm-cs-trace-disasm.py on lines 61..64

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 35.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              p = ((cbr * 1000 / data[2]) + 5) / 10
          Severity: Minor
          Found in tools/perf/scripts/python/intel-pt-events.py and 1 other location - About 45 mins to fix
          tools/perf/scripts/python/export-to-sqlite.py on lines 735..735

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 35.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status