add timestamps

Signed-off-by: faithwang <wangyanteng@huawei.com>
This commit is contained in:
faithwang 2023-03-31 16:01:00 +08:00
parent fdf8980bd5
commit 4ef9bea269
3 changed files with 88 additions and 1 deletions

View File

@ -55,7 +55,8 @@
"//developtools/profiler/host/smartperf/client/:SmartPerf",
"//developtools/profiler/host/smartperf/client/client_command_fps/:GP_daemon_fps",
"//developtools/profiler/hiebpf:hiebpf_tool",
"//developtools/profiler/transitto:transitto_tool"
"//developtools/profiler/transitto:transitto_tool",
"//developtools/profiler/timestamps:timestamps_tool"
],
"inner_kits": [
{

34
timestamps/BUILD.gn Normal file
View File

@ -0,0 +1,34 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# 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.
import("//build/ohos.gni")
import("//developtools/profiler/device/base/config.gni")
ohos_executable("timestamps") {
sources = [ "timestamps.cpp" ]
include_dirs = []
defines = []
cflags_cc = [ "-std=c++20" ]
deps = []
install_images = [ "system" ]
install_enable = true
subsystem_name = "developtools"
part_name = "profiler"
}
group("timestamps_tool") {
deps = [ ":timestamps" ]
}

52
timestamps/timestamps.cpp Normal file
View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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 <time.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#define TOSTRING(x) #x
struct ClockTime {
std::string name;
clockid_t clockId;
struct timespec ts;
};
int main()
{
std::vector<ClockTime> times = {
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIME, { 0 } },
{ TOSTRING(CLOCK_REALTIME_ALARM), CLOCK_REALTIME_ALARM MMM, { 0 } },
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIM E, { 0 } },
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIME, { 0 } },
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIME, { 0 } },
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIME, { 0 } },
{ TOSTRING(CLOCK_REALTIME), CLOCK_REALTIME, { 0 } },
};
for (auto& time : times) {
clock_gettime(time.clockId, &time.ts);
}
for (auto& time : times) {
printf("%-25s: %10lld.%09ld\n", time.name.c_str(),
static_cast<long long>(time.ts.tv_sec), time.ts.tv_nsec);
}
fflush(stdout);
return 0;
}