~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2011-01-02 01:08:38 UTC
  • mfrom: (2045.1.2 clean)
  • Revision ID: brian@tangent.org-20110102010838-en7ctsg86t642hdz
Roll up of code around timer issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
662
662
 
663
663
private:
664
664
  boost::posix_time::ptime _epoch;
 
665
  boost::posix_time::ptime _connect_time;
665
666
  boost::posix_time::ptime _start_timer;
666
667
  boost::posix_time::ptime _end_timer;
667
668
 
 
669
  boost::posix_time::ptime _user_time;
668
670
public:
669
 
 
670
 
  time_t start_time;
671
 
  time_t user_time;
672
 
  uint64_t start_utime;
673
 
  uint64_t utime_after_lock;
 
671
  uint64_t utime_after_lock; // This used by Innodb.
 
672
 
 
673
  void resetUserTime()
 
674
  {
 
675
    _user_time= boost::posix_time::not_a_date_time;
 
676
  }
 
677
 
 
678
  const boost::posix_time::ptime &start_timer() const
 
679
  {
 
680
    return _start_timer;
 
681
  }
 
682
 
 
683
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
 
684
  {
 
685
    result_arg=  arg - _start_timer;
 
686
  }
674
687
 
675
688
  thr_lock_type update_lock_default;
676
689
 
1250
1263
 
1251
1264
  time_t query_start()
1252
1265
  {
1253
 
    return start_time;
 
1266
    return getCurrentTimestampEpoch();
1254
1267
  }
1255
1268
 
1256
1269
  void set_time()
1257
1270
  {
1258
1271
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
1259
 
    start_utime= utime_after_lock= (_start_timer - _epoch).total_microseconds();
1260
 
 
1261
 
    if (user_time)
1262
 
    {
1263
 
      start_time= user_time;
1264
 
      connect_microseconds= start_utime;
1265
 
    }
1266
 
    else 
1267
 
    {
1268
 
      start_time= (_start_timer - _epoch).total_seconds();
1269
 
    }
 
1272
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
1270
1273
  }
1271
1274
 
1272
 
  void set_time(time_t t)
 
1275
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
1273
1276
  {
1274
 
    start_time= user_time= t;
1275
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1276
 
    uint64_t t_mark= (mytime - _epoch).total_microseconds();
1277
 
 
1278
 
    start_utime= utime_after_lock= t_mark;
 
1277
    _user_time= boost::posix_time::from_time_t(t);
1279
1278
  }
1280
1279
 
1281
1280
  void set_time_after_lock()
1290
1289
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
1291
1290
  }
1292
1291
 
 
1292
  uint64_t getElapsedTime() const
 
1293
  {
 
1294
    return (_end_timer - _start_timer).total_microseconds();
 
1295
  }
 
1296
 
1293
1297
  /**
1294
1298
   * Returns the current micro-timestamp
1295
1299
   */
1296
 
  uint64_t getCurrentTimestamp(bool actual= true)  
 
1300
  uint64_t getCurrentTimestamp(bool actual= true) const
1297
1301
  { 
1298
1302
    uint64_t t_mark;
1299
1303
 
1310
1314
    return t_mark; 
1311
1315
  }
1312
1316
 
1313
 
  uint64_t found_rows(void)
 
1317
  // We may need to set user on this
 
1318
  int64_t getCurrentTimestampEpoch() const
 
1319
  { 
 
1320
    if (not _user_time.is_not_a_date_time())
 
1321
      return (_user_time - _epoch).total_seconds();
 
1322
 
 
1323
    return (_start_timer - _epoch).total_seconds();
 
1324
  }
 
1325
 
 
1326
  uint64_t found_rows(void) const
1314
1327
  {
1315
1328
    return limit_found_rows;
1316
1329
  }
1317
1330
 
1318
1331
  /** Returns whether the session is currently inside a transaction */
1319
 
  bool inTransaction()
 
1332
  bool inTransaction() const
1320
1333
  {
1321
1334
    return server_status & SERVER_STATUS_IN_TRANS;
1322
1335
  }
1499
1512
   * Returns the timestamp (in microseconds) of when the Session 
1500
1513
   * connected to the server.
1501
1514
   */
1502
 
  inline uint64_t getConnectMicroseconds() const
1503
 
  {
1504
 
    return connect_microseconds;
 
1515
  uint64_t getConnectMicroseconds() const
 
1516
  {
 
1517
    return (_connect_time - _epoch).total_microseconds();
 
1518
  }
 
1519
 
 
1520
  uint64_t getConnectSeconds() const
 
1521
  {
 
1522
    return (_connect_time - _epoch).total_seconds();
1505
1523
  }
1506
1524
 
1507
1525
  /**
1622
1640
  
1623
1641
  
1624
1642
 private:
1625
 
 /** Microsecond timestamp of when Session connected */
1626
 
  uint64_t connect_microseconds;
1627
1643
  const char *proc_info;
1628
1644
 
1629
1645
  /** The current internal error handler for this thread, or NULL. */