Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /ipc /ipc_perftest_util.h
blob: eb43f77b0ed33b33ca5357a503f1ca71ec6bfb57 [file] [log] [blame] [edit]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IPC_IPC_PERFTEST_UTIL_H_
#define IPC_IPC_PERFTEST_UTIL_H_
#include<string>
#include"base/memory/raw_ptr.h"
#include"base/task/single_thread_task_runner.h"
#include"build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include<windows.h>
#endif
#include"base/functional/callback.h"
#include"base/memory/ref_counted.h"
#include"base/process/process_metrics.h"
#include"base/task/single_thread_task_executor.h"
#include"base/task/single_thread_task_runner.h"
#include"build/build_config.h"
#include"ipc/ipc_channel.h"
#include"ipc/ipc_listener.h"
#include"ipc/ipc_message.h"
#include"ipc/ipc_sender.h"
#include"ipc/ipc_test.test-mojom.h"
#include"mojo/public/cpp/bindings/receiver.h"
#include"mojo/public/cpp/system/message_pipe.h"
#if BUILDFLAG(IS_WIN)
#include<windows.h>
#endif
namespace IPC{
scoped_refptr<base::SingleThreadTaskRunner>GetIOThreadTaskRunner();
// This channel listener just replies to all messages with the exact same
// message. It assumes each message has one string parameter. When the string
// "quit" is sent, it will exit.
classChannelReflectorListener:publicListener{
public:
ChannelReflectorListener();
~ChannelReflectorListener()override;
voidInit(Sender* channel,base::OnceClosure quit_closure);
boolOnMessageReceived(constMessage& message)override;
voidOnHello();
voidOnPing(const std::string& payload);
voidOnSyncPing(const std::string& payload, std::string* response);
voidOnQuit();
voidSend(IPC::Message* message);
private:
raw_ptr<Sender> channel_;
base::OnceClosure quit_closure_;
};
// This class locks the current thread to a particular CPU core. This is
// important because otherwise the different threads and processes of these
// tests end up on different CPU cores which means that all of the cores are
// lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU
// frequency, leading to unpredictable and often poor performance.
classLockThreadAffinity{
public:
explicitLockThreadAffinity(int cpu_number);
LockThreadAffinity(constLockThreadAffinity&)=delete;
LockThreadAffinity&operator=(constLockThreadAffinity&)=delete;
~LockThreadAffinity();
private:
bool affinity_set_ok_;
#if BUILDFLAG(IS_WIN)
DWORD_PTR old_affinity_;
#elif BUILDFLAG(IS_LINUX)|| BUILDFLAG(IS_CHROMEOS)
cpu_set_t old_cpuset_;
#endif
};
// Avoid core 0 due to conflicts with Intel's Power Gadget.
// Setting thread affinity will fail harmlessly on single/dual core machines.
constint kSharedCore=2;
classMojoPerfTestClient{
public:
MojoPerfTestClient();
~MojoPerfTestClient();
intRun(MojoHandle handle);
private:
base::SingleThreadTaskExecutor main_task_executor_;
std::unique_ptr<ChannelReflectorListener> listener_;
std::unique_ptr<Channel> channel_;
mojo::ScopedMessagePipeHandle handle_;
};
classReflectorImpl:public IPC::mojom::Reflector{
public:
explicitReflectorImpl(mojo::ScopedMessagePipeHandle handle,
base::OnceClosure quit_closure);
~ReflectorImpl()override;
private:
// IPC::mojom::Reflector:
voidPing(const std::string& value,PingCallback callback)override;
voidSyncPing(const std::string& value,PingCallback callback)override;
voidQuit()override;
base::OnceClosure quit_closure_;
mojo::Receiver<IPC::mojom::Reflector> receiver_;
};
}// namespace IPC
#endif// IPC_IPC_PERFTEST_UTIL_H_

[8]ページ先頭

©2009-2025 Movatter.jp