profiling_level.js 831 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const CommandOperation = require('./command');
  3. class ProfilingLevelOperation extends CommandOperation {
  4. constructor(db, command, options) {
  5. super(db, options);
  6. }
  7. _buildCommand() {
  8. const command = { profile: -1 };
  9. return command;
  10. }
  11. execute(callback) {
  12. super.execute((err, doc) => {
  13. if (err == null && doc.ok === 1) {
  14. const was = doc.was;
  15. if (was === 0) return callback(null, 'off');
  16. if (was === 1) return callback(null, 'slow_only');
  17. if (was === 2) return callback(null, 'all');
  18. return callback(new Error('Error: illegal profiling level value ' + was), null);
  19. } else {
  20. err != null ? callback(err, null) : callback(new Error('Error with profile command'), null);
  21. }
  22. });
  23. }
  24. }
  25. module.exports = ProfilingLevelOperation;