Merge pull request #15018 from guru4elephant/add_timer
Add debug thread function for async executorrevert-15207-remove_op_handle_lock_and_fix_var
commit
ff739449ab
@ -0,0 +1,63 @@
|
||||
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
|
||||
#include "paddle/fluid/platform/timer.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace platform {
|
||||
|
||||
void Timer::Reset() {
|
||||
_start.tv_sec = 0;
|
||||
_start.tv_usec = 0;
|
||||
|
||||
_count = 0;
|
||||
_elapsed = 0;
|
||||
_paused = true;
|
||||
}
|
||||
|
||||
void Timer::Start() {
|
||||
Reset();
|
||||
Resume();
|
||||
}
|
||||
|
||||
void Timer::Pause() {
|
||||
if (_paused) {
|
||||
return;
|
||||
}
|
||||
_elapsed += Tickus();
|
||||
++_count;
|
||||
_paused = true;
|
||||
}
|
||||
|
||||
void Timer::Resume() {
|
||||
gettimeofday(&_start, NULL);
|
||||
_paused = false;
|
||||
}
|
||||
|
||||
int Timer::Count() { return _count; }
|
||||
|
||||
double Timer::ElapsedUS() { return static_cast<double>(_elapsed); }
|
||||
|
||||
double Timer::ElapsedMS() { return _elapsed / 1000.0; }
|
||||
|
||||
double Timer::ElapsedSec() { return _elapsed / 1000000.0; }
|
||||
|
||||
int64_t Timer::Tickus() {
|
||||
gettimeofday(&_now, NULL);
|
||||
return (_now.tv_sec - _start.tv_sec) * 1000 * 1000L +
|
||||
(_now.tv_usec - _start.tv_usec);
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace paddle
|
@ -0,0 +1,54 @@
|
||||
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include "paddle/fluid/platform/port.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace platform {
|
||||
|
||||
// A Standard Timer implementation for debugging
|
||||
class Timer {
|
||||
public:
|
||||
// a timer class for profiling
|
||||
// Reset() will be called during initialization
|
||||
// all timing variables will be set 0 in Reset()
|
||||
Timer() { Reset(); }
|
||||
void Reset();
|
||||
void Start();
|
||||
void Pause();
|
||||
// Resume will get current system time
|
||||
void Resume();
|
||||
int Count();
|
||||
// return elapsed time in us
|
||||
double ElapsedUS();
|
||||
// return elapsed time in ms
|
||||
double ElapsedMS();
|
||||
// return elapsed time in sec
|
||||
double ElapsedSec();
|
||||
|
||||
private:
|
||||
struct timeval _start;
|
||||
struct timeval _now;
|
||||
int _count;
|
||||
int _elapsed;
|
||||
bool _paused;
|
||||
|
||||
// get us difference between start and now
|
||||
int64_t Tickus();
|
||||
};
|
||||
|
||||
} // namespace platform
|
||||
} // namespace paddle
|
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "paddle/fluid/platform/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Timer, Reset) {
|
||||
paddle::platform::Timer timeline;
|
||||
timeline.Start();
|
||||
sleep(3);
|
||||
timeline.Pause();
|
||||
timeline.Reset();
|
||||
}
|
||||
|
||||
TEST(Timer, Start) {
|
||||
paddle::platform::Timer timeline;
|
||||
timeline.Start();
|
||||
sleep(3);
|
||||
timeline.Pause();
|
||||
}
|
||||
|
||||
TEST(Timer, Pause) {
|
||||
paddle::platform::Timer timeline;
|
||||
timeline.Start();
|
||||
sleep(3);
|
||||
timeline.Pause();
|
||||
}
|
||||
|
||||
TEST(Timer, Resume) {
|
||||
paddle::platform::Timer timeline;
|
||||
timeline.Start();
|
||||
sleep(3);
|
||||
timeline.Pause();
|
||||
timeline.Resume();
|
||||
}
|
Loading…
Reference in new issue