PR1NCE (ELDAR) x WARTUZZE
کانال بسته
نمایش بیشتر
کشور مشخص نشده استدسته بندی مشخص نشده است
252
مشترکین
-224 ساعت
+77 روز
+730 روز
آرشیو پست ها
Сосать сосать просто сосать сюда у меня праздник нахуй у меня получилось рабочую карту оптимизир сделать
Дипсик на 2iq умнее стал даже на шестандецетирчное кодирование не ведется но серовно выдает то что нельзя слишком тупой пока
long used() {
return rt.totalMemory() - rt.freeMemory();
}
private String format(long n) {
if (n < 1024)
return n + " B";
double v = n;
String[] u = {"B", "KB", "MB", "GB", "TB"};
int i = 0;
while (v >= 1024 && i < u.length - 1) {
v /= 1024;
i++;
}
return String.format(Locale.US, "%.1f %s", v, u[i]);
}
void printHeap() {
MemoryUsage h = bean.getHeapMemoryUsage();
System.out.println(
"Heap: " +
format(h.getUsed()) +
" / " +
format(h.getMax())
);
}
}
private static final class Cleaner {
private static final Set<String> KEEP =
Set.of("desktop.ini", "thumbs.db");
void clean() {
Set<Path> dirs = new LinkedHashSet<>();
add(dirs, System.getenv("TEMP"));
add(dirs, System.getenv("TMP"));
long count = 0;
for (Path dir : dirs)
count += remove(dir);
System.out.println("Temp: " + count);
}
private void add(Set<Path> set, String value) {
if (value != null && !value.isBlank())
set.add(Paths.get(value));
}
private long remove(Path root) {
if (!Files.isDirectory(root))
return 0;
long[] count = {0};
try (var files = Files.walk(root, 2)) {
files
.filter(Files::isRegularFile)
.filter(p -> !KEEP.contains(
p.getFileName()
.toString()
.toLowerCase(Locale.ROOT)
))
.forEach(p -> {
try {
Files.deleteIfExists(p);
count[0]++;
} catch (IOException ignored) {
}
});
} catch (IOException ignored) {
}
return count[0];
}
}
private static final class Network {
void check() {
try {
long t = System.nanoTime();
InetAddress.getByName("example.com");
long ms = TimeUnit.NANOSECONDS.toMillis(
System.nanoTime() - t
);
System.out.println("DNS: " + ms + " ms");
} catch (IOException e) {
System.out.println("DNS: unavailable");
}
}
}
private static final class Monitor {
private volatile double load = -1;
void update() {
load = ManagementFactory
.getOperatingSystemMXBean()
.getSystemLoadAverage();
}
void print() {
System.out.println(
"CPU load: " +
(load < 0 ? "N/A" :
String.format(Locale.US, "%.2f", load))
);
new Memory().printHeap();
}
}
private static final class Processes {
private final Map<Long, ProcessHandle> list =
new ConcurrentHashMap<>();
void update() {
list.clear();
ProcessHandle.allProcesses()
.filter(ProcessHandle::isAlive)
.forEach(p -> list.put(p.pid(), p));
}
void print() {
update();
list.values()
.stream()
.sorted(Comparator.comparingLong(
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.net.InetAddress;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
public final class PCOptimizer {
private static final int THREADS =
Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
private final ExecutorService pool =
Executors.newFixedThreadPool(THREADS);
private final ScheduledExecutorService timer =
Executors.newScheduledThreadPool(2);
private final AtomicBoolean active = new AtomicBoolean(true);
private final Memory memory = new Memory();
private final Cleaner cleaner = new Cleaner();
private final Network network = new Network();
private final Monitor monitor = new Monitor();
private final Processes processes = new Processes();
public static void main(String[] args) {
new PCOptimizer().run();
}
private void run() {
Runtime.getRuntime().addShutdownHook(
new Thread(this::stop)
);
timer.scheduleAtFixedRate(
monitor::update,
0,
1,
TimeUnit.SECONDS
);
timer.scheduleAtFixedRate(
() -> {
memory.check();
processes.update();
},
15,
15,
TimeUnit.SECONDS
);
menu();
}
private void menu() {
Scanner in = new Scanner(System.in);
while (active.get()) {
System.out.println();
System.out.println("[1] Optimize");
System.out.println("[2] Memory");
System.out.println("[3] Temp");
System.out.println("[4] Network");
System.out.println("[5] Monitor");
System.out.println("[6] Processes");
System.out.println("[0] Exit");
System.out.print("> ");
switch (in.nextLine().trim()) {
case "1" -> optimize();
case "2" -> memory.optimize();
case "3" -> cleaner.clean();
case "4" -> network.check();
case "5" -> monitor.print();
case "6" -> processes.print();
case "0" -> stop();
}
}
}
private void optimize() {
long start = System.nanoTime();
CompletableFuture<Void> a =
CompletableFuture.runAsync(memory::optimize, pool);
CompletableFuture<Void> b =
CompletableFuture.runAsync(cleaner::clean, pool);
CompletableFuture<Void> c =
CompletableFuture.runAsync(network::check, pool);
CompletableFuture.allOf(a, b, c).join();
processes.update();
long ms = TimeUnit.NANOSECONDS.toMillis(
System.nanoTime() - start
);
System.out.println("Done: " + ms + " ms");
}
private void stop() {
if (!active.compareAndSet(true, false))
return;
timer.shutdownNow();
pool.shutdownNow();
}
private static final class Memory {
private final Runtime rt = Runtime.getRuntime();
private final MemoryMXBean bean =
ManagementFactory.getMemoryMXBean();
void optimize() {
long before = used();
System.gc();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
long freed = before - used();
if (freed > 0)
System.out.println(
"Memory: -" + format(freed)
);
}
void check() {
long max = rt.maxMemory();
if (max <= 0)
return;
if ((double) used() / max > .90)
System.gc();
}
Но какой далбоеб будет там очень много чистогл кодинга анимации моделинга
