ecotrace 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: ecotrace
3
+ Version: 0.1.0
4
+ Summary: Python kodlarinin karbon ayak izini ve enerji tuketimini olcen gelistirici araci.
5
+ Author: Emre Ozkal
6
+ Keywords: carbon,footprint,eco,trace,green software,profiling
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: psutil
10
+ Requires-Dist: py-cpuinfo
11
+ Dynamic: author
12
+ Dynamic: description
13
+ Dynamic: description-content-type
14
+ Dynamic: keywords
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # 🌱 EcoTrace
20
+
21
+ EcoTrace, yazdığınız Python fonksiyonlarının ne kadar enerji harcadığını ve ne kadar karbon emisyonuna (gCO2) sebep olduğunu ölçen hafif bir analiz (profiling) kütüphanesidir.
22
+
23
+ ## Özellikler
24
+ - **Çoklu Çekirdek Desteği:** İşlemcinizin tüm çekirdeklerini analiz eder.
25
+ - **Dinamik İşlemci Tanıma:** Sisteminizdeki CPU'yu tanır ve doğru TDP (Watt) değerini çeker.
26
+ - **Bölgesel Karbon Endeksi:** Ülkelere göre enerji kirliliğini hesaplar (TR, US, DE, FR vb.).
27
+ - **Otomatik Loglama:** Sonuçları analiz için `ecotrace_log.csv` dosyasına otomatik kaydeder.
28
+
29
+ ## Kurulum (Yerel)
30
+ Projeyi indirdiğiniz klasöre gidin ve şu komutu çalıştırın:
31
+ ```bash
32
+ pip install -e .
@@ -0,0 +1 @@
1
+ from .core import EcoTrace
@@ -0,0 +1,105 @@
1
+ import time
2
+ import psutil
3
+ import os
4
+ import cpuinfo
5
+ import json
6
+ import pkg_resources
7
+
8
+ class EcoTrace:
9
+ def __init__(self, region_code="TR", carbon_limit=None):
10
+ # 1. JSON Verisini Çekme ve Güvenlik (Fallback Mekanizması)
11
+ try:
12
+ data_path = pkg_resources.resource_filename('ecotrace', 'data.json')
13
+ with open(data_path, 'r', encoding='utf-8') as f:
14
+ data = json.load(f)
15
+ except Exception as e:
16
+ # Eğer JSON dosyası silinirse veya bozuksa kütüphane çökmesin!
17
+ print(f"Uyari: data.json yuklenemedi. Varsayilan degerler kullaniliyor. Hata: {e}")
18
+ data = {}
19
+
20
+ # 2. Sözlükleri Oluştur (JSON'da yoksa içindeki yedeği kullan)
21
+ self.TDP_MAP = data.get("TDP_MAP", {
22
+ "i7-12": 125, "i5-11": 65, "Ryzen5": 65, "M1": 20, "M2": 22
23
+ })
24
+
25
+ self.CARBON_INTENSITY_MAP = data.get("CARBON_INTENSITY_MAP", {
26
+ "TR": 475, "DE": 385, "FR": 55, "US": 367, "GB": 253, "DEFAULT": 475
27
+ })
28
+
29
+ # 3. Bölge Ayarları
30
+ self.region_code = region_code.upper()
31
+ self.region_factor = self.CARBON_INTENSITY_MAP.get(self.region_code, self.CARBON_INTENSITY_MAP.get("DEFAULT", 475))
32
+ self.carbon_limit = carbon_limit
33
+
34
+ # 4. Donanım Analizi (Çoklu Çekirdek ve CPU Modeli)
35
+ self.total_cores = psutil.cpu_count(logical=True) or 1
36
+
37
+ info = cpuinfo.get_cpu_info()
38
+ cpu_brand = info.get('brand_raw', 'Unknown CPU')
39
+ self.tdp = self.__getdynamic_tdp(cpu_brand)
40
+
41
+ # 5. Log Dosyası Hazırlığı
42
+ self.log_file = "ecotrace_log.csv"
43
+ if not os.path.exists(self.log_file):
44
+ with open(self.log_file, 'w', encoding='utf-8') as f:
45
+ f.write("Function,Duration_Sec,Load_Factor,Carbon_g\n")
46
+
47
+ # 6. Başlangıç Özeti (Ekrana havalı bir çıktı verelim)
48
+ print(f"\n--- EcoTrace Baslatildi ---")
49
+ print(f"Bolge: {self.region_code} ({self.region_factor} gCO2/kWh)")
50
+ print(f"Cekirdek: {self.total_cores}")
51
+ print(f"Islemci: {cpu_brand}")
52
+ print(f"Tahmini TDP: {self.tdp}W")
53
+ print(f"Veri Kaynagi: {'data.json' if data else 'Varsayilan (Fallback)'}")
54
+ print(f"---------------------------\n")
55
+
56
+ def __getdynamic_tdp(self, cpu_brand):
57
+ # Artık global TDP_MAP yerine JSON'dan gelen self.TDP_MAP kullanılıyor
58
+ for key, val in self.TDP_MAP.items():
59
+ if key in cpu_brand:
60
+ return val
61
+ return 50 # Bulunamazsa yedek 50W
62
+
63
+ def track(self, func):
64
+ def wrapper(*args, **kwargs):
65
+ process = psutil.Process(os.getpid())
66
+
67
+ # Baslangic olcumleri
68
+ start_cpu = process.cpu_times()
69
+ start_time = time.perf_counter()
70
+
71
+ # Gercek fonksiyonu calistir
72
+ result = func(*args, **kwargs)
73
+
74
+ # Bitis olcumleri
75
+ end_time = time.perf_counter()
76
+ end_cpu = process.cpu_times()
77
+
78
+ # Hesaplamalar
79
+ duration = end_time - start_time
80
+ cpu_used_sec = (end_cpu.user - start_cpu.user) + (end_cpu.system - start_cpu.system)
81
+
82
+ # Cekirdek bazli gercek islemci yuku
83
+ total_capacity_sec = duration * self.total_cores
84
+ load_factor = (cpu_used_sec / total_capacity_sec) if total_capacity_sec > 0 else 0
85
+
86
+ # Enerji (Wh) ve Karbon (g)
87
+ energy_wh = self.tdp * load_factor * (duration / 3600)
88
+ carbon_gram = (energy_wh / 1000) * self.region_factor
89
+
90
+ if self.carbon_limit and carbon_gram > self.carbon_limit:
91
+ print("\033[91m" + "!!!" * 10)
92
+ print(f"UYARI: KARBON LIMITI ASILDI! (Limit: {self.carbon_limit}g | Olculen: {carbon_gram:.6f}g)")
93
+ print("!!!" * 10 + "\033[0m")
94
+
95
+ # Sonuclari Bas
96
+ print(f"\n--- [EcoTrace] '{func.__name__}' Sonuclari ---")
97
+ print(f"Sure: {duration:.4f} sn | Yük: %{load_factor*100:.2f}")
98
+ print(f"Karbon: {carbon_gram:.10f} g CO2")
99
+
100
+ # CSV'ye Logla
101
+ with open(self.log_file, 'a', encoding='utf-8') as f:
102
+ f.write(f"{func.__name__},{duration:.6f},{load_factor:.4f},{carbon_gram:.10f}\n")
103
+
104
+ return result
105
+ return wrapper
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: ecotrace
3
+ Version: 0.1.0
4
+ Summary: Python kodlarinin karbon ayak izini ve enerji tuketimini olcen gelistirici araci.
5
+ Author: Emre Ozkal
6
+ Keywords: carbon,footprint,eco,trace,green software,profiling
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: psutil
10
+ Requires-Dist: py-cpuinfo
11
+ Dynamic: author
12
+ Dynamic: description
13
+ Dynamic: description-content-type
14
+ Dynamic: keywords
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # 🌱 EcoTrace
20
+
21
+ EcoTrace, yazdığınız Python fonksiyonlarının ne kadar enerji harcadığını ve ne kadar karbon emisyonuna (gCO2) sebep olduğunu ölçen hafif bir analiz (profiling) kütüphanesidir.
22
+
23
+ ## Özellikler
24
+ - **Çoklu Çekirdek Desteği:** İşlemcinizin tüm çekirdeklerini analiz eder.
25
+ - **Dinamik İşlemci Tanıma:** Sisteminizdeki CPU'yu tanır ve doğru TDP (Watt) değerini çeker.
26
+ - **Bölgesel Karbon Endeksi:** Ülkelere göre enerji kirliliğini hesaplar (TR, US, DE, FR vb.).
27
+ - **Otomatik Loglama:** Sonuçları analiz için `ecotrace_log.csv` dosyasına otomatik kaydeder.
28
+
29
+ ## Kurulum (Yerel)
30
+ Projeyi indirdiğiniz klasöre gidin ve şu komutu çalıştırın:
31
+ ```bash
32
+ pip install -e .
@@ -0,0 +1,8 @@
1
+ setup.py
2
+ ecotrace/__init__.py
3
+ ecotrace/core.py
4
+ ecotrace.egg-info/PKG-INFO
5
+ ecotrace.egg-info/SOURCES.txt
6
+ ecotrace.egg-info/dependency_links.txt
7
+ ecotrace.egg-info/requires.txt
8
+ ecotrace.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ psutil
2
+ py-cpuinfo
@@ -0,0 +1 @@
1
+ ecotrace
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="ecotrace",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ install_requires=[
8
+ "psutil",
9
+ "py-cpuinfo",
10
+ ],
11
+ author="Emre Ozkal",
12
+ description="Python kodlarinin karbon ayak izini ve enerji tuketimini olcen gelistirici araci.",
13
+ long_description=open("README.md", encoding="utf-8").read(),
14
+ long_description_content_type="text/markdown",
15
+ keywords="carbon, footprint, eco, trace, green software, profiling",
16
+ python_requires=">=3.7",
17
+ )