#ifndef LP_PROFILER_H
#define LP_PROFILER_H

#include "lp_array.h"

#define USE_PROFILER
#ifdef USE_PROFILER
#define LP_PROFILE(NAME) \
  LP_ProfilePoint lpProfiler_##NAME(#NAME, __FILE__, __LINE__)
#else
#define LP_PROFILE(NAME)
#endif

class LP_ProfilePoint
{
public:
  LP_ProfilePoint(char *aName, char* aFile, int aLine);
  ~LP_ProfilePoint();

  char *name;
  char *file;
  int line;
  clock_t startTime;
};

class LP_Profiler
{
public:
  static LP_Profiler* GetInstance();
  static void Destroy();

  void Add(char *aName, char *aFile, int aLine, int accTime);

  void Print();

private:
  LP_Profiler();
  ~LP_Profiler();

  class Task
  {
  public:
    Task()
    : name("")
    , file("")
    , line(-1)
    , accTime(0)
    , numExecs(0)
    {
    }

    Task(char *aName, char *aFile, int aLine, int aAccTime)
    : name(aName)
    , file(aFile)
    , line(aLine)
    , accTime(aAccTime)
    , numExecs(1)
    {
    }

    char *name;
    char *file;
    int line;
    int accTime;
    int numExecs;
  };

  LP_Array<Task, 20> tasks;
};

#endif
