1

Following the docs on line_profiler, I am able to profile my code just fine, but when I view the output with python -m line_profiler script_to_profile.py.lprof, I only see 27 lines of code. I expect to see about 250, because that's the length of the function that I added the @profile decorator to. My output looks like this:

Timer unit: 1e-06 s

Total time: 831.023 s
File: /Users/will/Repos/Beyond12/src/student_table.py
Function: aggregate_student_data at line 191

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
   191                                               # load files
   192                                               files = os.listdir(datadir)
   193
   194                                               tabs = ['Contact', 'Costs_Contributions', 'Course', 'EducationalHistory', 'Events', 'FinancialAidScholarship',
   195         1          764    764.0      0.0              'PreCollegiateExam', 'QualitativeInformation', 'Student_Performance', 'Task', 'Term']
   196                                               special_contact_id = {'Contact': 'Id',
   197         1            7      7.0      0.0                            'Events': 'WhoId',
   198         1            6      6.0      0.0                            'QualitativeInformation': 'Alumni',
   199         1            6      6.0      0.0                            'Student_Performance': 'Contact',
   200         1            6      6.0      0.0                            'PreCollegiateExam': 'Contact ID'}
   201         1            6      6.0      0.0
   202         1            5      5.0      0.0      # todo: make dictionary of the columns that we'll be using, along with their types?
   203
   204                                               df = {}
   205                                               for tab in tabs:
   206         1            6      6.0      0.0          # match tab titles to files by matching first 5 non-underscore characters
   207        12          115      9.6      0.0          filename = filter(lambda x: tab.replace('_', '')[:5] in x.replace('_', '')[:5], files)[0]

It's cut off in the middle of a for loop.

Mr. W.
  • 359
  • 3
  • 12
  • It seems it picks up some other code. Normally the `for`-loop is executed n+1 times. Could you try to make a [mcve]? That would make it easier to help you. – MSeifert Sep 17 '17 at 17:31

1 Answers1

1

you might have modified source file after creating profile result file, try a re-run. because the source code line_profiler printed is read from the file on disk, ref:

https://github.com/rkern/line_profiler/blob/master/line_profiler.py#L190

georgexsh
  • 15,984
  • 2
  • 37
  • 62
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Donald Duck Sep 25 '17 at 14:35
  • @DonaldDuck thanks for your suggestion, but it is hard to abstract out relevant code snippet in this case. – georgexsh Sep 25 '17 at 14:38
  • @will-adler does this answered your question? – georgexsh Oct 18 '17 at 18:27